I am trying to Google it for few hours, but can't find it. I have Java/Spring application (+MySQL if it matters) and I am looking to create CI for that.
I know what to do and how:
- I know that I have to move my Git repo to Gitlab.
- Push to repo will trigger CI script.
- Gitlab will build my docker image into Gitlab Docker Registry.
Question is:
What do I have to do to force docker compose on my VPS to pull the new image from Gitlab and restart the server?
I know (correct me if I am wrong) that on my VPS I should run docker-compose pull && docker-compose up
inside my app folder, but I have literally no idea how to make it automatically with Gitlab?
@m-uu, you don't need restart the server at all, just do
docker-compose up
to pull new image and restart serviceYes, you are on the right way. Look at my Gitlab CI configuration file, I think it doesn't difficult to change it for Java project. Just give you ideas how to build, push to your registry and deploy an image to your server. One thing you need to do is generate SSH keys and push public to server (.ssh/authorized_keys) and private to GITLAB pipeline secret variable (https://docs.gitlab.com/ee/ci/variables/#secret-variables)
You also need Gitlab runner with Docker support. How install it look at in Gitlab doc, please.
About stages:
build
- just change it to build what you needbuild_image
- very simple, just login to gitlab registry, build new image and push it to registry. Look atcache
part, it need to cache files between stages and can be different for you.deploy-dev
- that part more about what you asked. Here first 6 commands just install ssh and create your private key file to have access to your VPS. Just copy it and add your SSH_PRIVATE_KEY to secret vars in Gitlab UI. Last 3 SSH commands more interesting for you.