-
Notifications
You must be signed in to change notification settings - Fork 1
127 lines (103 loc) · 3.11 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
name: Build, Test & Deploy
on: [push, pull_request]
env:
DOCKER_IMAGE_NAME: ghcr.io/fredagscafeen/web
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup python environment
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Setup pip version
run: pip install pip==24.0.0
- name: Install python dependencies
run: pip install -r requirements.txt -r dev-requirements.txt
- name: Run pre-commit checks
uses: pre-commit/[email protected]
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Pull existing images
run: docker-compose pull
- name: Restore docker layer cache
uses: satackey/[email protected]
continue-on-error: true
- 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@v2
with:
name: image
path: image.tar.gz
test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download docker image
uses: actions/download-artifact@v2
with:
name: image
- name: Load docker image
run: docker load < image.tar.gz
- name: Run tests
run: docker run --env DJANGO_SETTINGS_MODULE=fredagscafeen.settings.local "$DOCKER_IMAGE_NAME" ./manage.py test
test-docker-compose:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Download docker image
uses: actions/download-artifact@v2
with:
name: image
- name: Load docker image
run: docker load < image.tar.gz
- name: Test docker-compose
run: |
for k in "SECRET_KEY" "RECAPTCHA_PUBLIC_KEY" "RECAPTCHA_PRIVATE_KEY"; 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-docker-compose
steps:
- name: Download docker image
uses: actions/download-artifact@v2
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 }}