Until recently, releasing my project meant SSH-ing into the production server, running git pull, and then docker compose build while the live app was still running. It worked, but nothing stopped a broken build or a bad database migration from reaching users.
So I spent a few days building a proper CI/CD pipeline for SocialPost, a social media management platform I'm building for Facebook and Instagram. Now every push to the deploy branch that passes all checks ships itself to production in about 10 minutes, with no manual step on the server.
In this post I want to share what I built, the constraints that shaped it, and what it still can't do. I'm not an expert in DevOps, so I'll be clear about the trade-offs.
- The problem: releases depended on me and luck Before the pipeline, the setup had five problems: • Images were built on the production server, using its CPU and memory while the live app was running. • Tests were run by hand, if at all. Nothing blocked a red build. • No backup was taken right before a release, so a bad migration had no clean way back. • Rolling back meant rebuilding an old commit by hand. • Anyone with SSH access to deploy also had a full shell on a server shared with other sites. The goal was simple to say: production should only ever run code that passed the tests, was built once, and can be rolled back in seconds.
- What the pipeline does On every push to the deploy branch, GitHub Actions:
- Checks the database migrations.
- Runs the backend tests (against PostgreSQL 16 and Redis 7) and the frontend lint, tests and build.
- Builds the backend and frontend Docker images once.
- Pushes them to GitHub Container Registry (GHCR), tagged with the full commit SHA.
- Asks the VPS, over SSH, to deploy that exact SHA. Then the VPS:
- Takes a verified database backup.
- Restarts the app on the new images.
- Runs health checks.
- Rolls back automatically if any check fails. A nightly encrypted copy of the database also goes off the server to Cloudflare R2, so the server itself can't read its own off-site backups.
- Decisions I'm glad I made Build once, run that exact image. The tested image is the deployed image. Nothing is rebuilt on the server, so the server's resources stay free for the app. Tag images with the full commit SHA, never latest. Every release is traceable, and any old release can be pulled again for a rollback. Lock the CI key to one script. The SSH key used by CI is restricted to a single root-owned script. It can only ask for deploy , rollback or status. It has no shell. Only root can change that script, so a push to the repository can't widen what the key is allowed to do. If the key ever leaks, the damage is limited to those three actions.
- Constraints that shaped the design Some of the most useful decisions came from things I couldn't do: • A shared VPS. Other sites live on the same server, so I couldn't run a server-wide docker prune. The pipeline only cleans up SocialPost's own images, and deploys run as a dedicated user. • One backend container runs the post scheduler. A blue-green deploy would briefly run two backends, and that could publish a post twice. So I accepted a short restart gap of about 15 to 60 seconds per deploy instead. • Migrations run when the backend starts (Flyway). That means a rollback restores the old images, but not the database. This is why the backup before every deploy matters, and why migrations are checked in CI first. • A private repo on GitHub's free plan. Branch rulesets can't be enforced there, so some protection depends on me following the process rather than the platform blocking me.
- What it still can't do I don't want to oversell this: • Deploys are not zero-downtime. There is a short gap while the single backend restarts. • Rolling back does not undo database changes. • Some safeguards rely on discipline, not enforcement, because of the free-plan limit.
- What I'm taking away
- Make the safe path the easy path. Once deploying was one push, I stopped dreading releases.
- Constraints are useful. The single scheduler, the shared server and the free plan each pushed me toward a clearer design.
- Backups only count if you can restore them. That's why the backup is verified before the deploy goes ahead.
- Give automation the least power it needs. A key that can only run three commands is much easier to trust. [Add one real thing that broke or surprised you while building this, in two or three sentences.] Conclusion Setting this up taught me that CI/CD is less about tools and more about deciding what must be true before code reaches users. I still have things to improve, like reducing deploy downtime and enforcing the checks at the platform level. If you've dealt with deploys on a small shared server, I'd like to hear how you handle rollbacks when the database has already changed. SocialPost: socialpost.tech

Top comments (0)