-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.yml
131 lines (120 loc) · 3.44 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
- name: deploy
hosts: all
remote_user: "{{ user }}"
gather_facts: no
tasks:
- name: clone repo
git:
repo: "https://github.com/vientos/vientos-{{ item.name }}.git"
dest: "/home/{{ user }}/{{ item.name }}"
version: "{{ common.env }}"
when: item.domain is defined
loop:
- "{{ website }}"
- "{{ app }}"
- "{{ service }}"
- "{{ idp }}"
- "{{ webhooks }}"
- name: npm install
npm:
path: "/home/{{ user }}/{{ item.name }}"
when: item.domain is defined
loop:
- "{{ app }}"
- "{{ service }}"
- "{{ idp }}"
- "{{ webhooks }}"
- name: bootstrap app
block:
- name: create app config
template:
src: app-config.json.j2
dest: "/home/{{ user }}/{{ app.name }}/config.json"
- name: install app bower dependencies
shell: "NODE_ENV={{ common.env }} ./node_modules/.bin/bower install"
args:
chdir: "/home/{{ user }}/{{ app.name }}"
- name: run webpack build
shell: "NODE_ENV={{ common.env }} npm run build"
args:
chdir: "/home/{{ user }}/{{ app.name }}"
when: app.domain is defined
# https://www.brendanlong.com/systemd-user-services-are-amazing.html
- name: create directory for user services
file:
path: "/home/{{ user }}/.config/systemd/user"
state: "directory"
- name: Register uid of user
command: "id -u {{ user }}"
register: user_uid
- name: copy units from templates
template:
src: "systemd/{{ item.name }}.service.j2"
dest: "/home/{{ user }}/.config/systemd/user/vientos-{{ item.name }}.service"
when: item.domain is defined
loop:
- "{{ service }}"
- "{{ idp }}"
- "{{ webhooks }}"
- name: enable and start services
systemd:
name: "vientos-{{ item.name }}"
enabled: yes
state: restarted
user: yes
daemon_reload: yes
environment:
XDG_RUNTIME_DIR: "/run/user/{{user_uid.stdout}}"
when: item.domain is defined
loop:
- "{{ service }}"
- "{{ idp }}"
- "{{ webhooks }}"
- name: create directory for update scripts
file:
path: "/home/{{ user }}/bin"
state: directory
- name: copy update scripts
template:
src: "scripts/update-{{ item.name }}.sh.j2"
dest: "/home/{{ user }}/bin/update-{{ item.name }}"
mode: 0740
when: item.domain is defined
loop:
- "{{ website }}"
- "{{ app }}"
- "{{ service }}"
- "{{ idp }}"
- "{{ webhooks }}"
tags:
- backups
- name: create directory for backups
file:
path: "/home/{{ user }}/backups"
state: directory
when: common.backups is defined
- name: copy backups script
template:
src: "scripts/backup.sh.j2"
dest: "/home/{{ user }}/bin/backup"
mode: 0740
when: common.backups is defined
tags:
- backups
- name: add backups cron job
cron:
name: vientos backups
user: "{{ user }}"
special_time: daily
job: "/home/{{ user }}/bin/backup"
when: common.backups is defined
- name: restart nginx
hosts: all
remote_user: root
gather_facts: no
tasks:
- name: restart nginx
systemd:
name: nginx
state: restarted