-
Notifications
You must be signed in to change notification settings - Fork 8
139 lines (113 loc) · 3.34 KB
/
main.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
132
133
134
135
136
137
138
139
name: Build, Test & Deploy
on: [push, pull_request]
env:
DOCKER_IMAGE_NAME: ghcr.io/beeracademy/web
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup python environment
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install python dependencies
run: pip install -r requirements.txt -r dev-requirements.txt
- name: Run pre-commit checks
uses: pre-commit/action@v3.0.0
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Pull existing images
run: docker compose pull
- name: Build image
run: ./build
- name: Save docker image
run: docker save "$DOCKER_IMAGE_NAME" | gzip > image.tar.gz
- name: Upload docker image for other jobs
uses: actions/upload-artifact@v3
with:
name: image
path: image.tar.gz
test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download docker image
uses: actions/download-artifact@v3
with:
name: image
- name: Load docker image
run: docker load < image.tar.gz
- name: Run tests
run: docker run --env DJANGO_SETTINGS_MODULE=academy.settings.development "$DOCKER_IMAGE_NAME" ./manage.py test
test-postgres:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download docker image
uses: actions/download-artifact@v3
with:
name: image
- name: Load docker image
run: docker load < image.tar.gz
- name: Run tests using postgres
run: USE_DOCKER=1 ./test_postgres
test-docker-compose:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download docker image
uses: actions/download-artifact@v3
with:
name: image
- name: Load docker image
run: docker load < image.tar.gz
- name: Test docker compose
run: |
for k in "SECRET_KEY" "EMAIL_HOST_PASSWORD" "FACEBOOK_ACCESS_TOKEN"; do
echo "$k=foo" >> ".env"
done
docker network create traefik
docker compose up -d
sleep 10
res=$(docker compose ps)
echo "$res"
if echo "$res" | grep Exit &>/dev/null; then
exit 1
fi
release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
needs:
- pre-commit
- build
- test
- test-postgres
- test-docker-compose
steps:
- name: Download docker image
uses: actions/download-artifact@v3
with:
name: image
- name: Load docker image
run: docker load < image.tar.gz
- name: Publish image to ghcr.io
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io --username "${{ github.actor }}" --password-stdin
docker push "$DOCKER_IMAGE_NAME"
deploy:
runs-on: ubuntu-latest
needs: release
steps:
- name: Deploy image to production
run: curl --fail -X POST "$WEBHOOK_URL"
env:
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}