stages: - test - build - deploy_to_test - deploy_to_production docker-build: # Official docker image. image: docker:latest stage: build services: - docker:dind tags: - "sdc-dev" before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker build --pull -t "$CI_REGISTRY_IMAGE" atdb - docker push "$CI_REGISTRY_IMAGE" # only: # - master test-code: image: python:3.10 stage: test tags: - "sdc-dev" services: - postgres:14.0 variables: POSTGRES_DB: atdb_ldv_test_ci POSTGRES_USER: atdb_admin_test_ci POSTGRES_PASSWORD: "atdb123_test_ci" script: - cd atdb - pip install -r requirements/dev.txt - python manage.py migrate --settings atdb.settings.test_ci - python manage.py test --settings atdb.settings.test_ci # deploy to 'sdc-dev.astron.nl' docker-deploy-to-test: image: docker:latest stage: deploy_to_test tags: - "sdc-dev" before_script: - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )' - eval $(ssh-agent -s) - echo "$SSH_PRIVATE_KEY_USER_SDC" | tr -d '\r' | ssh-add - - mkdir -p ~/.ssh - chmod 700 ~/.ssh - ssh-keyscan dop814.astron.nl >> ~/.ssh/known_hosts - chmod 644 ~/.ssh/known_hosts script: - scp -O -o StrictHostKeyChecking=no atdb/docker/docker-compose-dev-cd.yml sdc@dop814.astron.nl:/docker_compose/atdb-ldv/docker-compose-dev-cd.yml - ssh -o StrictHostKeyChecking=no sdc@dop814.astron.nl "echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY" - ssh -o StrictHostKeyChecking=no sdc@dop814.astron.nl "docker pull "$CI_REGISTRY_IMAGE"" - ssh -o StrictHostKeyChecking=no sdc@dop814.astron.nl "docker-compose -p atdb -f /docker_compose/atdb-ldv/docker-compose-dev-cd.yml up -d" when: manual # only: # - master # deploy to 'sdc.astron.nl' docker-deploy-to-production: image: docker:latest stage: deploy_to_production tags: - "sdc-dev" before_script: - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )' - eval $(ssh-agent -s) - echo "$SSH_PRIVATE_KEY_USER_SDC" | tr -d '\r' | ssh-add - - mkdir -p ~/.ssh - chmod 700 ~/.ssh - ssh-keyscan dop821.astron.nl >> ~/.ssh/known_hosts - chmod 644 ~/.ssh/known_hosts script: - scp -O -o StrictHostKeyChecking=no atdb/docker/docker-compose-production-cd.yml sdco@dop821.astron.nl:/opt/dockercompose/atdb-ldv-compose/docker-compose-production-cd.yml - ssh -o StrictHostKeyChecking=no sdco@dop821.astron.nl "echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY" - ssh -o StrictHostKeyChecking=no sdco@dop821.astron.nl "docker pull "$CI_REGISTRY_IMAGE"" - ssh -o StrictHostKeyChecking=no sdco@dop821.astron.nl "docker-compose -p atdb -f /opt/dockercompose/atdb-ldv-compose/docker-compose-production-cd.yml up -d" when: manual # only: # - master