A lab on two VPS: Semaphore and gitness
Our lab is two ordinary VPS machines running Docker Compose, and the whole infrastructure is described in a single repository and brought up from a clean server with a few button clicks. The main criterion is simple: you can wipe a server and get exactly the same state back without having to remember anything.
The lab is still a proving ground: changes are tried out on us first, not in a client's project. But real services live on it — this site, a CRM and three more products — with their own domains, certificates and monitoring.
Two servers and three layers
There are two servers, each with its own role:
- infra — everything that supports development: Traefik, Postgres, Valkey, gitness (git, image and crate registries, CI/CD), Kaneo for tasks, AppFlowy for documentation, ExcaliDash for Excalidraw boards and the observability stack (Prometheus, Loki, Tempo, Grafana, Alloy);
- production — what users see: Traefik, Postgres, Valkey, SeaweedFS as S3 storage and five web services written in Rust.
On top of them sit three layers, each described in code: management (Semaphore UI and
ansible), delivery (gitness with pipelines in .harness/) and
observability (OpenTelemetry in the applications, Grafana on infra).
Semaphore UI: buttons instead of manual commands
We start Semaphore with a single docker compose up command. A one-shot
provision service creates two projects from JSON —
infrastructure and production — with a ready-made set of
tasks. They are numbered because Semaphore sorts them by name:
0. Full cycle
1. Install Docker
2. Deploy stack
3. Status
...
The "Full cycle" task runs all the steps in a row, while the individual tasks exist so you can
repeat a step that failed. Under the hood these are ordinary ansible playbooks:
deploy.yml renders the templates from
templates/<infra|prod>/ into /opt/stack on the
server and runs docker compose up. The stack configuration is a
folder of templates, not a set of commands that somebody once ran by hand.
Secrets in git, but encrypted
All passwords, keys and tokens live in a single file, vault.yml,
encrypted with ansible-vault. The file is committed to the repository, and its password
is entered once into Semaphore's key store:
cd bootstrap/ansible
ansible-vault edit inventory/vars/vault.yml
The templates take their values from the vault, and before running, the playbook checks that the
required variables exist — an error about a missing password arrives immediately, not
on the third step. It is the same with certificates: to avoid hitting the Let's Encrypt
limit (five identical certificates per week) when a server is recreated, we
keep the public part of acme.json in the template and the private keys in the
vault. A new server starts with the certificates already issued.
gitness: git, registries and CI in one place
gitness replaced our combination of a git host, an image registry and a CI system. It hosts the repository, the Docker registry for service images, the Cargo registry for shared crates, and the pipelines. A playbook sets it up as well: it creates the space, the registries and the users with minimal permissions, puts the code into the repository and registers the pipelines.
The code is a monorepo with one Cargo workspace and one
Cargo.lock. The shared libraries (authorization, mail, system
tasks, observability) live in packages/ and are published to our
Cargo registry, while the services pull them in as ordinary dependencies. So that the build does not
recompile the whole dependency graph every time, we build two base images: all the
dependencies are already compiled in them, and a service image adds only its own
code.
From push to production
There are three pipelines, and their names speak for themselves:
-
main— runs on every push tomain: it publishes new versions of the crates, rebuilds the images and rolls out the services; -
build— the same build steps without the deploy, started manually; deploy— the rollout only, also started manually.
steps:
- name: publish-packages # new versions of the shared crates to the Cargo registry
- name: build-base # base images: compiled dependencies
- name: build-services # images of the five services
- name: deploy # ssh to production, one service at a time
The deploy is an ssh connection to the production server with a dedicated key that can do
exactly one thing: run the script deploy-service.sh <service>. In
authorized_keys it looks like this:
restrict,command="/opt/stack/deploy-service.sh" ssh-ed25519 AAAA…
The script runs docker compose pull and up -d for the
named service; the container is recreated only if the image has changed. If
someone gets hold of the key, all they can do is restart our own
services.
When the cache is warm, it takes minutes from a push to an updated site. The first build on an empty registry takes about half an hour — but after that the base images are rebuilt only when the dependencies change.
Logs, metrics and traces in one Grafana
The applications send metrics and traces over OpenTelemetry (OTLP over http), write logs in JSON with a trace identifier, and Alloy collects the container logs and, on production, the host and container metrics as well. Everything arrives on infra: Prometheus, Loki and Tempo sit behind a shared basic authentication.
In Grafana every service has its own dashboard, and there are jumps between the signals: from a request with a 500 error to its trace, from the trace to the log lines, from a log with a panic to the backtrace. The dashboards are ordinary JSON files in the repository, and when a server is recreated they appear on their own.
The pitfalls we ran into
The "wipe and repeat" idea is good because it brings to the surface everything that used to be held together by manual memory:
- The Let's Encrypt limit. Several test recreations in a row run into the five identical certificates per week — hence the scheme with certificates in the template and keys in the vault.
-
Crate checksums. A new registry publishes the same
versions with different checksums, and the committed
Cargo.lockstops building. Now the pipeline checks the lock against the registry and updates it itself in a separate commit. - Repository import. The background import job in gitness on a fresh server started only at the scheduler's next 20-minute check. We replaced it with a plain clone and push — and stopped waiting.
- The Traefik timeout. Heavy image pushes were cut off at 60 seconds of reading — the timeout had to be disabled.
Summary
Two servers, one repository, one Full cycle button.
The same "simple and in one place" principle that makes us love a clean monolith instead of microservices, we applied to infrastructure: no magic on the servers, everything lives in git, and a server can be recreated without fear of forgetting how it was configured.
For why we write our own services in Rust, see the article Rust and Zig in everyday applications.