Update .gitlab-ci.yml file: Deployment
This commit is contained in:
@ -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"
|
||||
|
Reference in New Issue
Block a user