Repository navigation
devops: prepare docker deployment setup - #12
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-upruns the same production setup on your machine, with images built from the checkout, to try a change before it ships.What changed
Images (
docker/)docker/api/Dockerfile, ~345 MB): one image runs the HTTP API, the worker and migrations.entrypoint.shpicks one with the commandserver,workerormigrate.docker/web/Dockerfile, targetweb, ~187 MB): the server that renders pages, including embed pages, which call the API and set aContent-Security-Policyper embed. Distroless (nothing but Bun), non-root. Bun serves TanStack Start's handler directly, with no wrapper code.docker/web/Dockerfile, targetnginx, ~96 MB): nginx with the browser assets built in. It serves/assets/*with year-long caching and gzip, servespublic/files, and passes every other request toweb. It comes from the same build as the web image.turbo prune <app> --docker, so dependencies only reinstall when manifests change.bun build, so no image shipsnode_modules..dockerignorekeepsnode_modules, build output and env files out of the build context.Bundling workarounds
--minify-syntaxbreaks 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.msgpackr-extract(an optional native add-on of BullMQ's msgpackr) is left out of the bundle; msgpackr falls back to plain JavaScript.migrate.jsis bundled intodist/db/, so it still finds the migrations at../../drizzle..gitignore. Without it, Tailwind also scansnode_modules, and the server-rendered page links to a stylesheet the client build never produced.Production stack (
docker-compose.prod.yml)db(Postgres 16),redis,migrate,app,worker,webandfrontend.migratewaits for Postgres, andapp,workerandwebwait formigrateto finish successfully. A failed migration exits with code 1, so the app never starts on an old schema.appendonly yesandmaxmemory-policy noeviction, as BullMQ requires.app(127.0.0.1:3001) andfrontend(127.0.0.1:3080) are published, both on localhost. Caddy on the host routes/api/*toappand everything else tofrontend..env(ENV_FILEcan point elsewhere);.env.production.examplelists them.DATABASE_URLandREDIS_URLare set by the compose file.REGISTRYandTAGpick the images, withTAGset 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 toghcr.io/<owner>/open-stream-{api,web,nginx}, tagged with the commit SHA andlatest. It uses the built-inGITHUB_TOKENand the GitHub Actions build cache.make docker-buildbuilds the same images locally (or one at a time withdocker-build-api,docker-build-web,docker-build-nginx), andmake docker-pushpushes them.Local production-like stack (
docker-compose.local.yml)https://localhost:8443, self-signed);http://storage.localhost:9100);http://localhost:8125).storage.localhostto the local machine, and the containers map it to the host. Presigned video URLs therefore work from both.docker/local/local.env, with throwaway secrets, committed on purpose.appandfrontendare published on 13001 and 13080, so they don't collide withbun run dev.make local-up,make local-logs s=app,make local-down.