mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-12-04 00:56:43 +09:00
## Summary - Reduce encoding worker VM startup time from **~10 minutes to ~30 seconds** by pre-installing dependencies in a custom GCE image - Add Packer template and provisioning script for building the custom image - Simplify startup script from ~700 lines to ~30 lines ## Changes ### New Files - `infrastructure/packer/encoding-worker.pkr.hcl` - Packer template - `infrastructure/packer/scripts/provision.sh` - Provisioning script - `infrastructure/packer/README.md` - Documentation ### Modified Files - `infrastructure/compute/encoding_worker_vm.py` - Use custom image family `encoding-worker` - `infrastructure/compute/startup_scripts/encoding_worker.sh` - Simplified to just start service ## What's Pre-installed in the Image | Component | Location | |-----------|----------| | Python 3.13.1 (PGO+LTO) | `/opt/python313` | | FFmpeg 7.x | `/usr/local/bin/ffmpeg` | | Noto fonts (incl. CJK) | System fonts | | Virtual environment | `/opt/encoding-worker/venv` | | Systemd service | `encoding-worker.service` | ## Startup Time Improvement | Phase | Before | After | |-------|--------|-------| | Python 3.13 build | ~7 min | 0 | | FFmpeg install | ~1 min | 0 | | System packages | ~1 min | 0 | | API key + wheel | ~30 sec | ~30 sec | | **Total** | **~10 min** | **~30 sec** | ## Test Plan - [x] Packer image builds successfully (`encoding-worker-1767723849`) - [x] `pulumi preview` shows expected changes (VM replacement only) - [ ] After merge: Verify VM starts in ~30 seconds - [ ] After merge: Verify encoding jobs complete successfully ## Pulumi Preview ``` +- gcp:compute:Instance encoding-worker replace [diff: ~bootDisk,metadataStartupScript] Resources: +-1 to replace, 131 unchanged ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) @coderabbitai ignore --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
32 lines
1.1 KiB
Bash
32 lines
1.1 KiB
Bash
#!/bin/bash
|
|
# Encoding worker startup script (for Packer-built custom image)
|
|
#
|
|
# Most dependencies are pre-installed in the custom GCE image:
|
|
# - Python 3.13 at /opt/python313
|
|
# - FFmpeg at /usr/local/bin/ffmpeg
|
|
# - Virtual environment at /opt/encoding-worker/venv
|
|
# - Systemd service: encoding-worker.service
|
|
#
|
|
# This startup script just starts the service.
|
|
# The service's ExecStartPre (/opt/encoding-worker/startup.sh) handles:
|
|
# - Fetching API key from Secret Manager
|
|
# - Installing latest karaoke-gen wheel from GCS
|
|
#
|
|
# See infrastructure/packer/README.md for image build instructions.
|
|
|
|
set -e
|
|
exec > >(tee /var/log/encoding-worker-startup.log) 2>&1
|
|
|
|
echo "=== Encoding worker VM startup at $(date) ==="
|
|
|
|
# Start Docker (in case it's not running)
|
|
systemctl start docker || echo "Docker already running or not available"
|
|
|
|
# Start the encoding worker service
|
|
# This triggers ExecStartPre which fetches API key and installs wheel
|
|
echo "Starting encoding-worker service..."
|
|
systemctl start encoding-worker
|
|
|
|
echo "=== Encoding worker started at $(date) ==="
|
|
echo "Service listening on port 8080"
|