.gitlab-ci.yml
stages: - test - build - tag .python: image: registry.gitlab.com/janw/python-poetry:3.7 stage: test cache: key: pip-${CI_JOB_NAME} paths: - .pytest_cache - "$CI_PROJECT_DIR/.cache/pip" - "$CI_PROJECT_DIR/.cache/pre-commit" variables: PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" PRE_COMMIT_HOME: "$CI_PROJECT_DIR/.cache/pre-commit" before_script: - poetry debug - poetry config virtualenvs.create false - poetry install --no-interaction pytest: extends: .python services: - postgres:latest variables: POSTGRES_DB: tapedrive_testing POSTGRES_USER: gitlabci POSTGRES_PASSWORD: tapedrive DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres/$POSTGRES_DB" # Required for coverage to pick up correct branch name GIT_BRANCH: "${CI_COMMIT_REF_NAME}" script: - wget -O ./cc-test-reporter https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 - chmod +x cc-test-reporter - ./cc-test-reporter before-build - pytest --junitxml=pytest.xml --vcr-record=none --cov --cov-report term --cov-report xml - ./cc-test-reporter after-build artifacts: reports: junit: pytest.xml coverage: '/^TOTAL\s+\d+\s+\d+\s+([\d\.]+\%)$/' pre-commit: extends: .python image: python:3.7 before_script: - pip install -U pre-commit script: - pre-commit run --all-files .docker: image: docker:stable stage: build services: - docker:dind variables: DOCKER_TLS_CERTDIR: "" DOCKER_DRIVER: overlay2 before_script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY build: extends: .docker script: - docker pull $CI_REGISTRY_IMAGE:latest || true - docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG . - if [[ "$CI_COMMIT_REF_SLUG" == master ]]; then docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG $CI_REGISTRY_IMAGE:master-$CI_COMMIT_SHORT_SHA; fi - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG tag latest: extends: .docker stage: tag script: - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG $CI_REGISTRY_IMAGE:latest - docker push $CI_REGISTRY_IMAGE:latest only: - master