Skip to content
Snippets Groups Projects
.gitlab-ci.yml 2.2 KiB
Newer Older
Nico Vermaas's avatar
Nico Vermaas committed
stages:
  - build
  - deploy_to_test
  - deploy_to_production

docker-build-master:
  # Official docker image.
  image: docker:latest
  stage: build
  services:
    - docker:dind
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker build --pull -t "$CI_REGISTRY_IMAGE" ldvspec
    - docker push "$CI_REGISTRY_IMAGE"
  only:
    - main


# deploy test/dev version on 'sdc-dev.astron.nl'
docker-deploy-master-test:
  image: docker:latest
  stage: deploy_to_test
  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
    - ssh-keyscan sdc-dev.astron.nl >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  script:
Nico Vermaas's avatar
Nico Vermaas committed
#    - scp docker/docker-compose-dev-cd.yml sdc@sdc-dev.astron.nl:/docker_compose/ldvspec/docker-compose-dev-cd.yml
Nico Vermaas's avatar
Nico Vermaas committed
    - ssh -o StrictHostKeyChecking=no sdc@dop814.astron.nl "docker pull "$CI_REGISTRY_IMAGE""
    - ssh -o StrictHostKeyChecking=no sdc@dop814.astron.nl "docker-compose -p ldvspec -f /docker_compose/ldvspec/docker-compose-dev-cd.yml up -d"
  when: manual
  only:
    - main

# deploy release version on 'sdc.astron.nl'
docker-deploy-master-production:
  image: docker:latest
  stage: deploy_to_production
  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" | 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:
    - 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 ldvspec -f /opt/dockercompose/ldvspec/docker-compose-production-cd.yml up -d"
  when: manual
  only:
    - main