File tree Expand file tree Collapse file tree 4 files changed +72
-16
lines changed
Expand file tree Collapse file tree 4 files changed +72
-16
lines changed Original file line number Diff line number Diff line change 11name : CD
22
3- on : [workflow_dispatch, pull_request, push]
3+ on :
4+ workflow_dispatch :
5+ push :
6+ branches :
7+ - ' master'
48
59jobs :
610 cd :
11+ if : |
12+ github.event_name == 'push' || (
13+ github.event_name == 'workflow_dispatch' &&
14+ contains(fromJSON(vars.PROJECT_ADMINS), github.actor)
15+ )
716 runs-on : ubuntu-latest
817 steps :
918 - name : Checkout
1019 uses : actions/checkout@v3
11-
12- - name : Decode private key file
20+ - name : Generate .env for staging vm from github secrets
1321 run : |
1422 echo "${{secrets.PRODUCTION_DOT_ENV_FILE}}" > .env
23+ - name : Decode private key file for OpenSSH access over Ansible
24+ run : |
1525 echo "${{secrets.SSH_PRIVATE_KEY}}" | base64 --decode > "private.pem"
1626 chmod 400 private.pem
17-
18- - name : Run CD playbook
27+ - name : Run playbook for deployment
1928 uses : dawidd6/action-ansible-playbook@v2
2029 with :
2130 playbook : deploy.yml
2433 hosts:
2534 staging:
2635 ansible_host: staging.pycon.tw
27- ansible_user: changchaishi
36+ ansible_user: "${{secrets.GCE_USERNAME}}"
37+ # secret file generated from previous step
2838 ansible_ssh_private_key_file: private.pem
2939 ansible_python_interpreter: /home/dev/.pyenv/shims/python
Original file line number Diff line number Diff line change 11---
2- - name : Check services
2+ - name : Deploy project to staging machine
33 hosts : staging
4- # need to use become since I'm connecting using personal private key
4+ # escalate privilege
55 become : true
6- # switch user as dev
76 become_user : dev
87 vars :
98 project_dir : /home/dev/web-projects/pycontw-2023-ansible
109
1110 tasks :
12- - name : Ensure that Docker for python is present ( docker in pip)
11+ - name : Dependencies check dor docker and docker-compose in remote server
1312 community.general.python_requirements_info :
1413 dependencies :
1514 - docker
15+ - docker-compose
1616
17- - name : Create a directory if it does not exist
17+ - name : Create project directory ( if not exist)
1818 ansible.builtin.file :
1919 path : " {{ project_dir }}"
2020 state : directory
2121
22- - name : Copy entire project files to remote server
22+ # Copy project files to remote server (.env is included)
23+ - name : Copy project files to remote server
2324 ansible.posix.synchronize :
2425 src : ./
2526 dest : " {{ project_dir }}"
3334 community.docker.docker_compose :
3435 project_src : " {{ project_dir }}"
3536 build : true
36- # try to build first, without up the service
37- state : absent
37+ state : present
Original file line number Diff line number Diff line change 1+ version : " 3.5"
2+ services :
3+ web :
4+ build : .
5+ container_name : pycontw-2023-ansible
6+ image : pycontw-2023_web-ansible
7+ hostname : pycontw-2023
8+ entrypoint : " "
9+ command :
10+ # Hacky script for quick demonstration purpose
11+ - bash
12+ - -c
13+ - |
14+ set -o errexit -o nounset -o pipefail
15+ python3 manage.py compilemessages
16+ python3 manage.py migrate
17+ python3 manage.py collectstatic --no-input
18+
19+ exec uwsgi --http-socket :8000 \
20+ --master \
21+ --hook-master-start "unix_signal:15 gracefully_kill_them_all" \
22+ --static-map /static=assets \
23+ --static-map /media=media \
24+ --mount /prs=pycontw2016/wsgi.py \
25+ --manage-script-name \
26+ --offload-threads 2
27+ restart : always
28+ environment :
29+ # Save us from having to type `--setting=pycontw2016.settings.production`
30+ DJANGO_SETTINGS_MODULE : pycontw2016.settings.production.pycontw2023
31+ SCRIPT_NAME : /prs
32+ SECRET_KEY : ${SECRET_KEY}
33+ DATABASE_URL : ${DATABASE_URL}
34+ EMAIL_URL : ${EMAIL_URL}
35+ DSN_URL : ${DSN_URL}
36+ GTM_TRACK_ID : ${GTM_TRACK_ID}
37+ SLACK_WEBHOOK_URL : ${SLACK_WEBHOOK_URL}
38+
39+ volumes :
40+ - ${MEDIA_ROOT}:/usr/local/app/src/media
41+ networks :
42+ - network
43+
44+ networks :
45+ network :
46+ external : true
47+ name : network-2023
Original file line number Diff line number Diff line change @@ -2,8 +2,7 @@ version: "3.5"
22services :
33 web :
44 build : .
5- container_name : pycontw-2023-ansible
6- image : pycontw-2023_web-ansible
5+ container_name : pycontw-2023
76 hostname : pycontw-2023
87 entrypoint : " "
98 command :
You can’t perform that action at this time.
0 commit comments