Deploy with Docker Compose
Это содержимое пока не доступно на вашем языке.
The Compose file in Get started is built for a first look. The changes below make it something you can leave running.
The Compose file and its .env
Section titled “The Compose file and its .env”services: setup: image: ghcr.io/redfox-soft/oauth-server-ts:<version> command: ['sh', '-c', 'bun run db:setup && bun run db:migrate'] env_file: .env restart: 'no'
oauth: image: ghcr.io/redfox-soft/oauth-server-ts:<version> ports: - '127.0.0.1:3000:3000' env_file: .env depends_on: setup: condition: service_completed_successfully restart: unless-stoppedwith a .env beside it:
ISSUER=https://auth.example.comMONGODB_URI=mongodb+srv://user:password@cluster.example.mongodb.netDATABASE_NAME=OAuthWhat changed from Get started, and why
Section titled “What changed from Get started, and why”Pin the image tag. Images are published to ghcr.io/redfox-soft/oauth-server-ts on every
release, tagged with the version and with latest. latest means a docker compose pull can move
you across a release you have not read the changelog for. Name the version instead, and change it
on purpose. That is also what turns the upgrade into a reviewable diff.
The published tags are listed on the
GitHub releases page and on the
container package page.
Verify the image once per version you adopt. Every release is signed over its digest and carries an SBOM and a build provenance attestation, so you can check the tag you just pinned instead of trusting it:
cosign verify \ --certificate-oidc-issuer https://token.actions.githubusercontent.com \ --certificate-identity-regexp '^https://github\.com/RedFox-Soft/OAuth-server\.ts/\.github/workflows/release\.yml@refs/tags/v' \ ghcr.io/redfox-soft/oauth-server-ts:<version>Run it in the same change that moves the pin, since that is usually when you are already reading the changelog. What is attached and how to read the SBOM.
Use a database you back up. The Get started file runs mongo:8 on a local named volume, which
is convenient and has no backups. Either point MONGODB_URI at a managed instance such as
MongoDB Atlas, or keep the local mongo service and treat the
volume as the production data it is:
mongo: image: mongo:8 volumes: - mongo-data:/data/db healthcheck: test: ['CMD', 'mongosh', '--quiet', '--eval', 'db.runCommand({ ping: 1 }).ok'] interval: 5s timeout: 5s retries: 12 restart: unless-stoppedwith depends_on: { mongo: { condition: service_healthy } } on the setup service, and a scheduled
mongodump against the volume. Everything a deployment cannot lose is in that database: end-user
accounts, clients, the audit trail, and the signing keys. The one exception is the
keyring that encrypts the stored secrets, which you keep apart from it.
To run PostgreSQL instead, swap the service for postgres:17, put POSTGRES_URL in the .env in
place of MONGODB_URI and DATABASE_NAME, and change the setup command to
['bun', 'run', 'db:setup:pg']. Set one connection string, never both. Given both, the server
refuses to start instead of picking one. PostgreSQL has the details.
restart: unless-stopped on the server, restart: 'no' on setup. The setup service is a
one-shot that must exit; restarting it would loop. The server should come back after a host reboot
or a crash. A server container that cannot reach the datastore exits at boot instead of serving, so
the restart policy is how it recovers once the database comes back.
Bind the port to loopback and put a proxy in front. '127.0.0.1:3000:3000' keeps the plaintext
port off the network. TLS terminates in the proxy, and ISSUER is the public https URL.
Behind a reverse proxy has the nginx and Caddy blocks and the one
setting you must get right there.
The keyring
Section titled “The keyring”The server encrypts the secrets it stores, such as application secrets and private signing keys, with a keyring: a key file that you hold outside the database. The keyring describes what it covers and how to rotate it.
Both shipped Compose files mount a named volume, foxauth-keyring, at /app/keyring on the oauth
service. That directory is where the server looks for its keyring file. Because the directory exists,
first-run setup can generate a keyring, write it there and use it at once. Setup also shows you the
keyring once: save a copy then.
For production, move the keyring into the .env instead:
KEYRING='{"v":1,"write":"<kid>","keys":{"<kid>":"<base64url key>"}}'Then delete foxauth.keyring from the volume. With the variable and the file both present, the server
refuses to start. To make a keyring yourself rather than through setup, the image carries the command:
docker run --rm ghcr.io/redfox-soft/oauth-server-ts:<version> bun run keyring newKeep a copy of the keyring apart from your database backups. The secrets in a mongodump or a volume
snapshot cannot be read without it.
Upgrading: change the tag and run setup again
Section titled “Upgrading: change the tag and run setup again”Change the tag and bring the stack up again:
docker compose pulldocker compose up -dsetup re-runs on every up, which is intended: both of its commands are safe to repeat, and
together they apply a new release’s collections, indexes, seed changes and schema migrations. The
server waits for it to complete successfully before starting, and would refuse to start without the
migrations anyway. When the release notes name a migration that cannot be undone, take a backup
before the up. The full checklist, including what a restart does and does not carry over, is in
Upgrading.