Skip to content

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:

  1. Builder. uv sync --frozen --no-dev installs the locked dependencies into /app/.venv; the dependency layer is cached separately from the source.
  2. Runtime. python:3.13-slim with only git and ca-certificates, the virtual environment, the OSB template/ and the example/TravelPermission reference project.

Runtime defaults:

  • FORGE_ENV=production, FORGE_DATA_DIR=/data, FORGE_LOG_FORMAT=json.
  • Runs as the non-root user 10001:10001.
  • HEALTHCHECK on /health/live; CMD middleware-forge serve --host 0.0.0.0 --port 8000.

For reproducible builds, pin the base image to a digest:

docker compose build --build-arg PYTHON_IMAGE=python:3.13-slim-trixie@sha256:<digest>

First deployment

  1. 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_BASE and LLM_MODEL. See Configuration for everything else.

  2. 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:

    export FORGE_BIND_ADDRESS=10.0.0.15   # internal NIC of the Docker host
    export FORGE_PORT=8000
    
  3. Build and start.

    docker compose up -d --build --wait
    docker compose ps                         # forge-api should be "healthy"
    curl -s http://10.0.0.15:8000/health/ready
    
  4. Run the smoke test from a machine that can reach the API.

  5. Deploy the web UI (Web UI on IIS) with ForgeApi__BaseUrl=http://10.0.0.15:8000 and 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: true root filesystem, tmpfs for /tmp (256 MB)
  • cap_drop: ALL, security_opt: no-new-privileges
  • restart: unless-stopped and stop_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.