-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.yaml
89 lines (78 loc) · 2.54 KB
/
deploy.yaml
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
- name: Deploy waiting-time-backend
hosts: main
remote_user: ihar
vars:
deployment_dir: /home/ihar/deployments/waiting-time-backend
tasks:
- name: Install Docker to Python
pip:
name: "{{ item }}"
state: present
with_items:
- docker
- docker-compose
- name: Copy configuration files
copy:
src: "{{ item }}"
dest: "{{ deployment_dir }}"
mode: 0644
loop:
- docker-compose.yml
- nginx.conf
- env.production
- name: Copy env.production as .env
copy:
src: env.production
dest: "{{ deployment_dir }}/.env"
mode: 0644
- name: Synchronize database-api directory
ansible.builtin.synchronize:
src: ./database-api/
dest: "{{ deployment_dir }}/database-api"
- name: Ensure DATABASE_URL is set in .env
ansible.builtin.lineinfile:
path: "{{ deployment_dir }}/.env"
regexp: '^DATABASE_URL='
line: 'DATABASE_URL={{ DATABASE_URL }}'
- name: Ensure POSTGRES_DB is set in .env
ansible.builtin.lineinfile:
path: "{{ deployment_dir }}/.env"
regexp: '^POSTGRES_DB='
line: 'POSTGRES_DB={{ POSTGRES_DB }}'
- name: Ensure POSTGRES_USER is set in .env
ansible.builtin.lineinfile:
path: "{{ deployment_dir }}/.env"
regexp: '^POSTGRES_USER='
line: 'POSTGRES_USER={{ POSTGRES_USER }}'
- name: Ensure POSTGRES_PASSWORD is set in .env
ansible.builtin.lineinfile:
path: "{{ deployment_dir }}/.env"
regexp: '^POSTGRES_PASSWORD='
line: 'POSTGRES_PASSWORD={{ POSTGRES_PASSWORD }}'
- name: Ensure OPENAI_API_KEY is set in .env
ansible.builtin.lineinfile:
path: "{{ deployment_dir }}/.env"
regexp: '^OPENAI_API_KEY='
line: 'OPENAI_API_KEY={{ OPENAI_API_KEY }}'
- name: Build the database-api Docker image
community.docker.docker_compose:
project_src: "{{ deployment_dir }}"
project_name: waiting-time-backend
env_file: "{{ deployment_dir }}/.env"
services:
- database-api
build: yes
pull: no
state: present
restarted: no
- name: Pull updated Docker images and restart containers
community.docker.docker_compose:
project_src: "{{ deployment_dir }}"
project_name: waiting-time-backend
env_file: "{{ deployment_dir }}/.env"
pull: yes
build: no
remove_orphans: yes
remove_volumes: yes
state: present
restarted: yes