Setting up CI/CD for Docker on a Hetzner server with Jira source control

I’ve got my code in Jira and I’m using an unmanaged Ubuntu server from Hetzner. My setup includes a Docker Compose file with several services, containers, and volumes mapped to the hard drive. The main container runs FastAPI behind an NGINX reverse proxy.

Before I switched to Docker, I used a cronjob to pull from git every minute. When changes were detected, I’d restart the Linux services with systemctl.

Now that I’ve finished dockerizing, I’m not sure how to handle deployments. I need to keep the volumes untouched, especially my SQLite database on a disk volume.

I’m using Docker Compose because I need to map volumes correctly and I have multiple containers that need to communicate. Some of them share the same base image too.

Basically, I just want to run docker-compose down and docker-compose up when git detects changes. Any ideas on how to set this up?

I’ve been in a similar situation, and here’s what worked for me:

Instead of pulling every minute, I set up a webhook in Jira to trigger a deployment script on my server when changes are pushed. This approach is more efficient and reduces unnecessary checks.

For the deployment script, I created a simple bash file that pulls the latest changes from Jira, checks for any Docker-related file updates, and if updates are detected, runs ‘docker-compose down’ followed by ‘docker-compose up -d’. To preserve your volumes, especially the SQLite database, ensure they’re defined as external in your docker-compose.yml so they remain intact after ‘docker-compose down’.

For handling multiple containers with shared base images, leveraging Docker’s build cache helps speed up rebuilds. As your infrastructure grows, consider orchestrators like Docker Swarm or Kubernetes for smoother scaling and rolling updates.

I’ve implemented a similar CI/CD pipeline for Docker on Hetzner servers. One effective approach is to use Jira’s webhook functionality to trigger a deployment script on your server when changes are pushed. This script can handle pulling the latest changes, checking for Docker-related file updates, and executing the necessary Docker Compose commands.

To preserve your volumes, especially the SQLite database, ensure they’re defined as external in your docker-compose.yml file. This way, they’ll remain intact when you run ‘docker-compose down’.

For efficiency, consider using Docker’s build cache to speed up rebuilds of containers with shared base images. As your setup grows more complex, you might want to explore container orchestration tools like Docker Swarm or Kubernetes for better scaling and update management.

hey pete, i’ve dealt with similar setups. instead of constantly pulling, try setting up a webhook in jira to trigger a script on ur server when changes are pushed. the script can pull changes, check for docker file updates, and run docker-compose down/up if needed. just make sure to define ur volumes as external in docker-compose.yml to keep em safe during restarts. Good luck!