Skip to content
.gitlab-ci.yml 1.38 KiB
Newer Older
Grant's avatar
Grant committed
stages:
  - publish
  - deploy

variables:
  REGISTRY: registry.sc07.dev
Grant's avatar
Grant committed
  IMAGE_NAME: sc07/canvas:edge
Grant's avatar
Grant committed

publish:
  image: docker
  stage: publish
Grant's avatar
Grant committed
  tags:
    - docker-in-docker
Grant's avatar
Grant committed
  services:
    - docker:dind
  before_script:
    - echo $PAT | docker login $REGISTRY -u $GITLAB_USER_LOGIN --password-stdin
  script:
    - docker build . --tag $REGISTRY/$IMAGE_NAME
    - docker push $REGISTRY/$IMAGE_NAME

deploy:
  image: ubuntu:latest
  stage: deploy
  only:
    - main
  before_script:
Grant's avatar
Grant committed
    ##
    ## Install ssh-agent if not already installed, it is required by Docker.
    ## (change apt-get to yum if you use an RPM-based image)
    ##
    - "command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )"

    ##
    ## Run ssh-agent (inside the build environment)
    ##
    - eval $(ssh-agent -s)

    ##
    ## Give the right permissions, otherwise ssh-add will refuse to add files
    ## Add the SSH key stored in SSH_PRIVATE_KEY file type CI/CD variable to the agent store
    ##
    - chmod 400 "$SSH_PRIVATE_KEY"
    - ssh-add "$SSH_PRIVATE_KEY"

    ##
    ## Create the SSH directory and give it the right permissions
    ##
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
Grant's avatar
Grant committed
    - ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts
  script:
    - ssh $SSH_USER@$SSH_HOST "cd $WORK_DIR && docker compose pull && docker compose up -d && exit"
  after_script:
    - rm -rf ~/.ssh