mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-12-02 18:08:07 +09:00
## Summary - Fix the deploy health check test payload and status value mismatches that prevented blue-green swaps from ever completing - Follow-up to #642 which fixed the error handling / rollback conditions ## Changes - **Missing required fields**: `encode-preview` requires `audio_gcs_path` and `output_gcs_path` but the health check only sent `job_id`, `ass_gcs_path`, and `duration_seconds` (caused HTTP 422). Added a 3-second test audio file and proper output path. - **Status polling mismatch**: Polling checked for `"completed"` but the GCE worker returns `"complete"` — would always time out even on success. - **Submit response mismatch**: Validated against `"completed"` which is never returned — endpoint returns `"accepted"`, `"cached"`, or `"in_progress"`. ## Root Cause The test payload was written based on the plan doc which had an incomplete request schema. The `audio_gcs_path` and `output_gcs_path` fields have been required since the endpoint was first created (PR #200, Jan 2026). The status string mismatch (`"completed"` vs `"complete"`) was likely a typo that was never caught because the request always failed before reaching the polling stage. ## Testing - Previous deploy (#642) confirmed the 422 error and verified rollback now triggers correctly - This fix addresses the payload so the encode test can actually succeed and the swap can complete - Real validation: next deploy after merge @coderabbitai ignore --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Encoding Worker Deployment
This directory contains the scripts for the GCE encoding worker's immutable deployment pattern.
Architecture
┌─────────────────────────────────────────────────────────────────┐
│ PACKER IMAGE (rarely changes) │
├─────────────────────────────────────────────────────────────────┤
│ - Python 3.13, FFmpeg, fonts (static dependencies) │
│ - bootstrap.sh (downloads startup.sh from GCS) │
│ - systemd service definition │
└─────────────────────────────────────────────────────────────────┘
│
▼ downloads on every service start
┌─────────────────────────────────────────────────────────────────┐
│ GCS (CI-managed, always current) │
├─────────────────────────────────────────────────────────────────┤
│ gs://karaoke-gen-storage-nomadkaraoke/ │
│ ├── encoding-worker/ │
│ │ ├── startup.sh ← Main logic (this file) │
│ │ └── version.txt ← Expected version number │
│ └── wheels/ │
│ └── karaoke_gen-current.whl ← Latest wheel (fixed path) │
└─────────────────────────────────────────────────────────────────┘
Files
| File | Location | Purpose |
|---|---|---|
bootstrap.sh |
Baked in Packer image | Downloads and runs startup.sh |
startup.sh |
Deployed to GCS by CI | Main startup logic |
version.txt |
Written to GCS by CI | Expected version for verification |
Deployment Flow
- CI builds wheel → uploads to
wheels/karaoke_gen-current.whl - CI uploads startup.sh →
encoding-worker/startup.sh - CI writes version →
encoding-worker/version.txt - CI restarts service → triggers bootstrap.sh
- bootstrap.sh downloads fresh startup.sh from GCS
- startup.sh downloads wheel, installs, verifies version
- CI verifies health endpoint returns correct version
- CI FAILS if version mismatch
Why This Pattern?
Before (problematic)
- startup.sh baked into Packer image
- Required image rebuild + VM recreation for logic changes
- 51 versioned wheels, sorting could fail
- CI warned on version mismatch but continued
After (robust)
- startup.sh downloaded from GCS on every start
- Logic changes via CI, no image rebuild needed
- Fixed path
karaoke_gen-current.whl, no sorting - CI FAILS on version mismatch
Modifying Startup Logic
- Edit
infrastructure/encoding-worker/startup.sh - Push to main
- CI automatically deploys to GCS
- Service restart picks up new script
No Packer image rebuild needed!
When to Rebuild Packer Image
Only rebuild when changing:
- Python version
- FFmpeg version
- System packages/fonts
- bootstrap.sh (should be extremely rare)
Manual Operations
# Check current version on VM
gcloud compute ssh encoding-worker --zone=us-central1-c --project=nomadkaraoke \
--tunnel-through-iap \
--command="curl -s http://localhost:8080/health | jq '.wheel_version'"
# View startup logs
gcloud compute ssh encoding-worker --zone=us-central1-c --project=nomadkaraoke \
--tunnel-through-iap \
--command="sudo journalctl -u encoding-worker -n 50"
# Force service restart (triggers fresh startup.sh download)
gcloud compute ssh encoding-worker --zone=us-central1-c --project=nomadkaraoke \
--tunnel-through-iap \
--command="sudo systemctl restart encoding-worker"
Troubleshooting
Version mismatch after deployment
- Check CI logs for GCS upload success
- Check
/var/log/encoding-worker-startup.logon VM - Verify
version.txtin GCS matches expected
Service won't start
- Check bootstrap.sh can reach GCS:
gsutil ls gs://karaoke-gen-storage-nomadkaraoke/ - Check Secret Manager access for API key
- Check startup.sh logs:
cat /var/log/encoding-worker-startup.log