Skip to content

Deploying a Linkwarden App

Introduction

Linkwarden is an open-source, self-hosted bookmark and archive manager built on Node.js and Next.js. Deploying Linkwarden with a Dockerfile on Klutch.sh provides reproducible builds, managed secrets, and persistent storage for archives and metadata—all managed from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample usage, and production tips.


Prerequisites

  • A Klutch.sh account (create one)
  • A GitHub repository containing your Linkwarden code/config (GitHub is the only supported git source)
  • Docker familiarity and Node.js 18+ knowledge
  • PostgreSQL credentials (required)
  • Storage for snapshots, uploads, and logs

For onboarding, see the Quick Start.


Architecture and ports

  • Linkwarden serves HTTP; set the internal container port to 3000.
  • PostgreSQL should run as a separate Klutch.sh TCP app, exposed on port 8000, connected internally on 5432.
  • Persistent storage is required for archives/uploads and recommended for logs.

Repository layout

linkwarden/
├── Dockerfile # Must be at repo root for auto-detection
├── package.json
├── pnpm-lock.yaml # or yarn.lock / package-lock.json
├── .env.example # Template only; no secrets
├── public/ # Static assets
├── uploads/ # Snapshots/uploads (mount as volume)
└── 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
pnpm install
pnpm build
pnpm start -- --port 3000

Optional helper start.sh for portability and Nixpacks fallback:

#!/usr/bin/env bash
set -euo pipefail
pnpm prisma migrate deploy || true
exec pnpm start -- --port 3000

Make it executable with chmod +x start.sh.


Dockerfile for Linkwarden (production-ready)

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

FROM node:18-alpine AS build
WORKDIR /app
COPY package.json pnpm-lock.yaml* yarn.lock* package-lock.json* ./
RUN corepack enable
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build
FROM node:18-alpine
WORKDIR /app
ENV NODE_ENV=production PORT=3000
COPY --from=build /app /app
RUN corepack enable && pnpm install --prod --frozen-lockfile
EXPOSE 3000
CMD ["pnpm", "start", "--", "--port", "3000"]

Notes:

  • Add build tools (apk add --no-cache python3 make g++) in the build stage if native modules are needed.
  • Keep uploads/ writable and mount it as a volume for snapshots and assets.

Environment variables (Klutch.sh)

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

  • NODE_ENV=production
  • PORT=3000
  • DATABASE_URL=postgres://<user>:<password>@<host>:<port>/<db>
  • NEXTAUTH_SECRET=<secure-nextauth-secret>
  • JWT_SECRET=<secure-jwt-secret>
  • NEXTAUTH_URL=https://example-app.klutch.sh
  • Optional provider keys (e.g., GITHUB_ID, GITHUB_SECRET) if enabling OAuth

If you deploy without the Dockerfile and need Nixpacks overrides:

  • NIXPACKS_BUILD_CMD=pnpm install --frozen-lockfile && pnpm build
  • NIXPACKS_START_CMD=pnpm start -- --port 3000
  • NIXPACKS_NODE_VERSION=18

These keep Linkwarden 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/uploads — required for snapshots/uploads.
  • /app/logs — optional if you store logs locally.

Ensure these paths are writable inside the container.


Deploy Linkwarden 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 Linkwarden.
  3. Set the internal port to 3000.
  4. Add the environment variables above (database URL, secrets, OAuth keys if used, and any NIXPACKS_* overrides if you temporarily deploy without the Dockerfile).
  5. Attach persistent volumes for /app/uploads (and /app/logs if used), selecting sizes that fit your storage needs.
  6. Deploy. Your Linkwarden instance will be reachable at https://example-app.klutch.sh; attach a custom domain if desired.

Sample API usage

Create a bookmark via the API (replace placeholders):

Terminal window
curl -X POST "https://example-app.klutch.sh/api/bookmarks" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{"url": "https://klutch.sh", "title": "Klutch.sh Docs"}'

Health checks and production tips

  • Add a reverse proxy probe to / or a lightweight status route.
  • Enforce HTTPS at the edge; forward HTTP to port 3000 internally.
  • Keep lockfiles committed and Node version pinned for reproducible builds.
  • Monitor PostgreSQL performance and set connection pools to match your deployment size.
  • Rotate secrets (NextAuth/JWT/OAuth) regularly; keep them only in Klutch.sh secrets.
  • Monitor disk usage on /app/uploads and resize volumes before they fill.

Linkwarden on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage for snapshots, and flexible HTTP/TCP routing. With the Dockerfile at the repo root and port 3000 configured, you can deliver a reliable bookmark and archive platform without extra YAML or workflow overhead.