-
Notifications
You must be signed in to change notification settings - Fork 2
200 lines (176 loc) · 7.75 KB
/
tests.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Tests | docker
on:
push:
paths-ignore:
- 'docs/**'
branches:
- master
pull_request:
paths-ignore:
- 'docs/**'
branches:
- master
types: [review_requested, ready_for_review]
concurrency:
group: ${{ github.ref_name }}
cancel-in-progress: true
env:
PYTHON_IMAGE: python:3.9-slim-buster
LOCAL_IMAGE_DJANGO_PROD: localhost:5000/lms-backend-django:latest
LOCAL_IMAGE_DJANGO_DEV: localhost:5000/lms-backend-django-dev:latest
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: lms-backend
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: v0.9.1
provenance: false
driver-opts: network=host
- name: Docker registry cache
uses: actions/cache@v2
id: cache-docker
with:
path: /tmp/.docker-registry
key: ${{ runner.os }}-docker-local-registry-${{ github.sha }}
restore-keys: |
${{ runner.os }}-docker-local-registry
- name: Start docker registry
# https://docs.docker.com/registry/deploying/#run-a-local-registry
# Assuming it will be ready before first build
run: docker run -d -p 5000:5000 --restart=always --name registry -v /tmp/.docker-registry:/var/lib/registry registry:2
- name: Inspect python base image
id: digests
# FIXME: RepoDigests refer to the digest of the manifest list, better to use `docker manifest inspect --verbose docker.io/library/python:3.9-slim-buster` and filter by image manifest
run: |
docker pull ${{ env.PYTHON_IMAGE }}
echo "::set-output name=PYTHON_IMAGE::$(docker inspect docker.io/library/${{ env.PYTHON_IMAGE }} | jq -r '.[0].RepoDigests[0]' | cut -d'@' -f2)"
- name: Production dependencies cache | header image
uses: actions/cache@v2
with:
path: /tmp/.buildx-django-cache
key: ${{ runner.os }}-django-buildx-${{ hashFiles('**/Pipfile.lock') }}-${{ steps.digests.outputs.PYTHON_IMAGE }}
restore-keys: |
${{ runner.os }}-django-buildx
- name: Debug
run: |
[ -d /tmp/.buildx-django-cache ] && ls -la /tmp/.buildx-django-cache
[ -d /tmp/.buildx-django-cache/blobs/sha256 ] && ls -la /tmp/.buildx-django-cache/blobs/sha256
[ -d /tmp/.buildx-django-cache/ingest ] && ls -la /tmp/.buildx-django-cache/ingest
[ -f /tmp/.buildx-django-cache/index.json ] && cat /tmp/.buildx-django-cache/index.json
echo 'done'
- name: Build Django image with production dependencies | header image
uses: docker/build-push-action@v2
with:
context: ./lms-backend/
file: ./lms-backend/docker-files/app/common.Dockerfile
push: true
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ env.LOCAL_IMAGE_DJANGO_PROD }}
cache-from: type=local,src=/tmp/.buildx-django-cache
# “min” on only exports layers already in the final build stage
cache-to: type=local,mode=min,dest=/tmp/.buildx-django-cache-new
- name: Debug
run: |
[ -d /tmp/.buildx-django-cache-new ] && ls -la /tmp/.buildx-django-cache-new
[ -d /tmp/.buildx-django-cache-new/blobs/sha256 ] && ls -la /tmp/.buildx-django-cache-new/blobs/sha256
[ -d /tmp/.buildx-django-cache-new/ingest ] && ls -la /tmp/.buildx-django-cache-new/ingest
[ -f /tmp/.buildx-django-cache-new/index.json ] && cat /tmp/.buildx-django-cache-new/index.json
echo 'done'
- name: Build Django image with dev dependencies | full image
uses: docker/build-push-action@v2
with:
context: ./lms-backend/
file: ./lms-backend/docker-files/app/dev.Dockerfile
push: true
builder: ${{ steps.buildx.outputs.name }}
build-args: |
BASE_IMAGE=${{ env.LOCAL_IMAGE_DJANGO_PROD }}
tags: ${{ env.LOCAL_IMAGE_DJANGO_DEV }}
cache-from: type=registry,ref=${{ env.LOCAL_IMAGE_DJANGO_DEV }}
cache-to: type=inline
- name: Debug docker registry
run: |
curl -s http://localhost:5000/v2/_catalog
docker exec registry cat /etc/docker/registry/config.yml
curl -s http://localhost:5000/v2/lms-backend-django/manifests/latest
curl -s http://localhost:5000/v2/lms-backend-django-dev/manifests/latest
# https://docs.docker.com/registry/garbage-collection/#run-garbage-collection
- name: Cleanup local docker registry
# --delete-untagged delete manifests that are not currently referenced via tag
run: docker exec registry bin/registry garbage-collect /etc/docker/registry/config.yml --delete-untagged
# TODO: remove prod django image from local registry https://docs.docker.com/registry/spec/api/#deleting-an-image
# https://github.com/docker/build-push-action/issues/252
- name: Move cache
run: |
rm -rf /tmp/.buildx-django-cache
mv /tmp/.buildx-django-cache-new /tmp/.buildx-django-cache
tests:
runs-on: ubuntu-latest
needs: build
services:
postgres:
image: postgres:12
env:
POSTGRES_USER: csc
POSTGRES_PASSWORD: FooBar
POSTGRES_DB: cscdb
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
redis:
# 5.0.6 on AWS
image: redis:5.0.14
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 6379 on service container to the host
- 6379:6379
env:
REDIS_HOST: localhost
REDIS_PORT: 6379
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
DATABASE_URL: postgresql://csc:FooBar@postgres:5432/cscdb
steps:
- name: Restore docker registry cache
uses: actions/cache@v2
id: cache-docker
with:
path: /tmp/.docker-registry
key: ${{ runner.os }}-docker-local-registry-${{ github.sha }}
- name: Start docker registry
run: docker run -d -p 5000:5000 --restart=always --name registry -v /tmp/.docker-registry:/var/lib/registry registry:2 && npx wait-on tcp:5000
- name: Run tests
run: docker run -e ENV_FILE=${{ env.ENV_FILE }} --network host ${{ env.LOCAL_IMAGE_DJANGO_DEV }} pytest --create-db --cov=./apps/
env:
WEBPACK_ASSETS_ROOT: ./site-frontend/assets/
ENV_FILE: /var/www/code/lms/settings/.env.example
- name: Run tests for CS Center project
run: docker run -e ENV_FILE=${{ env.ENV_FILE }} --network host ${{ env.LOCAL_IMAGE_DJANGO_DEV }} pytest -c compscicenter_ru/pytest.ini --cov=./compscicenter_ru/
env:
ENV_FILE: /var/www/code/lms/settings/.env.example
- name: Run tests for CS Club project
run: docker run -e ENV_FILE=${{ env.ENV_FILE }} --network host ${{ env.LOCAL_IMAGE_DJANGO_DEV }} pytest -c compsciclub_ru/pytest.ini --cov=./compsciclub_ru/
env:
ENV_FILE: /var/www/code/lms/settings/.env.example
- name: Run tests for Yandex School of Data Analysis project
run: docker run -e ENV_FILE=${{ env.ENV_FILE }} --network host ${{ env.LOCAL_IMAGE_DJANGO_DEV }} pytest -c lk_yandexdataschool_ru/pytest.ini --cov=./lk_yandexdataschool_ru/
env:
ENV_FILE: /var/www/code/lms/settings/.env.example