Infrastructure for shared ML work at CML. The current stack deploys an MLflow tracking server and serves it through a Cloudflare tunnel behind Access.
| Path | What it is |
|---|---|
compose.yaml |
Starts MLflow and the tunnel connector |
mlflow/ |
MLflow tracking server |
tunnel/ |
Cloudflare tunnel connector |
infra/ |
OpenTofu configuration for the tunnel, DNS, and Access |
bin/mlflow-restore-test |
On-demand check of a live database snapshot |
tests/ |
Shell tests run by just check |
.env.example |
Example settings for Docker Compose and just |
The host needs Docker Engine with the Compose plugin 2.20 or later, just, OpenTofu, curl,
and Bash 4 or later. just tofu runs on the host. just infra uses a container.
cp .env.example .envand fill it in. Docker Compose andjustboth read it.- Set up the tunnel once (below), so
$CMLOPS_STATE/tunnel-tokenexists. just setupcreates the MLflow store and the state dir as you, and checks the token file.docker compose up -d --wait. The services come back on their own after a crash or a reboot, untildocker compose down.
To run MLflow before the tunnel exists, skip step 2: just setup then creates the dirs, says
there is no token yet and exits 0, and docker compose up -d --wait mlflow starts MLflow alone.
Run just setup and the full docker compose up -d --wait once the token is there.
To take over a node that already runs MLflow and a tunnel from elsewhere:
- Set
CMLOPS_MLFLOW_STOREto the existing store. SetCMLOPS_STATEto the existing tunnel state directory. Keep the existing Compose definitions for rollback. - Run
just tofu init -reconfigure, then reviewjust tofu planfrom the existing state. Stop if the plan shows creates, deletes, replacements, or unexpected updates. Preserve existing hostnames inservicesinterraform.tfvars. Setteam_nameif the existing variables file doesn't have it. - Back up the database. Stop the old MLflow server and connector before starting the new ones.
- Run
just setupanddocker compose up -d --wait. Verify local health and access through the existing URL. If verification fails, stop the new services before restarting the old ones.
Every service binds to 127.0.0.1 only; the tunnel with Access is the only way in from outside. The service images in the compose files are pinned by tag and digest, and Dependabot bumps them; the tool images in the justfile are pinned the same way and bumped by hand.
One tracking server for every project on the node, on 127.0.0.1:${CMLOPS_MLFLOW_PORT:-5000}.
A client talks HTTP and never opens the database itself, so a project's locked MLflow version
need not match the store's schema: only the server's version does.
The store is $CMLOPS_MLFLOW_STORE, mounted at /mlflow: mlflow.db and artifacts/. Back it
up from the host. Copy the database through SQLite's backup API, never with cp while the server
runs, which can copy a half-written file:
docker compose exec mlflow python -c "import sqlite3; sqlite3.connect('/mlflow/mlflow.db').backup(sqlite3.connect('/mlflow/mlflow.db.bak'))"just mlflow-restore-test checks a fresh database snapshot on demand. It takes the snapshot
from a read-only mount and checks SQLite integrity. A temporary MLflow server uses the same
image as the deployed stack. The check compares the snapshot's run and experiment counts with
the live server's. It does not read an existing backup or restore artifacts. Test recovery
of the off-host database and artifacts separately.
To upgrade MLflow, follow the comment at the top of mlflow/compose.yaml.
export MLFLOW_TRACKING_URI=http://127.0.0.1:5000
curl -s http://127.0.0.1:5000/health # OKLeave the artifact location to the server: a new experiment gets mlflow-artifacts:/<id>, and
the client uploads artifacts through the server. A local artifact_location would record a path
only one checkout has. mlflow-skinny is enough on the client side.
To delete runs for good, back up mlflow.db as above, then name the runs:
docker compose exec mlflow mlflow gc --backend-store-uri sqlite:////mlflow/mlflow.db \
--artifacts-destination /mlflow/artifacts --run-ids <ids>Without --run-ids, gc purges every soft-deleted run in the store.
A Cloudflare tunnel publishes the node's web UIs behind Cloudflare Access, so a browser opens
them without ssh -L. infra/ holds the tunnel, its ingress rules (ending in a 404), the DNS
records, one Access application per hostname and one shared policy for the allowed emails. Access
sends a one-time PIN to those addresses only; a session lasts 24 hours. Each ingress rule also
makes cloudflared check the Access token for its own application, so a request without one never
reaches the service. The connector in
tunnel/compose.yaml only dials out, and binds only a metrics port on 127.0.0.1:20241 for its
healthcheck.
just tofu runs OpenTofu with everything private in $CMLOPS_STATE (mode 700): the state, its
.terraform dir and terraform.tfvars. just token writes the connector's token there.
-
In the Cloudflare dashboard (My Profile, API Tokens, Create Custom Token), make a token scoped to the account and the zone, with: Account, Cloudflare Tunnel, Edit; Account, Access: Apps and Policies, Edit; Zone, DNS, Edit.
-
Open the zone's Overview page: the API box in the right sidebar lists the Zone ID and the Account ID. The Zero Trust dashboard's settings show the team name (
team_name), the first part of<team_name>.cloudflareaccess.com. -
Fill in the variables (
set -a; . ./.env; set +aputsCMLOPS_STATEin the shell):mkdir -p -m 700 "$CMLOPS_STATE" cp infra/terraform.tfvars.example "$CMLOPS_STATE/terraform.tfvars" $EDITOR "$CMLOPS_STATE/terraform.tfvars"
-
Apply, with the API token in the environment for this shell only, then write the connector token:
read -rs CLOUDFLARE_API_TOKEN && export CLOUDFLARE_API_TOKEN just tofu init just tofu apply just token
Access sends the PIN only if the account has the One-time PIN login method (Zero Trust, Settings, Authentication).
Add subdomain = "http://127.0.0.1:<port>" to services in terraform.tfvars (the default is in
infra/variables.tf), then just tofu apply. The ingress rule, the DNS record and the Access
application all follow from that map, and the tests fail if a hostname would lack Access. The
connector picks up the new route on its own, since the tunnel is managed from Cloudflare.
-
MLflow has no login. Access is its only gate, so every hostname gets an Access application, and
tofu testchecks that. -
Keep the services bound to 127.0.0.1. Then the local network cannot reach them directly, and the only way in from outside is through Access.
servicesrefuses anything else. -
The tunnel token lets whoever holds it run a connector for this tunnel, and so serve its hostnames. It lives only in
$CMLOPS_STATE/tunnel-token(mode 600, checked byjust setup) and in the state file next to it. To rotate it, replace the tunnel and its token:just tofu apply -replace=cloudflare_zero_trust_tunnel_cloudflared.node just token docker compose up -d --force-recreate cloudflared
The new tunnel gets a new ID, and the DNS records follow it in the same apply.
just check # compose config, shell lint, secrets in history, hygiene, tofu fmt/validate/test and tests/
prek install # the git hooks: file checks and linters on commit, the message on commit, `just check` on push
just hooks # every git hook over the whole repo, as the checks workflow doesThe linters and OpenTofu run in pinned containers, so just check needs Docker, and network
access for the images and for tofu init to fetch the provider. The hooks need prek. A test
that cannot run on the machine (no Docker, not Linux) prints SKIP and does not fail, except when
CI is set, as GitHub Actions does: there a skip fails the run.
MIT. Per-file licensing is in REUSE.toml.