---
estimated_steps: 8
estimated_files: 4
skills_used: []
---

# T01: Capture git commit SHA in Docker build and pipeline metadata

Add GIT_COMMIT_SHA build arg to Dockerfile.api, pass it from docker-compose.yml, write it to /app/.git-commit. Add a helper function in stages.py that reads the SHA from the file (Docker) or runs `git rev-parse --short HEAD` (local dev) with fallback to "unknown". Extend `_capture_pipeline_metadata()` to include the `git_commit_sha` key. Add `git_commit_sha` setting to config.py as an additional fallback.

**Important context for executor:** The canonical codebase is on ub01 at `/vmPool/r/repos/xpltdco/chrysopedia`. SSH with `ssh ub01` to edit files and test. The Docker compose stack runs there. The local working directory has .gsd/ planning artifacts only.

Steps:
1. SSH to ub01, edit `docker/Dockerfile.api` — add `ARG GIT_COMMIT_SHA=unknown` and `RUN echo "${GIT_COMMIT_SHA}" > /app/.git-commit` after the `COPY backend/ /app/` line
2. Edit `docker-compose.yml` — add `args: GIT_COMMIT_SHA: ${GIT_COMMIT_SHA:-unknown}` to both `chrysopedia-api` and `chrysopedia-worker` build sections (they already have `build: context: . dockerfile: docker/Dockerfile.api`)
3. Edit `backend/config.py` — add `git_commit_sha: str = "unknown"` field to Settings class
4. Edit `backend/pipeline/stages.py` — add `_get_git_commit_sha()` helper that tries: (a) read `/app/.git-commit` file, (b) run `subprocess.run(['git', 'rev-parse', '--short', 'HEAD'])`, (c) return `get_settings().git_commit_sha`, (d) return `"unknown"`. Add `"git_commit_sha": _get_git_commit_sha()` to the dict returned by `_capture_pipeline_metadata()`
5. Verify: run `python -c "from pipeline.stages import _capture_pipeline_metadata; print(_capture_pipeline_metadata())"` from backend dir (should show git_commit_sha key)

## Inputs

- ``docker/Dockerfile.api` — existing Dockerfile to add build arg to`
- ``docker-compose.yml` — existing compose file to add build args to api and worker services`
- ``backend/config.py` — existing Settings class to add git_commit_sha field`
- ``backend/pipeline/stages.py` — existing `_capture_pipeline_metadata()` function (line 557) to extend`

## Expected Output

- ``docker/Dockerfile.api` — contains ARG GIT_COMMIT_SHA and RUN echo to .git-commit`
- ``docker-compose.yml` — api and worker services have GIT_COMMIT_SHA build arg`
- ``backend/config.py` — Settings has git_commit_sha field`
- ``backend/pipeline/stages.py` — `_get_git_commit_sha()` helper added, `_capture_pipeline_metadata()` returns git_commit_sha key`

## Verification

ssh ub01 'cd /vmPool/r/repos/xpltdco/chrysopedia/backend && python -c "from pipeline.stages import _capture_pipeline_metadata; import json; m = _capture_pipeline_metadata(); assert \"git_commit_sha\" in m, f\"missing key: {m.keys()}\"; print(json.dumps(m, indent=2))"'
