Situatie
Summary
A single ci.yml will:
-
run tests on matrix (node/python variations),
-
build a Docker image,
-
push to Docker Hub / GitHub Container Registry,
-
SSH to your server and run a
docker pull+docker-compose up -d.
Prerequisites
-
GitHub repo with code + tests.
-
Docker Hub or GHCR credentials stored as GitHub secrets (
DOCKER_USERNAME,DOCKER_PASSWORDorGHCR_TOKEN). -
SSH deploy key added to GitHub secrets (
SSH_PRIVATE_KEY) and added to~/.ssh/authorized_keysof the VPS user. -
On VPS a
docker-compose.ymlthat pulls the new image tag (e.g.,myapp:latest).
Example .github/workflows/ci.yml
Steps to set up
-
Add secrets in GitHub:
GHCR_TOKEN(with write packages scope) or Docker credentials, plusSSH_HOST,SSH_USER,SSH_PRIVATE_KEY. -
Ensure VPS user has
dockeranddocker-composeand thedocker-compose.ymlusesimage: ghcr.io/your/repo:${TAG}orimage: ghcr.io/your/repo:latestand you update tag accordingly. -
Commit
.github/workflows/ci.ymland push tomain.
Troubleshooting & notes
-
For zero-downtime deploys, consider using
docker-composewithpullthenup --detach --no-deps --buildor switch todocker stack/ swarm or Kubernetes. -
Keep secrets rotated. Use limited-scope tokens.
-
Test the SSH action with a manual run first.
Leave A Comment?