From 22baecd70c914de0f1c6959260344a5dd429bdf5 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Fri, 21 Jan 2022 10:22:44 +0000 Subject: [PATCH] Update .gitlab-ci.yml file: Deployment --- .gitlab-ci.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 94f5144..a4f29bd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,27 +1,19 @@ -docker-build: - # docker-in-docker: the runner uses docker from inside a docker container to execute the CI-jobs - image: docker:20 # provides the docker toolset (but without an active daemon) - - stage: build - +workflow: # for entire pipeline rules: - - if: '$CI_COMMIT_REF_NAME == "master"' # only run on master - changes: # only run CI when these files have changed + - if: '$CI_COMMIT_REF_NAME == "master"' # only run on master... + changes: # ...and when these files have changed - "*.py" - "Dockerfile" - # services configure images that run during jobs linked to the image (above) - services: +docker-build: + stage: build + image: docker:20 # provides the docker toolset (but without an active daemon) + services: # configure images that run during jobs linked to the image (above) - docker:dind # dind build on docker and starts up the dockerdaemon (docker itself doesn't do that), which is needed to call docker build etc. - before_script: - # docker login asks for the password to be passed through stdin for security - docker login -u $CI_REGISTRY_USER -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - script: - # fetches the latest image from this projects registry to use as cache (not failing if image is not found) - - docker pull $CI_REGISTRY_IMAGE:latest || true - # build + - docker pull $CI_REGISTRY_IMAGE:latest || true # latest image for cache (not failing if image is not found) - > docker build --pull @@ -33,6 +25,14 @@ docker-build: --label "org.opencontainers.image.version=$CI_COMMIT_REF_NAME" --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . - # tag and push - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest - docker push $CI_REGISTRY_IMAGE:latest + +docker-deploy: + stage: deploy + image: alpine:3.15 + needs: ["docker-build"] + script: + - chmod og= $ID_RSA + - apk update && apk add openssh-client + - ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "/home/christoph/HeidiBot/launch.sh"