On this page

Deploying a Tenon web app as one static file

ADR-0282. Build a single Linux executable with no runtime dependencies, copy it to a server, run it under systemd, and put Caddy in front for TLS (ADR-0281: Tenon apps speak plain HTTP on loopback and leave TLS to a proxy).

1. Embed the assets

Assets in tenon.toml become an ordinary module, so the binary needs no files at run time:

[embed.assets]
dir = "public"
include = ["**/*.html", "**/*.css", "**/*.js", "**/*.png"]
import assets { get, text, paths, etag }

get returns bytes, text returns a string for UTF-8 files, and etag is a content hash. Run tenon gen --embed . assets to see the generated module. bench/static-app is a complete example that serves these files with web.static.serve. The recipe below deploys notes, which embeds public/ the same way and keeps its SQLite file in a state directory.

2. Build

tenon build --static --target x86_64-linux-musl main.tn -o app
scripts/dist/static-check.sh app x86_64     # no interpreter, no shared libraries

The build prints static: yes · x86_64-linux-musl · <size> · dynamic deps: none. It uses musl-gcc (Debian/Ubuntu: apt install musl-tools) for the host architecture, or zig cc 0.13+ for cross targets such as aarch64-linux-musl (resolved from $TENON_ZIG, Tenon's managed Zig installed by install.sh, or zig on PATH). FFI packages need static archives (E1152); libcurl is refused (E1153), so use the CurlProcess transport. macOS targets are best-effort and link only libSystem. Windows is unsupported (E1150).

3. Copy and run under systemd

scp app deploy@server:/tmp/notes
ssh deploy@server 'sudo install -D -m 0755 /tmp/notes /opt/notes/notes'

/etc/systemd/system/notes.service:

[Unit]
Description=notes (Tenon)
After=network.target

[Service]
ExecStart=/opt/notes/notes 8080 0 /var/lib/notes/notes.db
DynamicUser=yes
StateDirectory=notes
Restart=on-failure
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload && sudo systemctl enable --now notes

The app listens on 127.0.0.1:8080 only. The binary is the whole deploy; upgrades are a new scp plus systemctl restart notes.

4. Caddy for TLS

/etc/caddy/Caddyfile:

notes.example.com {
    encode zstd gzip
    reverse_proxy 127.0.0.1:8080
}

Caddy obtains and renews certificates automatically. Keep the app on loopback; it does not terminate TLS or trust forwarded headers.

Qualify a release

bench/static-app/qualify.sh [targets] builds, checks and (for the host target) serves the example with curl. It runs on demand and is not part of make check.