What do I need to do to get the docker collector on my VPS to retrieve a new image from Gitlab and reboot the server?
@ m-uu, you don’t have to restart the server at all, just follow docker-compose upto get a new image and restart the service.
I know (correct me if I'm wrong) that on my VPS I have to run docker-compose pull && docker-compose inside the application folder, but I literally have no idea how to do this automatically with Gitlab?
, . Gitlab CI, , Java. , , . , , SSH (.ssh/authorized_keys) GITLAB (https://docs.gitlab.com/ee/ci/variables/#secret-variables)
cache:
key: "cache"
paths:
- junte-api
stages:
- build
- build_image
- deploy
build:
image: golang:1.7
stage: build
script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" > ~/key && chmod 600 ~/key
- ssh-add ~/key
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- go get -u github.com/kardianos/govendor
- mkdir -p $GOPATH/src/github.com/junte/junte-api
- mv * $GOPATH/src/github.com/junte/junte-api
- cd $GOPATH/src/github.com/junte/junte-api
- govendor sync
- go build -o junte-api
- cd -
- cp $GOPATH/src/github.com/toscale/junte-api/junte-api .
build_image:
image: docker:latest
stage: build_image
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE .
- docker push $CI_REGISTRY_IMAGE
deploy-dev:
stage: deploy
image: junte/ssh-agent
variables:
SSH_PRIVATE_KEY: $SSH_DEV_PRIVATE_KEY
script:
- scp docker-compose.dev.yml root@SERVER_IP:/home/junte/junte-api/
- ssh root@SERVER_IP docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- ssh root@SERVER_IP "cd /home/junte/junte-api/ && docker-compose -f docker-compose.dev.yml pull api-dev && HOME=/home/dev docker-compose -f docker-compose.dev.yml up -d"
environment:
name: dev
only:
- dev
Gitlab Runner Docker. Gitlab doc, .
:
build - , ,build_image - , gitlab, . cache, .deploy-dev - , . 6 ssh , VPS. SSH_PRIVATE_KEY Gitlab. 3 SSH .