stages: - build - lint - test - publish - deploy image: python:3.7-alpine .test-template: &test-template stage: test services: - postgres:11-alpine script: - python manage.py test tags: - docker variables: DATABASE_URL: postgres://django:supersecret@postgres/pysite POSTGRES_DB: pysite POSTGRES_PASSWORD: supersecret POSTGRES_USER: django build-alpine-3.7: stage: build image: docker:dind script: - docker build --build-arg EXTRAS=test,lint -t django:alpine-3.7 -f docker/app/alpine/3.7/Dockerfile . - docker save django:alpine-3.7 > django_alpine_py37.tar.gz artifacts: paths: - django_alpine_py37.tar.gz build-alpine-3.6: stage: build image: docker:dind script: - docker build --build-arg EXTRAS=test -t django:alpine-3.6 -f docker/app/alpine/3.6/Dockerfile . - docker save django:alpine-3.6 > django_alpine_py36.tar.gz artifacts: paths: - django_alpine_py36.tar.gz build-stretch-3.7: stage: build image: docker:dind script: - docker build --build-arg EXTRAS=test -t django:stretch-3.7 -f docker/app/stretch/3.7/Dockerfile . - docker save django:stretch-3.7 > django_stretch_py37.tar.gz artifacts: paths: - django_stretch_py37.tar.gz build-stretch-3.6: stage: build image: docker:dind script: - docker build --build-arg EXTRAS=test -t django:stretch-3.6 -f docker/app/stretch/3.6/Dockerfile . - docker save django:stretch-3.6 > django_stretch_py36.tar.gz artifacts: paths: - django_stretch_py36.tar.gz lint: stage: lint dependencies: - build-alpine-3.7 image: docker:dind before_script: - docker load < django_alpine_py37.tar.gz script: - docker run django:alpine-3.7 flake8 tags: - docker test-3.7-alpine: <<: *test-template image: docker:dind dependencies: - build-alpine-3.7 before_script: - docker load < djano_alpine_py37.tar.gz - docker run --network=host --env DATABASE_URL=$DATABASE_URL django:alpine-3.7 python manage.py migrate script: - docker run --network=host --env DATABASE_URL=$DATABASE_URL -v ./:/app django:alpine-3.7 coverage run --source=api,home,pysite,wiki --branch manage.py test after_script: - docker run -v ./:/app coverage report artifacts: paths: - .coverage test-3.6-alpine: <<: *test-template image: docker:dind dependencies: - build-alpine-3.6 before_script: - docker load < django_alpine_py36.tar.gz - docker run --network=host --env DATABASE_URL=$DATABASE_URL django:alpine-3.6 python manage.py migrate script: - docker run --network=host --env DATABASE_URL=$DATABASE_URL django:alpine-3.6 python manage.py test test-3.7-stretch: <<: *test-template image: docker:dind dependencies: - build-stretch-3.7 before_script: - docker load < django_stretch_py37.tar.gz - docker run --network=host --env DATABASE_URL=$DATABASE_URL django:stretch-3.7 python manage.py migrate script: - docker run --network=host --env DATABASE_URL=$DATABASE_URL django:stretch-3.7 python manage.py test test-3.6-stretch: <<: *test-template image: docker:dind dependencies: - build-stretch-3.6 before_script: - docker load < django_stretch_py36.tar.gz - docker run --network=host --env DATABASE_URL=$DATABASE_URL django:stretch-3.6 python manage.py migrate script: - docker run --network=host --env DATABASE_URL=$DATABASE_URL django:stretch-3.6 python manage.py test pages: stage: publish dependencies: - test-3.7-alpine before_script: - pip install coverage script: - coverage html --directory=public artifacts: paths: - public expire_in: 30 days push-django: image: docker:stable-git stage: publish script: - echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin - docker build -t pythondiscord/django:latest . - docker push pythondiscord/django:latest only: - master - django tags: - docker deploy: stage: deploy image: alpine:latest before_script: - apk add --no-cache openssh-client - echo "$DJANGO_DEPLOY_SSH_PRIVATE_KEY" > id_ed25519 - chmod 400 id_ed25519 script: - ssh -i id_ed25519 -p 583 -o "StrictHostKeyChecking=no" pysite-deploy@jchri.st environment: name: Django staging url: https://pysite.jchri.st tags: - docker only: - master - django