Skip to content

devops: prepare docker deployment setup - #12

Merged
its-gabo merged 1 commit into
mainfrom
gs_devops_prepare_docker_deployment
Nov 22, 2026
Merged

its-gabo merged 1 commit into
mainfrom
gs_devops_prepare_docker_deployment

Conversation

@its-gabo

Copy link
Copy Markdown
Owner

Summary

OpenStream can now be deployed to a single server from prebuilt Docker images. GitHub Actions builds an API, a web and an nginx image and publishes them to the GitHub Container Registry. The server only needs a compose file and an .env: it pulls the images and runs them behind Caddy and Cloudflare.

On every start, database migrations run first, and the API, worker and web app start only after they succeed. make local-up runs the same production setup on your machine, with images built from the checkout, to try a change before it ships.

What changed

Images (docker/)

  • API (docker/api/Dockerfile, ~345 MB): one image runs the HTTP API, the worker and migrations. entrypoint.sh picks one with the command server, worker or migrate.
    • Alpine-based, with Alpine's ffmpeg (6.1, the same major version CI tests with; x264 included). About 190 MB smaller than static ffmpeg builds.
    • Runs as a non-root user, with its own directory for video processing temp files.
  • Web (docker/web/Dockerfile, target web, ~187 MB): the server that renders pages, including embed pages, which call the API and set a Content-Security-Policy per embed. Distroless (nothing but Bun), non-root. Bun serves TanStack Start's handler directly, with no wrapper code.
  • Frontend (docker/web/Dockerfile, target nginx, ~96 MB): nginx with the browser assets built in. It serves /assets/* with year-long caching and gzip, serves public/ files, and passes every other request to web. It comes from the same build as the web image.
  • Builds:
    • Each Dockerfile starts with turbo prune <app> --docker, so dependencies only reinstall when manifests change.
    • The apps are bundled with bun build, so no image ships node_modules.
    • .dockerignore keeps node_modules, build output and env files out of the build context.

Bundling workarounds

  • No syntax minification: Bun 1.3.11's --minify-syntax breaks a labelled statement in React's server renderer, and the bundle only fails when that chunk loads. Both builds use --minify-whitespace --minify-identifiers, and I checked that every chunk in both images parses.
  • Native add-on: msgpackr-extract (an optional native add-on of BullMQ's msgpackr) is left out of the bundle; msgpackr falls back to plain JavaScript.
  • Migrations folder: migrate.js is bundled into dist/db/, so it still finds the migrations at ../../drizzle.
  • Stylesheet: the web build keeps the root .gitignore. Without it, Tailwind also scans node_modules, and the server-rendered page links to a stylesheet the client build never produced.

Production stack (docker-compose.prod.yml)

  • Services: db (Postgres 16), redis, migrate, app, worker, web and frontend.
  • Order: migrate waits for Postgres, and app, worker and web wait for migrate to finish successfully. A failed migration exits with code 1, so the app never starts on an old schema.
  • Redis: runs with appendonly yes and maxmemory-policy noeviction, as BullMQ requires.
  • Ports: only app (127.0.0.1:3001) and frontend (127.0.0.1:3080) are published, both on localhost. Caddy on the host routes /api/* to app and everything else to frontend.
  • Logs go to journald.
  • Worker: gets 2 minutes to finish running jobs (ffmpeg, transcription) before a stop.
  • Settings:
    • Read from .env (ENV_FILE can point elsewhere); .env.production.example lists them.
    • DATABASE_URL and REDIS_URL are set by the compose file.
    • REGISTRY and TAG pick the images, with TAG set to a commit SHA to pin a version.

Publishing

  • .github/workflows/docker-publish.yml (run from the Actions tab): builds the three images and pushes them to ghcr.io/<owner>/open-stream-{api,web,nginx}, tagged with the commit SHA and latest. It uses the built-in GITHUB_TOKEN and the GitHub Actions build cache.
  • Makefile: make docker-build builds the same images locally (or one at a time with docker-build-api, docker-build-web, docker-build-nginx), and make docker-push pushes them.

Local production-like stack (docker-compose.local.yml)

  • Override: layered on the production compose file, so it runs the same services with the same settings and production mode, from images built from the checkout.
  • Stand-ins:
    • a Caddy container for Cloudflare and the server's Caddy (https://localhost:8443, self-signed);
    • RustFS for the bucket (http://storage.localhost:9100);
    • Mailpit for SMTP (http://localhost:8125).
  • Storage address: browsers send storage.localhost to the local machine, and the containers map it to the host. Presigned video URLs therefore work from both.
  • Settings: in docker/local/local.env, with throwaway secrets, committed on purpose.
  • Ports: app and frontend are published on 13001 and 13080, so they don't collide with bun run dev.
  • Commands: make local-up, make local-logs s=app, make local-down.

@its-gabo its-gabo self-assigned this Nov 22, 2026
@vercel

vercel Bot commented Nov 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
open-stream Ready Ready Preview Nov 22, 2026 5:39pm UTC

@its-gabo
its-gabo merged commit fbb7b62 into main Nov 22, 2026
3 checks passed
@its-gabo
its-gabo deleted the gs_devops_prepare_docker_deployment branch November 22, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant