- Automatically pull changes in your repo to your server.
- Perform
docker compose up
to deploy any new services. - Restart services if configuration files changed.
- scheduled backups (commits) for tracked files with external changes.
While on this self-hosting journey, I've not found any simple solutions that I liked for automatically deploying a docker compose stack to a single machine. I've played with git hooks and didn't want to go for Github actions (have to expose network). But now with the new release of Gitea Actions, there is another option to self-host a simple CI/CD workflow! Nice simple (and Github Actions compatible) workflows, and you can easily store all your environment variables in the Gitea repo secrets.
Changes normally come from one of two scenarios:
- You make changes to your
docker-compose.yml
or something like home assistant'sconfiguration.yml
in your local IDE. - You update something (config) through the UI of a service (say node-red
flows.json
), that you want backed up to your repo.
For scenario 1, you can simply make your changes in your comfy local IDE, push them to Gitea and the deploy.yaml
will pull the changes to your server, set environment variables based on your Gitea repo's secrets and update your compose stack.
After deploying your new services, it will also check which files were changed in the last commit, if these file paths contain
names of services you defined, those services will be restarted such that your new config can be picked up! Note: This assumes
the volumes for these services have the same name as the services themselves. E.g. Home assistant is called homeassistant
in
your docker compose stack and the volume is mapped to a directory also named homeassistant
.
version: "3"
name: home_server
services:
homeassistant:
volumes:
- ${REPO_DIR}/homeassistant:/config
For scenario 2, we can use backup.yaml
to schedule a workflow that will push your changes from the server to the repo.
Bonus: From Gitea you can set up a mirror to Github, so that you have extra peace of mind.
The following steps are to be executed on the same server the docker compose stack is meant to run on.
- Use
docker compose up -d gitea
to start Gitea - browse to the new Gitea instance and go through initial setup.
- Create a new repo in Gitea. Note: Name the base branch
main
or update the workflows accordingly. - Go to the repo's setting in Gitea, check the box: 'Enable Repository Actions' and save.
- Go to Site Administration -> Runners -> Create new runner and get a runner registration token. (see link)
- Replace the
${RUNNER_TOKEN}
indocker-compose.yml
or set it as an environment variable. - Run
docker compose up -d gitea_act
to start the actions runner. - Add all your environment variables for your other docker compose services to the secrets in the Gitea repo,
using the
SERVER_ENV_PROD
secret name.
Optional:
9) Set Github (or other) as mirror for Gitea repo.
In your development environment, set Gitea as the remote for your repo.
Commit and push your work, add your other services to the docker-compose.yml
and watch the Gitea Actions do the rest!
- make sure all the volumes in your
docker-compose.yml
have absolute paths, otherwise docker will try to mount from the filesystem of the Actions Runner container instead of the host.