From 75815b71cbc29ccf172dcf37a766e7b7a7b478f8 Mon Sep 17 00:00:00 2001 From: Grant <3380410-grahhnt@users.noreply.gitlab.com> Date: Thu, 26 Dec 2024 20:31:47 -0700 Subject: [PATCH] [ci] Fix SSH --- .gitlab-ci.yml | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 848aa81..e63b5a2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,11 +4,13 @@ stages: variables: REGISTRY: registry.sc07.dev - IMAGE_NAME: $GITLAB_USER_LOGIN/$CI_PROJECT_NAME:edge + IMAGE_NAME: sc07/canvas:edge publish: image: docker stage: publish + tags: + - docker-in-docker services: - docker:dind before_script: @@ -23,10 +25,29 @@ deploy: only: - main before_script: - - apt-get -yq update - - apt-get -yqq install ssh - - install -m 600 -D /dev/null ~/.ssh/id_rsa - - echo "$SSH_PRIVATE_KEY" | base64 -d > ~/.ssh/id_rsa + ## + ## 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 - 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" -- GitLab