Skip to content

Deploying a Kellnr App

Introduction

Kellnr is a self-hosted private crate registry for Rust. Deploying Kellnr with a Dockerfile on Klutch.sh gives you reproducible builds, managed secrets, and persistent storage for crates and metadata—all configured from klutch.sh/app. This guide covers installation, repository preparation, a production-ready Dockerfile, deployment steps, Nixpacks overrides, and best practices for secure crate publishing.


Prerequisites

  • A Klutch.sh account (create one)
  • A GitHub repository containing your Kellnr configuration (GitHub is the only supported git source)
  • Docker familiarity and Rust toolchain knowledge
  • PostgreSQL credentials (required by Kellnr)
  • Storage for crate files and database backups

Review the Quick Start for repo setup.


Architecture and ports

  • Kellnr exposes HTTP on port 8000; set the internal container port to 8000.
  • PostgreSQL runs as a separate Klutch.sh TCP app, exposed on port 8000 and reachable internally on 5432.
  • Persistent storage is required for the crate store.

Repository layout

kellnr/
├── config/ # Kellnr config files (e.g., Rocket.toml)
├── Dockerfile # Must be at repo root for auto-detection
├── docker-entrypoint.sh # Optional entrypoint
├── .env.example # Template only; no secrets
└── README.md

Keep secrets out of Git; store them in Klutch.sh environment variables.


Installation (local) and starter commands

Install dependencies and run locally before pushing to GitHub:

Terminal window
cargo build --release
DATABASE_URL=postgres://user:pass@localhost:5432/kellnr \
RUST_LOG=info \
./target/release/kellnr

Optional start.sh for portability and Nixpacks fallback:

#!/usr/bin/env bash
set -euo pipefail
./target/release/kellnr

Make it executable with chmod +x start.sh.


Dockerfile for Kellnr (production-ready)

Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):

FROM rust:1.72-slim AS build
WORKDIR /app
RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*
COPY . .
RUN cargo build --release
FROM debian:12-slim
WORKDIR /app
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=build /app/target/release/kellnr /app/kellnr
COPY config /app/config
ENV PORT=8000
EXPOSE 8000
CMD ["/app/kellnr"]

Notes:

  • Pin the Rust toolchain for consistent builds.
  • Copy only the built binary and configs into the runtime image to keep it slim.

Environment variables (Klutch.sh)

Set these in the Klutch.sh app settings (Secrets tab) before deploying:

  • PORT=8000
  • DATABASE_URL=postgres://<user>:<password>@<host>:<port>/<db>
  • KELLNR_URL=https://example-app.klutch.sh
  • RUST_LOG=info
  • KELLNR_ALLOW_REGISTRATIONS=true (set to false for private-only access)

If you deploy without the Dockerfile and need Nixpacks overrides:

  • NIXPACKS_BUILD_CMD=cargo build --release
  • NIXPACKS_START_CMD=./target/release/kellnr
  • NIXPACKS_RUST_VERSION=1.72
  • NIXPACKS_GO_VERSION=1.21 (omit unless you add Go-based sidecars)

These keep Kellnr compatible with Nixpacks defaults when a Dockerfile is absent.


Attach persistent volumes

In Klutch.sh storage settings, add mount paths and sizes (no names required):

  • /app/data — for crate storage and metadata.
  • /app/config — optional if you want runtime-editable config persisted.

Ensure these paths are writable inside the container.


Deploy Kellnr on Klutch.sh (Dockerfile workflow)

  1. Push your repository (with the Dockerfile at the root) to GitHub.
  2. Open klutch.sh/app, create a project, and add an app.
  1. Connect the GitHub repository; Klutch.sh automatically detects the Dockerfile.
  2. Choose HTTP traffic for Kellnr.
  3. Set the internal port to 8000.
  4. Add the environment variables above (database URL, Kellnr URL, log level, and any NIXPACKS_* overrides if you temporarily deploy without the Dockerfile).
  5. Attach persistent volumes for /app/data (and /app/config if used), selecting sizes that fit your crate storage needs.
  6. Deploy. Your registry will be reachable at https://example-app.klutch.sh; attach a custom domain if desired.

For PostgreSQL on Klutch.sh, create a separate TCP app, expose it on port 8000, and point DATABASE_URL to that endpoint (internal port 5432).


Sample configuration snippet

Add a config/Rocket.toml snippet for hosted URL and database:

[default]
address = "0.0.0.0"
port = 8000
log = "normal"
[default.databases]
postgres = { url = "postgres://USER:PASSWORD@HOST:5432/DB" }

Health checks and production tips

  • Use a reverse proxy health endpoint (e.g., /) for uptime monitoring.
  • Enforce HTTPS at the edge; forward HTTP to port 8000 internally.
  • Keep Rust, dependencies, and the Kellnr binary pinned; upgrade intentionally.
  • Monitor disk usage on /app/data and resize before it fills.
  • Back up PostgreSQL and crate storage regularly; do not rely on container filesystems for durability.

Kellnr on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage for crates, and flexible HTTP/TCP routing. With the Dockerfile at the repo root and port 8000 configured, you can serve a secure, private Rust crate registry without extra YAML or workflow overhead.