-
Notifications
You must be signed in to change notification settings - Fork 32
146 lines (132 loc) · 3.99 KB
/
build-push-images-latest.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
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
140
141
142
143
144
145
146
name: latest-build
on:
workflow_dispatch:
pull_request:
branches:
- develop
push:
branches:
- develop
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- 3.7
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- name: Test installing development dependencies
working-directory: deployment/docker
run: |
python -m pip install --upgrade pip
pip install -r REQUIREMENTS-dev.txt
- name: Run Flake8 test
run: flake8 .
test:
runs-on: ubuntu-latest
needs:
- lint
env:
APP_IMAGE: kartoza/projecta-uwsgi
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build test image
uses: docker/build-push-action@v2
with:
context: .
file: deployment/docker/Dockerfile
push: false
load: true
target: dev
tags: ${{ env.APP_IMAGE }}:dev
cache-from: |
type=gha,scope=test
type=gha,scope=prod
cache-to: type=gha,scope=test
- name: Build prod image
uses: docker/build-push-action@v2
with:
context: .
file: deployment/docker/Dockerfile
push: false
load: true
target: dev
tags: ${{ env.APP_IMAGE }}:prod
cache-from: |
type=gha,scope=test
type=gha,scope=prod
cache-to: type=gha,scope=prod
- name: Run docker compose services
working-directory: deployment
run: |
echo "Override docker compose for testing purposes"
cp .env.example .env
cp docker-compose.test.yml docker-compose.override.yml
make up
make devweb
make wait-db
make create-test-db
- name: Run Coverage test
working-directory: deployment
run: |
cat << EOF | docker compose exec -T devweb bash
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --noinput --verbosity 0
coverage run manage.py test
coverage xml
EOF
docker cp projecta-devweb-1:/home/web/django_project/coverage.xml ../coverage.xml
# - name: Upload coverage to codecov
# uses: codecov/codecov-action@v2
# with:
# fail_ci_if_error: true
docker-builder:
# Only push if PR happens in the same repo
if: github.event.pull_request.base.repo.url == github.event.pull_request.head.repo.url
runs-on: ubuntu-latest
needs:
- test
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v3
with:
images: ${{ secrets.DOCKERHUB_REPO }}/projecta-uwsgi
tags: |
type=semver,pattern=\d.\d.\d
type=ref,event=branch
type=ref,event=pr
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: deployment/docker/Dockerfile
push: true
target: prod
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: |
type=gha,scope=test
type=gha,scope=prod
cache-to: type=gha,scope=prod
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}