Select Git revision
.gitlab-ci.yml

Fanna Lautenbach authored and
Robbie Luijben
committed
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
.gitlab-ci.yml 6.09 KiB
stages:
- test
- build
- integration
- deploy_to_test
- deploy_to_production
workflow:
rules:
# don't create a pipeline if its a commit pipeline, on a branch and that branch has open merge requests.
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
variables:
DOCKER_IMAGE_TAG: "latest"
- if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
variables:
DOCKER_IMAGE_TAG: "$CI_COMMIT_REF_SLUG"
test-code:
image: python:3.10
stage: test
services:
- postgres:11.0
variables:
POSTGRES_DB: ldv-spec-db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: "atdb123"
script:
- cd ldvspec
- pip install -r requirements/dev.txt
- python manage.py migrate --settings ldvspec.settings.ci
- python manage.py test --settings ldvspec.settings.ci
docker-build:
image: docker:20-cli
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- HASH=$(sha256sum ldvspec/Dockerfile.base | awk '{ print $1 }')
- >
if docker manifest inspect $CI_REGISTRY_IMAGE/base:$HASH > /dev/null; then
echo "Base image exists"
else
docker build -t "$CI_REGISTRY_IMAGE/base:$HASH" -f ldvspec/Dockerfile.base ldvspec
docker push "$CI_REGISTRY_IMAGE/base:$HASH"
fi
- echo "Build using $CI_REGISTRY_IMAGE/base:$HASH"
# Try pulling the existing image for layer reuse; || true to ignore if it does not exist
- docker pull $CI_REGISTRY_IMAGE:$DOCKER_IMAGE_TAG || true
- docker build --cache-from $CI_REGISTRY_IMAGE:$DOCKER_IMAGE_TAG --build-arg BASE_IMAGE="$CI_REGISTRY_IMAGE/base:$HASH" --pull -t "$CI_REGISTRY_IMAGE:$DOCKER_IMAGE_TAG" ldvspec
- docker push "$CI_REGISTRY_IMAGE:$DOCKER_IMAGE_TAG"
integration-test:
image: docker:20-cli
services:
- docker:20-dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
stage: integration
tags:
- "sdc-dev"
script:
- cd integration
# TODO: cache the integration image
- docker compose build
- docker compose up -d atdb-backend ldv-specification-backend