Last updated 1 min read

How to Deploy Vapor App on a VPS

Related: Server Side Swift.

There is a nice tutorial describing how to setup continuous deployment of a Vapor App on a VPS with [[github actions]].

There are a few pitfalls.

This workflow pulls the repo, compiles the app, and builds the docker image on the target instance.

It will cause downtime while the new container is being built, stopped and restarted. Building a Vapor App image isn't fast at all. It takes about 10 minutes for an empty Vapor App project to compile and build a docker image on a mediocre 2 Core 4GB RAM VPS.


Build the image somewhere else, push it to a docker image registry, then pull on the target instance and run.

In that case, the downtime would be reduced to the time of restarting a container. This could be achieved by using a watchtower setup described here

The problem is that the watchtower is a tool for a homelab kind of thing. Not intended for production as they state right in their repo:

Watchtower is intended to be used in homelabs, media centers, local dev environments, and similar. We do not recommend using Watchtower in a commercial or production environment. If that is you, you should be looking into using Kubernetes. If that feels like too big a step for you, please look into solutions like MicroK8s and k3s that take away a lot of the toil of running a Kubernetes cluster

So it looks like for proper container deployment with zero downtime there is no choice other than using [[Kubernetes]] engine or Docker Swarm or custom deployment scripts or deployment tooling like [[Kamal]].