Skip to content

Commit 5ac1998

Browse files
yo-takclaude
andauthored
feat(upload): add S3 bucket/template settings + MinIO dev profile (#18)
Backend settings: - `S3_BUCKET` and `S3_KEY_TEMPLATE` are added to `Settings` as optional `str | None`. The eventual upload service treats both being set as the gate for the feature being enabled; until the consumer code lands, this is a no-op for users who do not set them. Dev tooling — MinIO: - `docker-compose.yml` gains a `minio` service (`pgsty/minio:latest`, ports 9000 / 9001) and a one-shot `minio-init` (`minio/mc:latest`) that auto-creates the bucket named by `${S3_BUCKET:-lutra-recordings}`. Both live behind the `s3` compose profile, so `make up` is unaffected. - `make minio-up` / `make minio-down` wrap `docker compose --profile s3` for convenience; `make help` documents them. Docs: - `docs/SETUP.md` grows an "S3 Upload (optional)" section with the full env-var table and an example `.env` snippet, plus a "Local Testing with MinIO" subsection that documents the make targets, console URL, and the MinIO-flavoured `.env` snippet (backend reaches the service via the compose-internal `minio:9000`). Tests: - Upload-feature conftest extends the env-clear list with `S3_BUCKET` / `S3_KEY_TEMPLATE` so tests for the upcoming consumer code remain deterministic on dev hosts where these vars are now likely set in `.env`. 26 existing upload tests still pass; ruff + mypy clean. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 880d069 commit 5ac1998

5 files changed

Lines changed: 123 additions & 0 deletions

File tree

‎Makefile‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Simple launcher for use at robot sites
33

44
.PHONY: help up dev-up down restart logs ps build stream \
5+
minio-up minio-down \
56
lint lint-backend lint-frontend \
67
test test-backend test-frontend \
78
test-cov test-cov-backend test-cov-frontend \
@@ -23,6 +24,10 @@ help:
2324
@echo " make build - Build Docker images"
2425
@echo " make stream - Show the SSE stream (topic monitoring)"
2526
@echo ""
27+
@echo "Local S3 (MinIO, for testing the upload feature):"
28+
@echo " make minio-up - Start MinIO + auto-create the bucket"
29+
@echo " make minio-down - Stop MinIO"
30+
@echo ""
2631
@echo "Dev tools:"
2732
@echo " make lint - Lint (all: backend + frontend)"
2833
@echo " make lint-backend - Lint (ruff + mypy)"
@@ -100,6 +105,21 @@ build:
100105
stream:
101106
@curl -s -N http://localhost:8000/api/topics/stream
102107

108+
# ===== Local S3 (MinIO) =====
109+
110+
# Start MinIO and auto-create the bucket
111+
minio-up:
112+
@echo "=== Starting MinIO ==="
113+
docker compose --profile s3 up -d minio minio-init
114+
@echo "=== MinIO started ==="
115+
@echo " S3 API: http://localhost:9000"
116+
@echo " Console: http://localhost:9001 (user: minioadmin / pass: minioadmin)"
117+
@echo " Bucket: $${S3_BUCKET:-lutra-recordings}"
118+
119+
# Stop MinIO
120+
minio-down:
121+
docker compose --profile s3 down
122+
103123
# ===== Dev tools =====
104124

105125
# ----- lint -----

‎backend/app/settings.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ class Settings(BaseSettings):
9898
port: int = 8000
9999
debug: bool = False
100100

101+
# S3 upload destination. When either field is unset, the upload feature
102+
# is disabled (the eventual /api/upload/start endpoint refuses to enqueue
103+
# and the UI hides its affordances).
104+
s3_bucket: str | None = None
105+
s3_key_template: str | None = None # see app/features/upload/key_template.py
106+
101107
# S3 client settings.
102108
#
103109
# Credentials are NOT declared here — boto3 picks AWS_ACCESS_KEY_ID /

‎backend/tests/features/upload/conftest.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# from the dev container's .env, contaminating tests that exercise the
77
# unset / default code paths.
88
_S3_ENV_VARS = (
9+
"S3_BUCKET",
10+
"S3_KEY_TEMPLATE",
911
"AWS_REGION",
1012
"AWS_PROFILE",
1113
"AWS_ENDPOINT_URL",

‎docker-compose.yml‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,40 @@ services:
8989
- backend
9090
restart: unless-stopped
9191

92+
# --- MinIO: local S3-compatible object store (development only) ---
93+
minio:
94+
image: pgsty/minio:latest
95+
container_name: open-lutra-minio
96+
command: ["server", "/data", "--console-address", ":9001"]
97+
environment:
98+
- MINIO_ROOT_USER=${MINIO_ROOT_USER:-minioadmin}
99+
- MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD:-minioadmin}
100+
volumes:
101+
- minio_data:/data
102+
ports:
103+
- "9000:9000"
104+
- "9001:9001"
105+
profiles:
106+
- s3
107+
restart: unless-stopped
108+
109+
# --- MinIO bucket bootstrap (runs once and exits) ---
110+
minio-init:
111+
image: minio/mc:latest
112+
container_name: open-lutra-minio-init
113+
depends_on:
114+
- minio
115+
entrypoint: >
116+
/bin/sh -c "
117+
until mc alias set local http://minio:9000 ${MINIO_ROOT_USER:-minioadmin} ${MINIO_ROOT_PASSWORD:-minioadmin} >/dev/null 2>&1; do
118+
echo 'waiting for minio...'; sleep 1;
119+
done;
120+
mc mb --ignore-existing local/${S3_BUCKET:-lutra-recordings};
121+
echo 'bucket ready: ${S3_BUCKET:-lutra-recordings}';
122+
"
123+
profiles:
124+
- s3
125+
92126
volumes:
93127
frontend_node_modules:
128+
minio_data:

‎docs/SETUP.md‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Local Development Tools](#local-development-tools)
1010
- [Production Deployment](#production-deployment)
1111
- [Configuration](#configuration)
12+
- [S3 Upload (optional)](#s3-upload-optional)
1213
- [Simulator](#simulator)
1314
- [Troubleshooting](#troubleshooting)
1415

@@ -242,6 +243,65 @@ The `.env` file holds only infrastructure and connection settings:
242243

243244
---
244245

246+
## S3 Upload (optional)
247+
248+
Recordings can be uploaded to Amazon S3 (or any S3-compatible endpoint). The feature stays disabled until both `S3_BUCKET` and `S3_KEY_TEMPLATE` are set in `.env`.
249+
250+
| Variable | Required | Description |
251+
|------|------|------|
252+
| `S3_BUCKET` | yes | Destination bucket name |
253+
| `S3_KEY_TEMPLATE` | yes | Object-key template. Supports `{recording_name}` and `{yyyymmddhhmmss}` placeholders |
254+
| `AWS_REGION` | yes\* | AWS region |
255+
| `AWS_ACCESS_KEY_ID` | \*\* | Access key (env-var auth) |
256+
| `AWS_SECRET_ACCESS_KEY` | \*\* | Secret key (env-var auth) |
257+
| `AWS_PROFILE` | \*\* | Named profile (profile auth; mutually exclusive with the access-key pair) |
258+
| `AWS_ENDPOINT_URL` | no | Custom S3 endpoint (MinIO / R2 / LocalStack) |
259+
| `S3_MULTIPART_THRESHOLD_MB` | no | `boto3` TransferConfig override (default 8 MB) |
260+
| `S3_MULTIPART_CHUNKSIZE_MB` | no | `boto3` TransferConfig override (default 8 MB) |
261+
| `S3_MAX_CONCURRENCY` | no | `boto3` TransferConfig override (default 10) |
262+
263+
\* `AWS_REGION` may be resolved from the profile when using `AWS_PROFILE`.
264+
\*\* Exactly one of the two auth paths (env-var keys **or** profile) must be configured.
265+
266+
Example `.env` snippet (env-var auth):
267+
268+
```env
269+
S3_BUCKET=lutra-recordings
270+
S3_KEY_TEMPLATE=lutra-recordings/operation-files/{yyyymmddhhmmss}/{recording_name}.zip
271+
AWS_REGION=ap-northeast-1
272+
AWS_ACCESS_KEY_ID=...
273+
AWS_SECRET_ACCESS_KEY=...
274+
```
275+
276+
### Local Testing with MinIO
277+
278+
A `pgsty/minio` container is wired into `docker-compose.yml` behind the `s3` profile so the upload feature can be tested without touching real AWS. A one-shot `minio-init` container auto-creates the bucket on startup.
279+
280+
```bash
281+
make minio-up # Start MinIO + create the bucket defined by S3_BUCKET
282+
make minio-down # Stop MinIO
283+
```
284+
285+
| Endpoint | URL | Default credentials |
286+
|---|---|---|
287+
| S3 API | http://localhost:9000 | `minioadmin` / `minioadmin` |
288+
| Web console | http://localhost:9001 | `minioadmin` / `minioadmin` |
289+
290+
`.env` snippet to point the backend at the local MinIO (used alongside `make up`):
291+
292+
```env
293+
S3_BUCKET=lutra-recordings
294+
S3_KEY_TEMPLATE=lutra-recordings/operation-files/{yyyymmddhhmmss}/{recording_name}.zip
295+
AWS_REGION=us-east-1
296+
AWS_ACCESS_KEY_ID=minioadmin
297+
AWS_SECRET_ACCESS_KEY=minioadmin
298+
AWS_ENDPOINT_URL=http://minio:9000
299+
```
300+
301+
The backend reaches MinIO via the compose-internal hostname `minio:9000`. From the host (browser, `aws s3` CLI), use `http://localhost:9000` instead. The bucket name and the root credentials are configurable via `S3_BUCKET`, `MINIO_ROOT_USER`, and `MINIO_ROOT_PASSWORD` in `.env`.
302+
303+
---
304+
245305
## Simulator
246306

247307
In the development environment, the simulator publishes dummy data in place of a real robot.

0 commit comments

Comments
 (0)