23 Nov 2026 · by Md. Shakil Ahmed
Ship Every Push: A Practical CI/CD Pipeline with GitHub Actions and Docker

Most developers can build an application. The part that hurts is everything after git push: logging in to a server, pulling code, rebuilding, restarting, and hoping nothing broke. Do that by hand a few times and you will eventually deploy the wrong branch, forget a step, or ship something that never ran its tests.
A CI/CD pipeline replaces that ritual with a script that runs the same way every time. This post walks through a pipeline I teach in my book, DevOps for Developers: tests and a Docker build on every push (CI), then an automatic deployment to a server (CD). It is small enough to understand in one sitting and solid enough to run a real product.

What CI and CD actually mean
- Continuous Integration (CI): every push is checked automatically. The code is installed, tested and built in a clean machine, so "works on my laptop" stops being an excuse.
- Continuous Deployment (CD): when the checks pass, the new version is released without anyone logging in to a server.
If the CI part fails, the CD part never starts. That single rule is where most of the safety comes from.
Step 1: The CI workflow
Create .github/workflows/deploy.yml in your repository. We start with the CI job:
name: CI/CD
on:
push:
branches: [main]
permissions:
contents: read
packages: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build Docker image (smoke build)
run: docker build -t my-app:${{ github.sha }} .
A few details that matter:
npm ci, notnpm install. It installs exactly what is inpackage-lock.json, so the pipeline is reproducible.- Write at least one real test. A pipeline with no tests only proves that the code compiles. Node's built-in runner is enough to start: add
"test": "node --test"topackage.jsonand a file that usesnode:test. - Check the
docker buildcommand ends with a dot.docker build -t my-app .The trailing.is the build context. Forgetting it is the most common first-run failure I see.
Step 2: Build once, push to a registry
The server should never build your image. It should only pull one that CI already built and tested. GitHub's container registry (GHCR) is free for this and uses the token GitHub already gives each run:
publish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.sha }}
needs: test is the safety rule from above. Tagging with the commit SHA as well as latest gives you a precise version to roll back to.
Step 3: Prepare the server once
On the VPS, keep a tiny folder with a Compose file. The server only needs Docker, Docker Compose and a way to read your registry.
# /opt/app/docker-compose.yml
services:
app:
image: ghcr.io/YOUR_USER/YOUR_REPO:latest
restart: always
env_file: .env # secrets live on the server, never in Git
ports:
- "127.0.0.1:3000:3000"
Put Nginx in front as a reverse proxy (and TLS with Let's Encrypt), so only ports 80 and 443 are public and the app itself stays on localhost.
Step 4: Deploy over SSH
Create a dedicated deploy key on your laptop. Never reuse your personal key:
ssh-keygen -t ed25519 -C "github-actions" -f ~/.ssh/github_actions_key
cat ~/.ssh/github_actions_key.pub >> ~/.ssh/authorized_keys # run this on the server
Then add these as repository secrets (Settings → Secrets and variables → Actions):
| Secret | What it holds |
|---|---|
VPS_HOST | the server's IP or hostname |
VPS_USERNAME | the Linux user, for example ubuntu |
VPS_SSH_KEY | the private half of the deploy key |
GHCR_PAT | a token with read:packages, so the server can pull the image |
And add the final job:
deploy:
needs: publish
runs-on: ubuntu-latest
steps:
- uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USERNAME }}
key: ${{ secrets.VPS_SSH_KEY }}
script: |
cd /opt/app
echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
docker compose pull
docker compose up -d --remove-orphans
docker image prune -f
Push to main and watch the Actions tab. Test, publish, deploy: three green steps and your change is live.
Mistakes that cost people hours
- Secrets in the repository. Anything in Git history is public to whoever gets the repo. Keep secrets in GitHub Secrets and in the server's
.env. - Deploying from every branch. Restrict CD to
main(or to tags). Test branches should only run CI. - No rollback plan. Because you tagged images with the commit SHA, rolling back is one command: point Compose at the previous tag and run
docker compose up -d. - Floating action versions. Use the current major version of each action and, for production, pin third-party actions to a full commit SHA. Tags can be moved; a SHA cannot.
- No health check. Add a
healthcheckto your container so a broken release is noticed instead of silently serving errors.
Where to go next
Once this pipeline is boring, build on it: zero-downtime releases, automatic backups before each deploy, and security scanning as part of the same workflow (I cover that in Six Security Gates for Your Pipeline).
This pipeline is built up step by step, with every command explained, in DevOps for Developers (Bengali Edition), a 408-page hands-on book that takes you from the Linux command line to production deployments. See the book, or get in touch if you want a pipeline like this set up for your team.
Need help with a project like this?
Get in touch