Compare commits

..
Author SHA1 Message Date
Andrew Beveridge ☄️andClaude Opus 4.5 0c4e946bb8 fix(gce): Use version sort for wheel selection in encoding worker (#277)
## Summary
- Fixed encoding worker startup script to use version sort (`sort -V`)
instead of time sort (`ls -t`) when selecting the wheel to install
- All wheels download simultaneously with identical timestamps, so time
sort picked arbitrarily (0.99.9) instead of the latest (0.105.0)
- Fixed zone references in CLAUDE.md and infrastructure/README.md
(us-central1-a → us-central1-c)
- Added lesson learned about version sorting for artifact selection

## Test plan
- [x] Shell script syntax validated
- [x] Manually verified fix on running VM - worker now reports version
0.105.0
- [ ] Future restarts will correctly select highest version wheel

🤖 Generated with [Claude Code](https://claude.com/claude-code)

@coderabbitai ignore

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 10:39:31 -05:00
Andrew Beveridge ☄️andClaude Opus 4.5 082d36a3c9 fix(pwa): Add service worker file that was gitignored (#276)
## Summary
- Adds the service worker file that was previously gitignored
- Updates gitignore to allow sw.js (hand-written) while still ignoring
auto-generated PWA files

## Context
The sw.js service worker file was created in PR #274 but was blocked
from being tracked by a gitignore rule meant for auto-generated PWA
files. Without this file, push notifications cannot work because the
browser has no service worker to receive push events.

## Test plan
- [ ] CI passes
- [ ] `curl https://gen.nomadkaraoke.com/sw.js` returns JavaScript after
deploy

@coderabbitai ignore

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 18:14:51 -05:00
Andrew Beveridge ☄️andClaude Opus 4.5 402eb9d86b fix(docker): Add missing backend directory to Dockerfile.base (#275)
## Summary
- Fixes Docker base image build failure by adding missing `backend`
directory to COPY command

## Context
The `backend` package was previously added to `pyproject.toml` packages
list but `Dockerfile.base` wasn't updated to copy the directory. This
caused the editable install to fail with:

```
ValueError: /app/backend does not contain any element
```

This was discovered when the push notifications PR (#274) triggered a
base image rebuild.

## Test plan
- [ ] CI passes (specifically Deploy - Backend job should succeed now)

@coderabbitai ignore

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 17:38:26 -05:00
7 changed files with 194 additions and 7 deletions

No files matched your search

+1 -2
View File
@@ -58,8 +58,7 @@ frontend/.eslintcache
# Storybook
frontend/storybook-static/
# PWA files
frontend/**/public/sw.js
# PWA auto-generated files (our sw.js is hand-written and should be tracked)
frontend/**/public/workbox-*.js
frontend/**/public/swe-worker-*.js
+2 -2
View File
@@ -105,11 +105,11 @@ EOF
### GCE Encoding Worker
```bash
# SSH to restart service (clears in-memory job queue)
gcloud compute ssh encoding-worker --zone=us-central1-a --project=nomadkaraoke \
gcloud compute ssh encoding-worker --zone=us-central1-c --project=nomadkaraoke \
--command="sudo systemctl restart encoding-worker"
# Check health
gcloud compute ssh encoding-worker --zone=us-central1-a --project=nomadkaraoke \
gcloud compute ssh encoding-worker --zone=us-central1-c --project=nomadkaraoke \
--command="curl -s http://localhost:8080/health"
```
+3
View File
@@ -148,6 +148,9 @@ Use `pulumi up --skip-preview --yes` when CI service account can't run preview.
### Docker Disk Management
Self-hosted runners need aggressive disk cleanup. Use threshold-based (70%) not age-based cleanup.
### Version Sort for Artifact Selection
When downloading multiple versioned files (wheels, tarballs), use `sort -V | tail -1` not `ls -t | head -1`. Files downloaded simultaneously have the same timestamp, so time-based sorting picks arbitrarily. Version sorting (`sort -V`) correctly identifies the highest semantic version.
---
## Performance Patterns
+183
View File
@@ -0,0 +1,183 @@
/**
* Service Worker for Web Push Notifications
*
* Handles push events and notification clicks for the Karaoke Generator PWA.
* This service worker is registered by the ServiceWorkerRegistration component.
*/
// Cache name for static assets (versioned for updates)
const CACHE_VERSION = 'v1';
const STATIC_CACHE = `karaoke-gen-static-${CACHE_VERSION}`;
// Assets to cache for offline support
const STATIC_ASSETS = [
'/nomad-logo.png',
'/nomad-karaoke-logo.svg',
'/favicon.ico',
];
/**
* Install event - cache static assets
*/
self.addEventListener('install', (event) => {
console.log('[SW] Installing service worker...');
event.waitUntil(
caches.open(STATIC_CACHE).then((cache) => {
return cache.addAll(STATIC_ASSETS);
}).then(() => {
console.log('[SW] Static assets cached');
return self.skipWaiting(); // Activate immediately
})
);
});
/**
* Activate event - clean up old caches
*/
self.addEventListener('activate', (event) => {
console.log('[SW] Activating service worker...');
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames
.filter((name) => name.startsWith('karaoke-gen-') && name !== STATIC_CACHE)
.map((name) => {
console.log('[SW] Deleting old cache:', name);
return caches.delete(name);
})
);
}).then(() => {
console.log('[SW] Service worker activated');
return self.clients.claim(); // Take control of all pages
})
);
});
/**
* Push event - show notification when push message received
*/
self.addEventListener('push', (event) => {
console.log('[SW] Push event received');
let data = {
title: 'Karaoke Generator',
body: 'You have a notification',
icon: '/nomad-logo.png',
tag: 'default',
url: '/app/',
};
// Parse push data if available
if (event.data) {
try {
const payload = event.data.json();
data = {
title: payload.title || data.title,
body: payload.body || data.body,
icon: payload.icon || data.icon,
tag: payload.tag || data.tag,
url: payload.url || data.url,
};
} catch (err) {
console.error('[SW] Error parsing push data:', err);
// Try as text
const text = event.data.text();
if (text) {
data.body = text;
}
}
}
// Show the notification
const options = {
body: data.body,
icon: data.icon,
badge: '/favicon-32x32.png',
tag: data.tag, // Replaces notifications with same tag
renotify: true, // Vibrate/sound even if replacing
requireInteraction: true, // Don't auto-dismiss
data: {
url: data.url,
},
// Actions for the notification (optional)
actions: [
{
action: 'open',
title: 'Open',
},
{
action: 'dismiss',
title: 'Dismiss',
},
],
};
event.waitUntil(
self.registration.showNotification(data.title, options)
);
});
/**
* Notification click event - open the app or focus existing window
*/
self.addEventListener('notificationclick', (event) => {
console.log('[SW] Notification clicked:', event.action);
event.notification.close();
// Handle dismiss action
if (event.action === 'dismiss') {
return;
}
// Get the URL to open
const url = event.notification.data?.url || '/app/';
const fullUrl = new URL(url, self.location.origin).href;
// Try to focus an existing window or open a new one
event.waitUntil(
self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clients) => {
// Check if there's already a window open
for (const client of clients) {
// If we find a matching URL, focus it
if (client.url === fullUrl && 'focus' in client) {
return client.focus();
}
}
// Check if there's any window from our origin
for (const client of clients) {
if (client.url.startsWith(self.location.origin) && 'focus' in client) {
// Navigate the existing window and focus it
return client.navigate(fullUrl).then((client) => client?.focus());
}
}
// No existing window, open a new one
if (self.clients.openWindow) {
return self.clients.openWindow(fullUrl);
}
})
);
});
/**
* Notification close event - cleanup if needed
*/
self.addEventListener('notificationclose', (event) => {
console.log('[SW] Notification closed');
// Could track analytics here if desired
});
/**
* Message event - handle messages from the main app
*/
self.addEventListener('message', (event) => {
console.log('[SW] Message received:', event.data);
if (event.data?.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});
console.log('[SW] Service worker loaded');
+1 -1
View File
@@ -182,7 +182,7 @@ High-performance VM for video encoding:
**Troubleshooting:**
```bash
gcloud compute ssh encoding-worker --zone=us-central1-a -- \
gcloud compute ssh encoding-worker --zone=us-central1-c -- \
"sudo systemctl status encoding-worker"
```
+3 -1
View File
@@ -118,7 +118,9 @@ echo "ENCODING_API_KEY=${ENCODING_API_KEY}" > /opt/encoding-worker/env
# This enables hot code updates without rebuilding the image
echo "Installing latest karaoke-gen wheel from GCS..."
gsutil cp "gs://karaoke-gen-storage-nomadkaraoke/wheels/karaoke_gen-*.whl" /tmp/ 2>/dev/null || true
WHEEL_FILE=$(ls -t /tmp/karaoke_gen-*.whl 2>/dev/null | head -1)
# Use version sort (-V) to get the highest version, not time sort (-t)
# All wheels download at the same time, so -t picks arbitrarily
WHEEL_FILE=$(ls /tmp/karaoke_gen-*.whl 2>/dev/null | sort -V | tail -1)
if [ -n "$WHEEL_FILE" ]; then
echo "Installing wheel: $WHEEL_FILE"
/opt/encoding-worker/venv/bin/pip install --upgrade --quiet "$WHEEL_FILE" || echo "WARNING: Failed to install wheel"
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "karaoke-gen"
version = "0.105.0"
version = "0.105.1"
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
license = "MIT"