Completed (#878) #446
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |