Backend on Docker¶
The backend image is built from the repository's Dockerfile and run with docker-compose.yml.
Prerequisites: Docker Engine 24+ with Compose v2, and outbound access from the host to the LLM endpoint and the git servers.
The image¶
The image is built in two stages:
- Builder.
uv sync --frozen --no-devinstalls the locked dependencies into/app/.venv; the dependency layer is cached separately from the source. - Runtime.
python:3.13-slimwith onlygitandca-certificates, the virtual environment, the OSBtemplate/and theexample/TravelPermissionreference project.
Runtime defaults:
FORGE_ENV=production,FORGE_DATA_DIR=/data,FORGE_LOG_FORMAT=json.- Runs as the non-root user
10001:10001. HEALTHCHECKon/health/live;CMD middleware-forge serve --host 0.0.0.0 --port 8000.
For reproducible builds, pin the base image to a digest:
First deployment¶
-
Create the environment file.
cp deploy/backend.env.example deploy/backend.env # git-ignored, chmod 600 openssl rand -hex 32 # use as FORGE_API_KEY (and in IIS as ForgeApi__ApiKey)Set at least
FORGE_API_KEY,OPENAI_API_BASEandLLM_MODEL. See Configuration for everything else. -
Choose the listen address. By default the API is published on
127.0.0.1:8000, which the IIS server cannot reach. Use the Docker host's internal address: -
Build and start.
-
Run the smoke test from a machine that can reach the API.
-
Deploy the web UI (Web UI on IIS) with
ForgeApi__BaseUrl=http://10.0.0.15:8000and the same API key.
If the container exits right after starting, read docker compose logs forge-api: startup validation lists every configuration problem at once.
Container hardening¶
docker-compose.yml already sets:
- non-root user,
read_only: trueroot filesystem,tmpfsfor/tmp(256 MB) cap_drop: ALL,security_opt: no-new-privilegesrestart: unless-stoppedandstop_grace_period: 60s(in-flight runs finish or are resumable)- log rotation:
json-file, 5 files of 20 MB - the port published only on
FORGE_BIND_ADDRESS
Data and volumes¶
Everything the backend keeps is under /data, in the named volume middleware-forge-data (see Data model for the layout). To use a host folder instead, replace forge-data:/data with a bind mount owned by uid 10001:
sudo mkdir -p /srv/middleware-forge
sudo chown 10001:10001 /srv/middleware-forge && sudo chmod 750 /srv/middleware-forge
Database migrations run automatically at startup and are forward-only.
Secrets¶
| Secret | How to supply it |
|---|---|
FORGE_API_KEY |
deploy/backend.env (mode 600) or your orchestrator's secret store; the same value goes to IIS as ForgeApi__ApiKey |
| Repository tokens | A mounted file referenced by token_file, e.g. -v /etc/forge/ado-pat:/run/secrets/ado-pat:ro; or an environment variable named by token_env |
OPENAI_API_KEY |
Only if the LLM server needs one |
| Internal CA | Mount the PEM bundle read-only and set FORGE_CA_BUNDLE |
Never bake secrets into the image: .dockerignore excludes .env* and deploy/. Key rotation is described in Operations.
Repository write-back¶
Add the repositories to FORGE_REPOS (reference) and mount their tokens. For a local repository, mount the folder into the container and give uid 10001 write access.
The service account needs Code: Read & Write and Contribute to pull requests. Azure DevOps Server 2019 needs "api_version": "5.0".
Check the result on the System status page of the UI, or with GET /v1/repositories.