Ini cara yang saya gunakan di production & sampai saat ini belum ada kendala. Biar bisa ngikutin tutorial ini, silahkan baca Pull Image di Gitlab Registry Secara Batch dan Setup Docker Swarm untuk Aplikasi PHP Native.
Silahkan clone project ipang - uang-kas-docker. Setelah itu lanjut buat file .gitlab-ci.yml nya (penjelasan saya tulis di komen ya):
image: docker:stable
# created 2 stage, for build docker images & for deploy to server
stages:
- build
- deploy
# first stage, we build docker images & push it to registry.gitlab.com
build_image:
stage: build
services:
- docker:dind
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $IMAGE_TAG .
- docker push $IMAGE_TAG
only:
- master
when: manual
# second stage, we deploy to server
# first, we pull new image in batch using ansible
# second, we update the service using docker service update command
deploy_to_production:
stage: deploy
before_script:
- apk update
- apk add openssh-client
- eval $(ssh-agent -s)
- echo "$swarm_manager" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# first, update all image in swarm node
# after that, update docker swarm service
script:
- ssh admin@192.168.1.1
"cd /home/admin/ansible &&
ansible-playbook pull-image.yml -i hosts --tags 'uang-kas' &&
docker service update --force --update-delay=10s --update-parallelism=1 --image registry.gitlab.com/ipang/uang-kas-docker"
- echo "success!"
when: manual
only:
- master
environment:
name: production
url: https://uangkas.com

Berhasil euy!