Skip to content

Commit b16e744

Browse files
authored
add coseeing (#22)
* Add coseeing-fe * Update * Fix typo * Update * Update * Update env
1 parent 3cd9988 commit b16e744

3 files changed

Lines changed: 331 additions & 0 deletions

File tree

.github/workflows/ansible.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ on:
1919
options:
2020
- a11yvillage-be
2121
- a11yvillage-fe
22+
- coseeing-fe
23+
- coseeing-be
2224

2325
jobs:
2426
deploy:
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
- name: Show Docker Compose Running Status
2+
hosts: all
3+
become: true
4+
become_user: root
5+
vars:
6+
deploy_tag: ${{ github.event.inputs.deployTag }}
7+
docker_compose_dir: /data/coseeing-server
8+
secret_name: prod/rdsuser/coseeing
9+
secret_region: ap-northeast-1
10+
webroot_path: '/var/www/html' # the root path of your site
11+
certbot_source_directory: /usr/local/certbot-src
12+
certbot_executable_path: "{{ certbot_source_directory }}/venv/bin/certbot"
13+
domain: api.coseeing.org
14+
email: tsengwoody@coseeing.org
15+
ecr_location: 622913514517.dkr.ecr.ap-northeast-1.amazonaws.com
16+
image_name: "{{ ecr_location }}/coseeing-be:{{ deploy_tag }}"
17+
collections:
18+
- community.docker
19+
- community.aws
20+
tasks:
21+
22+
- name: Set ansible_python_interpreter to use the installed Python
23+
set_fact:
24+
ansible_python_interpreter: /usr/bin/python3
25+
26+
- name: Update apt repo and cache on all Debian/Ubuntu boxes
27+
apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
28+
become: true
29+
30+
- name: Upgrade all apt packages
31+
apt: upgrade=yes force_apt_get=yes
32+
become: true
33+
34+
- name: Install Python pip
35+
apt: name={{ item }} update_cache=true state=present force_apt_get=yes
36+
with_items:
37+
- python3-pip
38+
become: true
39+
40+
- name: Install Python packages using apt
41+
apt:
42+
name:
43+
- python3-docker
44+
- python3-boto3
45+
- python3-botocore
46+
- python3-venv
47+
- gcc
48+
- libaugeas0
49+
- libssl-dev
50+
- libffi-dev
51+
- ca-certificates
52+
- openssl
53+
- git
54+
state: present
55+
update_cache: yes
56+
become: true
57+
58+
- name: Get info from AWS secret manager
59+
set_fact:
60+
secret_data: "{{ lookup('amazon.aws.aws_secret', secret_name, region=secret_region) | from_json }}"
61+
62+
- name: Set fact from secret_json
63+
set_fact:
64+
SECRET_KEY: "{{ secret_data.SECRET_KEY }}"
65+
MARIADB_USER: "{{ secret_data.username }}"
66+
MARIADB_PASSWORD: "{{ secret_data.password }}"
67+
MARIADB_HOST: "{{ secret_data.host }}"
68+
MARIADB_PORT: "{{ secret_data.port }}"
69+
MARIADB_DATABASE: "{{ secret_data.database }}"
70+
71+
- name: Ensure docker compose directory exists
72+
file:
73+
path: "{{ docker_compose_dir }}"
74+
state: directory
75+
mode: '0755'
76+
become: true
77+
78+
- name: Ensure docker compose directory exists
79+
file:
80+
path: "{{ docker_compose_dir }}/data"
81+
state: directory
82+
mode: '0755'
83+
become: true
84+
85+
- name: Create .env file
86+
copy:
87+
dest: "{{ docker_compose_dir }}/.env"
88+
content: |
89+
SECRET_KEY={{ SECRET_KEY }}
90+
MARIADB_USER={{ MARIADB_USER }}
91+
MARIADB_PASSWORD={{ MARIADB_PASSWORD }}
92+
MARIADB_HOST={{ MARIADB_HOST }}
93+
MARIADB_PORT={{ MARIADB_PORT }}
94+
MARIADB_DATABASE={{ MARIADB_DATABASE }}
95+
ALLOWED_HOSTS=*
96+
HOST=https://coseeing.org
97+
98+
- name: Copy docker-compose.yml Document
99+
copy:
100+
dest: "{{ docker_compose_dir }}/docker-compose.yml"
101+
content: |
102+
services:
103+
coseeing-server:
104+
container_name: coseeing-server
105+
image: {{ image_name }}
106+
restart: always
107+
volumes:
108+
- my-volume:/app/data
109+
networks:
110+
- default
111+
- entry
112+
labels:
113+
- "traefik.enable=true"
114+
- "traefik.http.routers.api-coseeing.rule=Host(`api.coseeing.org`)"
115+
- "traefik.http.routers.api-coseeing.entrypoints=websecure"
116+
- "traefik.http.routers.api-coseeing.tls.certresolver=api-coseeing"
117+
- "traefik.docker.network=entry"
118+
deploy:
119+
resources:
120+
limits:
121+
cpus: '0.20'
122+
memory: 0.3G
123+
command: ["sh", "-c", "python manage.py runserver 0.0.0.0:8000"]
124+
environment:
125+
- SECRET_KEY=${SECRET_KEY}
126+
- MARIADB_USER=${MARIADB_USER}
127+
- MARIADB_PASSWORD=${MARIADB_PASSWORD}
128+
- MARIADB_HOST=${MARIADB_HOST}
129+
- MARIADB_PORT=${MARIADB_PORT}
130+
- MARIADB_DATABASE=${MARIADB_DATABASE}
131+
- ALLOWED_HOSTS=${ALLOWED_HOSTS}
132+
- HOST=${HOST}
133+
134+
volumes:
135+
my-volume:
136+
driver: local
137+
driver_opts:
138+
type: none
139+
device: data
140+
o: bind
141+
142+
networks:
143+
entry:
144+
driver: bridge
145+
name: entry
146+
147+
- name: Update the repository cache and update package "unzip" to latest version using default
148+
apt:
149+
name: unzip
150+
state: latest
151+
update_cache: yes
152+
153+
- name: Install AWS CLI v2
154+
shell: |
155+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip"
156+
unzip /tmp/awscliv2.zip -d /tmp
157+
sudo /tmp/aws/install
158+
rm -f /tmp/awscliv2.zip
159+
rm -rf /tmp/aws
160+
args:
161+
creates: /usr/local/bin/aws
162+
163+
- name: Login ECR using AWS CLI
164+
shell: |
165+
aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin {{ ecr_location }}
166+
register: ecr_login
167+
no_log: false
168+
169+
- name: Check if image exists
170+
docker_image_info:
171+
name: "{{ image_name }}"
172+
register: image_info
173+
174+
- name: Untag existing image if it exists
175+
docker_image:
176+
name: "{{ image_name }}"
177+
state: absent
178+
force_absent: true
179+
when: image_info.images | length > 0
180+
181+
- name: Run
182+
docker_compose_v2:
183+
project_src: "{{ docker_compose_dir }}"
184+
state: present
185+
register: compose_result
186+
187+
- name: Show compose_result Detail info
188+
debug:
189+
var: compose_result
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
- name: Show Docker Compose Running Status
2+
hosts: all
3+
become: true
4+
become_user: root
5+
vars:
6+
deploy_tag: ${{ github.event.inputs.deployTag }}
7+
docker_compose_dir: /data/coseeing-web
8+
secret_name: prod/rdsuser/coseeing
9+
secret_region: ap-northeast-1
10+
webroot_path: '/var/www/html' # the root path of your site
11+
certbot_source_directory: /usr/local/certbot-src
12+
certbot_executable_path: "{{ certbot_source_directory }}/venv/bin/certbot"
13+
domain: coseeing.org
14+
email: tsengwoody@coseeing.org
15+
ecr_location: 622913514517.dkr.ecr.ap-northeast-1.amazonaws.com
16+
image_name: "{{ ecr_location }}/coseeing-fe:{{ deploy_tag }}"
17+
collections:
18+
- community.docker
19+
- community.aws
20+
tasks:
21+
22+
- name: Set ansible_python_interpreter to use the installed Python
23+
set_fact:
24+
ansible_python_interpreter: /usr/bin/python3
25+
26+
- name: Update apt repo and cache on all Debian/Ubuntu boxes
27+
apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
28+
become: true
29+
30+
- name: Upgrade all apt packages
31+
apt: upgrade=yes force_apt_get=yes
32+
become: true
33+
34+
- name: Install Python pip
35+
apt: name={{ item }} update_cache=true state=present force_apt_get=yes
36+
with_items:
37+
- python3-pip
38+
become: true
39+
40+
- name: Install Python packages using apt
41+
apt:
42+
name:
43+
- python3-docker
44+
- python3-boto3
45+
- python3-botocore
46+
- python3-venv
47+
- gcc
48+
- libaugeas0
49+
- libssl-dev
50+
- libffi-dev
51+
- ca-certificates
52+
- openssl
53+
- git
54+
state: present
55+
update_cache: yes
56+
become: true
57+
58+
- name: Ensure docker compose directory exists
59+
file:
60+
path: "{{ docker_compose_dir }}"
61+
state: directory
62+
mode: '0755'
63+
become: true
64+
65+
- name: Copy docker-compose.yml Document
66+
copy:
67+
dest: "{{ docker_compose_dir }}/docker-compose.yml"
68+
content: |
69+
version: "3.7"
70+
services:
71+
coseeing-web:
72+
container_name: coseeing-web
73+
image: {{ image_name }}
74+
restart: always
75+
deploy:
76+
resources:
77+
limits:
78+
cpus: '0.70'
79+
memory: 1G
80+
labels:
81+
- "traefik.enable=true"
82+
- "traefik.http.routers.coseeing.rule=Host(`coseeing.org`)"
83+
- "traefik.http.routers.coseeing.entrypoints=websecure"
84+
- "traefik.http.routers.coseeing.tls.certresolver=coseeing"
85+
- "traefik.docker.network=entry"
86+
networks:
87+
- default
88+
- entry
89+
environment:
90+
- NEXT_PUBLIC_BASE_URL=https://api.coseeing.org/about/api
91+
- NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID=GTM-NQQ79V67
92+
93+
networks:
94+
entry:
95+
driver: bridge
96+
name: entry
97+
98+
- name: Update the repository cache and update package "unzip" to latest version using default
99+
apt:
100+
name: unzip
101+
state: latest
102+
update_cache: yes
103+
104+
- name: Install AWS CLI v2
105+
shell: |
106+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip"
107+
unzip /tmp/awscliv2.zip -d /tmp
108+
sudo /tmp/aws/install
109+
rm -f /tmp/awscliv2.zip
110+
rm -rf /tmp/aws
111+
args:
112+
creates: /usr/local/bin/aws
113+
114+
- name: Login ECR using AWS CLI
115+
shell: |
116+
aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin {{ ecr_location }}
117+
register: ecr_login
118+
no_log: false
119+
120+
- name: Check if image exists
121+
docker_image_info:
122+
name: "{{ image_name }}"
123+
register: image_info
124+
125+
- name: Untag existing image if it exists
126+
docker_image:
127+
name: "{{ image_name }}"
128+
state: absent
129+
force_absent: true
130+
when: image_info.images | length > 0
131+
132+
- name: Run
133+
docker_compose_v2:
134+
project_src: "{{ docker_compose_dir }}"
135+
state: present
136+
register: compose_result
137+
138+
- name: Show compose_result Detail info
139+
debug:
140+
var: compose_result

0 commit comments

Comments
 (0)