diff options
author | jloup <jean-loup.jamet@trainline.com> | 2018-02-14 14:19:09 +0100 |
---|---|---|
committer | jloup <jean-loup.jamet@trainline.com> | 2018-02-14 14:19:09 +0100 |
commit | 7a9e5112eaaea58d55f181d3e5296e4ff839921c (patch) | |
tree | 968ed193f42a1fad759cc89ad2f8ad5b0091291e /cmd/ansible | |
download | Front-7a9e5112eaaea58d55f181d3e5296e4ff839921c.tar.gz Front-7a9e5112eaaea58d55f181d3e5296e4ff839921c.tar.zst Front-7a9e5112eaaea58d55f181d3e5296e4ff839921c.zip |
initial commit
Diffstat (limited to 'cmd/ansible')
-rw-r--r-- | cmd/ansible/.gitignore | 3 | ||||
-rw-r--r-- | cmd/ansible/ansible.cfg | 3 | ||||
-rw-r--r-- | cmd/ansible/conf.toml.j2 | 17 | ||||
-rw-r--r-- | cmd/ansible/cryptoportfolio-app.j2 | 13 | ||||
-rw-r--r-- | cmd/ansible/deploy.yml | 105 | ||||
-rw-r--r-- | cmd/ansible/hosts | 15 | ||||
-rw-r--r-- | cmd/ansible/release.yml | 59 | ||||
-rw-r--r-- | cmd/ansible/requirements.yml | 7 | ||||
-rw-r--r-- | cmd/ansible/vars.yml | 22 |
9 files changed, 244 insertions, 0 deletions
diff --git a/cmd/ansible/.gitignore b/cmd/ansible/.gitignore new file mode 100644 index 0000000..eeb2d6a --- /dev/null +++ b/cmd/ansible/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | *.retry* | ||
2 | roles/nginx | ||
3 | roles/certbot | ||
diff --git a/cmd/ansible/ansible.cfg b/cmd/ansible/ansible.cfg new file mode 100644 index 0000000..d48a88f --- /dev/null +++ b/cmd/ansible/ansible.cfg | |||
@@ -0,0 +1,3 @@ | |||
1 | [defaults] | ||
2 | inventory = hosts | ||
3 | roles_path = roles/ | ||
diff --git a/cmd/ansible/conf.toml.j2 b/cmd/ansible/conf.toml.j2 new file mode 100644 index 0000000..5f08a26 --- /dev/null +++ b/cmd/ansible/conf.toml.j2 | |||
@@ -0,0 +1,17 @@ | |||
1 | log_level="info" | ||
2 | mode="production" | ||
3 | log_out="/var/cryptoportfolio-app/app.log" | ||
4 | port="8080" | ||
5 | |||
6 | [db] | ||
7 | user="{{ postgres_user }}" | ||
8 | password="{{ postgres_password }}" | ||
9 | database="{{ postgres_database }}" | ||
10 | address="localhost:5432" | ||
11 | |||
12 | [api] | ||
13 | domain="{{ app_domain }}" | ||
14 | jwt_secret="{{ jwt_secret }}" | ||
15 | |||
16 | [app] | ||
17 | public_dir="/var/cryptoportfolio-app/static" | ||
diff --git a/cmd/ansible/cryptoportfolio-app.j2 b/cmd/ansible/cryptoportfolio-app.j2 new file mode 100644 index 0000000..40979d6 --- /dev/null +++ b/cmd/ansible/cryptoportfolio-app.j2 | |||
@@ -0,0 +1,13 @@ | |||
1 | [Unit] | ||
2 | Description=Cryptoportfolio app | ||
3 | |||
4 | [Service] | ||
5 | Type=simple | ||
6 | |||
7 | User={{ app_user }} | ||
8 | Group={{ app_user }} | ||
9 | UMask=007 | ||
10 | |||
11 | ExecStart=/usr/bin/cryptoportfolio-app -conf /var/cryptoportfolio-app/conf.toml | ||
12 | |||
13 | Restart=on-failure | ||
diff --git a/cmd/ansible/deploy.yml b/cmd/ansible/deploy.yml new file mode 100644 index 0000000..b56c581 --- /dev/null +++ b/cmd/ansible/deploy.yml | |||
@@ -0,0 +1,105 @@ | |||
1 | --- | ||
2 | - hosts: jloup-home | ||
3 | |||
4 | tasks: | ||
5 | - include_vars: vars.yml | ||
6 | |||
7 | - name: install myservice systemd unit file | ||
8 | template: src=cryptoportfolio-app.j2 dest=/etc/systemd/system/cryptoportfolio-app.service | ||
9 | become: yes | ||
10 | |||
11 | - name: stop cryptoportfolio-app | ||
12 | systemd: state=stopped name=cryptoportfolio-app | ||
13 | become: yes | ||
14 | |||
15 | - name: Creates cryptoportfolio-app directory | ||
16 | file: path=/var/cryptoportfolio-app state=directory owner={{ app_user }} | ||
17 | become: yes | ||
18 | |||
19 | - name: Set log file. | ||
20 | file: path=/var/cryptoportfolio-app/app.log owner={{ app_user }} state=touch | ||
21 | become: yes | ||
22 | |||
23 | - name: Copy server app binary from github 'https://github.com/jloup/dist/releases/download/crypto-v{{ version }}/cryptoportfolio-linux-{{ linux_arch }}'. | ||
24 | get_url: | ||
25 | url: "https://github.com/jloup/dist/releases/download/crypto-v{{ version }}/cryptoportfolio-linux-{{ linux_arch }}" | ||
26 | dest: /usr/bin/cryptoportfolio-app | ||
27 | owner: "{{ app_user }}" | ||
28 | mode: "u=rwx,g=r,o=r" | ||
29 | become: yes | ||
30 | |||
31 | - name: Copy server app configuration file. | ||
32 | template: | ||
33 | src: conf.toml.j2 | ||
34 | dest: /var/cryptoportfolio-app/conf.toml | ||
35 | owner: "{{ app_user }}" | ||
36 | become: yes | ||
37 | |||
38 | - name: Create webapp directory. | ||
39 | file: path=/var/cryptoportfolio-app/static state=directory owner={{ app_user }} | ||
40 | become: yes | ||
41 | |||
42 | - name: Copy webapp files from github 'https://github.com/jloup/dist/releases/download/crypto-v{{ version }}/webapp.tar.gz'. | ||
43 | unarchive: | ||
44 | src: "https://github.com/jloup/dist/releases/download/crypto-v{{ version }}/webapp.tar.gz" | ||
45 | dest: /var/cryptoportfolio-app/static | ||
46 | remote_src: yes | ||
47 | owner: "{{ app_user }}" | ||
48 | mode: "u=rwx,g=r,o=r" | ||
49 | become: yes | ||
50 | |||
51 | - import_role: | ||
52 | name: nginx | ||
53 | become: yes | ||
54 | vars: | ||
55 | nginx_vhosts: | ||
56 | - listen: "443 ssl" | ||
57 | server_name: "{{ app_domain }}" | ||
58 | filename: "{{ app_domain }}.443.conf" | ||
59 | extra_parameters: | | ||
60 | ssl_certificate /etc/letsencrypt/live/{{ app_domain }}/fullchain.pem; | ||
61 | ssl_certificate_key /etc/letsencrypt/live/{{ app_domain }}/privkey.pem; | ||
62 | location / { | ||
63 | proxy_pass "http://127.0.0.1:8080"; | ||
64 | } | ||
65 | |||
66 | - listen: "80" | ||
67 | server_name: "{{ app_domain }}" | ||
68 | filename: "{{ app_domain}}.80.conf" | ||
69 | return: "301 https://{{ app_domain }}$request_uri" | ||
70 | |||
71 | - import_role: | ||
72 | name: certbot | ||
73 | become: yes | ||
74 | vars: | ||
75 | certbot_admin_email: jeanloup.jamet@gmail.com | ||
76 | certbot_create_if_missing: yes | ||
77 | certbot_create_standalone_stop_services: [] | ||
78 | certbot_create_method: standalone | ||
79 | certbot_certs: | ||
80 | - domains: | ||
81 | - "{{ app_domain }}" | ||
82 | |||
83 | - name: Create postgres user. | ||
84 | user: name=postgres | ||
85 | |||
86 | - name: Add cryptoportfolio database. | ||
87 | postgresql_db: name={{ postgres_database }} | ||
88 | become: yes | ||
89 | become_user: postgres | ||
90 | vars: | ||
91 | ansible_ssh_pipelining: true | ||
92 | |||
93 | - name: Add cryptoportfolio user. | ||
94 | postgresql_user: user={{ postgres_user }} db={{ postgres_database }} password={{ postgres_password }} | ||
95 | become: yes | ||
96 | become_user: postgres | ||
97 | vars: | ||
98 | ansible_ssh_pipelining: true | ||
99 | |||
100 | - file: path=/www/{{ app_user }} state=directory owner={{ app_user }} | ||
101 | become: yes | ||
102 | |||
103 | - name: start cryptoportfolio-app | ||
104 | systemd: state=started name=cryptoportfolio-app daemon_reload=yes | ||
105 | become: yes | ||
diff --git a/cmd/ansible/hosts b/cmd/ansible/hosts new file mode 100644 index 0000000..64969e8 --- /dev/null +++ b/cmd/ansible/hosts | |||
@@ -0,0 +1,15 @@ | |||
1 | [jloup-home] | ||
2 | jlj.am | ||
3 | |||
4 | [jloup-home:vars] | ||
5 | ansible_port=21 | ||
6 | ansible_user=ansible-deploy | ||
7 | |||
8 | app_user=jloup | ||
9 | app_domain=jlj.am | ||
10 | |||
11 | postgres_database=cryptoportfolio | ||
12 | postgres_user=cryptoportfolio | ||
13 | postgres_password=cryptoportfolio-dev | ||
14 | |||
15 | linux_arch=386 \ No newline at end of file | ||
diff --git a/cmd/ansible/release.yml b/cmd/ansible/release.yml new file mode 100644 index 0000000..4cd005c --- /dev/null +++ b/cmd/ansible/release.yml | |||
@@ -0,0 +1,59 @@ | |||
1 | --- | ||
2 | - name: Release to github repo | ||
3 | hosts: 127.0.0.1 | ||
4 | connection: local | ||
5 | tasks: | ||
6 | - include_vars: vars.yml | ||
7 | |||
8 | # Create release. | ||
9 | - github_release: | ||
10 | token: "{{ github_release_token }}" | ||
11 | user: jloup | ||
12 | repo: dist | ||
13 | action: create_release | ||
14 | tag: "crypto-v{{ version }}" | ||
15 | target: master | ||
16 | name: Crypto Release | ||
17 | body: "NOTE: this repo does not include any source code." | ||
18 | |||
19 | # Build server app. | ||
20 | - make: | ||
21 | chdir: ../app | ||
22 | target: release | ||
23 | - shell: | ||
24 | github-release upload \ | ||
25 | -s "{{ github_release_token }}" \ | ||
26 | -u jloup \ | ||
27 | -r dist \ | ||
28 | -t crypto-v{{ version }} \ | ||
29 | -n "cryptoportfolio-linux-amd64" \ | ||
30 | -l "cryptoportfolio binary (linux amd64)" \ | ||
31 | -R \ | ||
32 | -f ../app/dist/linux_amd64/cryptoportfolio-app | ||
33 | - shell: | ||
34 | github-release upload \ | ||
35 | -s "{{ github_release_token }}" \ | ||
36 | -u jloup \ | ||
37 | -r dist \ | ||
38 | -t crypto-v{{ version }} \ | ||
39 | -n "cryptoportfolio-linux-386" \ | ||
40 | -l "cryptoportfolio binary (linux 386)" \ | ||
41 | -R \ | ||
42 | -f ../app/dist/linux_386/cryptoportfolio-app | ||
43 | |||
44 | # Build webapp. | ||
45 | - make: | ||
46 | chdir: ../web | ||
47 | target: release | ||
48 | params: | ||
49 | ENV: prod | ||
50 | - shell: | ||
51 | github-release upload \ | ||
52 | -s "{{ github_release_token }}" \ | ||
53 | -u jloup \ | ||
54 | -r dist \ | ||
55 | -t crypto-v{{ version }} \ | ||
56 | -n "webapp.tar.gz" \ | ||
57 | -R \ | ||
58 | -f ../web/build/webapp.tar.gz | ||
59 | |||
diff --git a/cmd/ansible/requirements.yml b/cmd/ansible/requirements.yml new file mode 100644 index 0000000..bacd7a8 --- /dev/null +++ b/cmd/ansible/requirements.yml | |||
@@ -0,0 +1,7 @@ | |||
1 | - src: geerlingguy.nginx | ||
2 | name: nginx | ||
3 | version: 2.5.0 | ||
4 | |||
5 | - src: geerlingguy.certbot | ||
6 | name: certbot | ||
7 | version: 3.0.0 | ||
diff --git a/cmd/ansible/vars.yml b/cmd/ansible/vars.yml new file mode 100644 index 0000000..1de7413 --- /dev/null +++ b/cmd/ansible/vars.yml | |||
@@ -0,0 +1,22 @@ | |||
1 | $ANSIBLE_VAULT;1.1;AES256 | ||
2 | 63613535333830393037646665363566636635366534636261623839326130663431653839346266 | ||
3 | 3832643338623561313362663837323234663537663439350a313034326663383235663964626132 | ||
4 | 38343964396265323539396439383731336464393337383833653666643736303539626136383431 | ||
5 | 6536316338376538360a343862626636363031353037626462333364623433613861393137353336 | ||
6 | 37396664663030363530333364633266653862393538313835326138663465626638326363656561 | ||
7 | 30393836386664633834663838666432383836623432363936343635313835303166393531643966 | ||
8 | 33313361383565363232373066306534613465386534386266306564383365373762613361366365 | ||
9 | 61366530623863623336643531346463323233323539333139336335383439373132373233663031 | ||
10 | 39666535633362383135376534376532333663636136366130653762643164333436313261646137 | ||
11 | 37353139633361636163326366616234613466393731373631616138386263383131663537633533 | ||
12 | 31393763316561623134623063623735356334363833623939313437386330323837626131356332 | ||
13 | 30383863373535366137366138633832623566613061313138396539306536633763633934313562 | ||
14 | 35383763653532336539346632623935303634353866636264373262363839326439313837313765 | ||
15 | 36303539613734646238636432393166616438666665363363323331373437633362613838653564 | ||
16 | 64393639346661646333383466363162633638643838386666383564366665656266333836363435 | ||
17 | 35643231323362323566303535303561626139333830393538383635326631656666323166343863 | ||
18 | 31393566346531653535393738326166303261376238316532373833616432306638326139353234 | ||
19 | 32653132323764316231393634663262313765393230656232343833373438636430643663353965 | ||
20 | 36333931303731646333316430646534383531313264353936396565336338663530303434643036 | ||
21 | 34356663373533663137636235386164646334356262336464363862643332636661313339303531 | ||
22 | 35663833656564393331636139663738323834373862623436633666306661373166 | ||