workflow: # for entire pipeline rules: - if: '$CI_COMMIT_REF_NAME == "master"' # only run on master... changes: # ...and when these files have changed - "*.py" - "Dockerfile" 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 -u $CI_REGISTRY_USER -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker pull $CI_REGISTRY_IMAGE:latest || true # latest image for cache (not failing if image is not found) - > docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --label "org.opencontainers.image.title=$CI_PROJECT_TITLE" --label "org.opencontainers.image.url=$CI_PROJECT_URL" --label "org.opencontainers.image.created=$CI_JOB_STARTED_AT" --label "org.opencontainers.image.revision=$CI_COMMIT_SHA" --label "org.opencontainers.image.version=$CI_COMMIT_REF_NAME" --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . - 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/$CI_PROJECT_TITLE/launch.sh"