Deployer: Self-Hosted CI/CD for Swift Server Apps

GitHub repository: click here.

I built a self-hosted CI/CD tool specifically for Swift server apps powered by the Vapor framework. When you git push new code to your app's repository, Deployer intercepts this using webhooks. It then builds your app (swift build) and restarts it on your server.

A reactive live dashboard provides real time build output streams and deployment status changes, as well as start and stop buttons for your app and run buttons for the commits pushed on main. You can either use manual mode where deployments only start by pressing the run button in the panel, or automatic mode, where deployments happen instantly once new code is pushed. Only one build can run at a time; the last commit wins when multiple are pushed concurrently.

Most Swift server deploy setups I’ve tried ended up being a mix of shell scripts, GitHub Actions, and manual SSH steps. I wanted something simpler that allows for quick interation and production testing while being fully self-hosted. Deployer handles initial server setup through an automated and interactive CLI command, so it’s suitable even for developers that are new to server-side Swift.

Tech Stack

Setup

To bootstrap on a fresh Ubuntu VPS, run (as root):

bash <(curl -sSL https://mottzi.codes/deployer/setup.sh)
  1. Installs Swift (via Swiftly).

  2. Configures Nginx reverse proxy

  3. Issues TLS certificates (using Let's encrypt).

  4. Sets up the GitHub webhook and deploy key.

  5. Brings your app online.

Control

You manage Deployer via deployerctl, for example:

sudo deployerctl start  # starts deployer and app 
sudo deployerctl status app
sudo deployerctl stop deployer
sudo deployerctl update # updates deployer itself

I'm interested in your thoughts and feedback. This release is pretty bear bones feature wise. It may have some rough edges, especially the front-end. You are very welcome to contribute, if you choose so.

9 Likes

Is it mandatory to use sudo command?

Yes, sudo is currently enforced. You must use sudo deployer setup to install the environment, and sudo deployerctl <cmd> (update, restart, etc.) to manage it. Initial setup requires root because it installs packages, creates users, and configures system components like nginx and systemd.

That said, after setup the deployer and your app run as an unprivileged service user (e.g. vapor). Even when invoked via sudo, deployerctl immediately drops privileges and executes all runtime operations as that user.

Technically, the service user can manage its own services via systemctl --user, but deployerctl is currently designed as an operator-only control surface and enforces root. I think I'll revisit this and make non-root usage possible for commands where it’s technically feasible.

1 Like

I found some time to continue working on Deployer. Here is an update (v0.2.0):

The pitch is still generally the same: You git push your Swift app, Deployer catches the webhook, runs the pipeline, swaps the binary, restarts the service. A live dashboard streams the whole thing into your browser in real time (build output, status changes). No page refreshes required. One setup command on a fresh Ubuntu VPS and you're good to go.

What's new? You can now roll back to prior deployments: Every successful build gets archived, and clicking Runon a previous one swaps the binary back in instantly with no rebuild. This behaviour is configurable: you can keep the n newest builds, save n builds until a disk size limit is reached, keep everything, or keep nothing. This was the biggest piece of feedback from 0.1.

The whole pipeline now streams into the panel in real time. git fetch, git checkout, swift test, swift build, the binary swap, all of it. Before only the build step streamed its output to the clients. If a step fails, that step lights up red and the full transcript stays attached to the deployment so you can read it back later. I've added support for tests, which can be started automatically before every build, or manually by hitting the Testbutton on a deployment.

There's a settings page for editing your app's .env variables from the panel. One less thing you'd have to do via a terminal / SSH. Make an edit or add a new variable in the panel, click restart and the change is live. And Deployer can update itself now, from a button in the panel, with auto-rollback if the new version fails to boot. The old deployerctl update still works through the terminal.

The websocket panel does ping/pong heartbeats and per-component state restoration now so flaky connections doesn't desync the UI (or reconnecting clients, e.g. the laptop lid was closed, etc). If the server reboots or Deployer crashes mid-deployment, it, at next startup, picks up the most recent stranded push and resumes. And there's a new logo and a pretty significant amount of styling work on the panel itself.

2 Likes