-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompose.yaml
More file actions
94 lines (89 loc) · 3.92 KB
/
compose.yaml
File metadata and controls
94 lines (89 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# compose.yaml — Recotem tutorial compose file
#
# This file is a runnable example for the getting-started tutorial. It is
# NOT for production use.
#
# Usage (3 commands from the repo root):
#
# 1. Generate a signing key + an API key
# $ docker run --rm ghcr.io/codelibs/recotem:latest keygen --type signing --kid dev
# # → copy the env_entry plaintext into RECOTEM_SIGNING_KEYS below
# $ docker run --rm ghcr.io/codelibs/recotem:latest keygen --type api --kid dev
# # → copy the env_entry hash into RECOTEM_API_KEYS below
# # → keep the api plaintext for later (used as X-API-Key header)
#
# 2. Train (one-shot)
# $ RECOTEM_SIGNING_KEYS="dev:..." \
# RECOTEM_API_KEYS="dev:sha256:..." \
# docker compose run --rm train
#
# 3. Serve + curl
# $ RECOTEM_SIGNING_KEYS="..." RECOTEM_API_KEYS="..." \
# docker compose up -d serve
# $ curl -sX POST http://localhost:8080/v1/recipes/purchase_log:recommend \
# -H "X-API-Key: <api plaintext>" \
# -H "Content-Type: application/json" \
# -d '{"user_id": "1", "limit": 5}'
x-recotem-image: &recotem-image
image: ghcr.io/codelibs/recotem:latest
# To build locally:
# build:
# context: .
# dockerfile: Dockerfile
services:
# ── train ──────────────────────────────────────────────────────────────────
# One-shot training job. Run via `docker compose run --rm train`.
# Exit codes: 0=success, 2=recipe error, 3=datasource error,
# 4=training error, 5=artifact error.
#
# Note: train does NOT bind any network port — it reads data, trains,
# and writes an artifact file. RECOTEM_ALLOWED_HOSTS, RECOTEM_API_KEYS,
# RECOTEM_HOST/PORT, and RECOTEM_ALLOWED_ORIGINS are serve-only variables
# and are intentionally omitted here.
train:
<<: *recotem-image
command: ["train", "/recipes/recipe.yaml"]
working_dir: /workspace
volumes:
- ./examples/tutorial-purchase-log:/recipes:ro
- artifacts:/workspace/artifacts
environment:
RECOTEM_SIGNING_KEYS: "${RECOTEM_SIGNING_KEYS}"
RECOTEM_LOG_FORMAT: "json"
restart: "no"
# ── serve ──────────────────────────────────────────────────────────────────
# Long-running prediction server. Hot-swaps when train rewrites the artifact.
serve:
<<: *recotem-image
command: ["serve", "--recipes", "/recipes"]
working_dir: /workspace
ports:
- "8080:8080"
volumes:
- ./examples/tutorial-purchase-log:/recipes:ro
- artifacts:/workspace/artifacts:ro
environment:
RECOTEM_SIGNING_KEYS: "${RECOTEM_SIGNING_KEYS}"
RECOTEM_API_KEYS: "${RECOTEM_API_KEYS}"
RECOTEM_HOST: "0.0.0.0"
RECOTEM_PORT: "8080"
RECOTEM_WATCH_INTERVAL: "10"
RECOTEM_LOG_FORMAT: "json"
RECOTEM_ENV: "production"
restart: unless-stopped
healthcheck:
test:
- "CMD-SHELL"
- "python -c \"import sys, urllib.request; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8080/health', timeout=5).status == 200 else 1)\""
interval: 30s
timeout: 10s
retries: 3
# Initial model load can take longer than the regular interval; bump
# this if your artifacts are large or stored on a slow object store.
start_period: 60s
# ── volumes ────────────────────────────────────────────────────────────────────
# Shared between train (writes) and serve (reads). The recipe writes to
# ./artifacts/purchase_log.recotem (CWD-relative); the working_dir above plus
# this mount resolve that to /workspace/artifacts.
volumes:
artifacts: