stages: - build - lint - test - publish - deploy variables: BASE_IMAGE_URL: registry.gitlab.com/python-discord/projects/site/django-ci .test-template: &test-template stage: test services: - postgres:11-alpine before_script: - python manage.py migrate script: - python manage.py test tags: - docker variables: DATABASE_URL: postgres://django:supersecret@postgres/pysite POSTGRES_DB: pysite POSTGRES_PASSWORD: supersecret POSTGRES_USER: django SECRET_KEY: supersecret build-alpine-3.7: stage: build image: docker:dind before_script: - echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY script: - > docker build --build-arg EXTRAS=test,lint -t $BASE_IMAGE_URL:alpine-3.7-$CI_COMMIT_REF_SLUG -f docker/app/alpine/3.7/Dockerfile . - docker push $BASE_IMAGE_URL:alpine-3.7-$CI_COMMIT_REF_SLUG build-alpine-3.6: stage: build image: docker:dind before_script: - echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY script: - > docker build --build-arg EXTRAS=test,lint -t $BASE_IMAGE_URL:alpine-3.6-$CI_COMMIT_REF_SLUG -f docker/app/alpine/3.6/Dockerfile . - docker push $BASE_IMAGE_URL:alpine-3.6-$CI_COMMIT_REF_SLUG build-stretch-3.7: stage: build image: docker:dind before_script: - echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY script: - > docker build --build-arg EXTRAS=test,lint -t $BASE_IMAGE_URL:stretch-3.7-$CI_COMMIT_REF_SLUG -f docker/app/stretch/3.7/Dockerfile . - docker push $BASE_IMAGE_URL:stretch-3.7-$CI_COMMIT_REF_SLUG build-stretch-3.6: stage: build image: docker:dind before_script: - echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY script: - > docker build --build-arg EXTRAS=test,lint -t $BASE_IMAGE_URL:stretch-3.6-$CI_COMMIT_REF_SLUG -f docker/app/stretch/3.6/Dockerfile . - docker push $BASE_IMAGE_URL:stretch-3.6-$CI_COMMIT_REF_SLUG lint-python: stage: lint image: $BASE_IMAGE_URL:alpine-3.7-$CI_COMMIT_REF_SLUG script: - flake8 tags: - docker lint-docker: stage: lint image: hadolint/hadolint:latest-debian script: - hadolint docker/**/**/**/Dockerfile tags: - docker lint-markdown: stage: lint image: ruby:2.5-alpine before_script: - gem install mdl script: - mdl *.md **/*.md tags: - docker test-3.7-alpine: <<: *test-template image: $BASE_IMAGE_URL:alpine-3.7-$CI_COMMIT_REF_SLUG before_script: - python manage.py migrate script: - coverage run --source=api,home,pysite,wiki --branch manage.py test after_script: - coverage report artifacts: paths: - .coverage test-3.6-alpine: <<: *test-template image: $BASE_IMAGE_URL:alpine-3.6-$CI_COMMIT_REF_SLUG test-3.7-stretch: <<: *test-template image: $BASE_IMAGE_URL:stretch-3.7-$CI_COMMIT_REF_SLUG test-3.6-stretch: <<: *test-template image: $BASE_IMAGE_URL:stretch-3.6-$CI_COMMIT_REF_SLUG pages: image: python:3.7-alpine 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