Compare commits
1
Commits
No files matched your search
+5
-6
@@ -54,12 +54,11 @@ playwright.config.*
|
||||
*~
|
||||
*.log
|
||||
|
||||
# Environment variables (only commit template files)
|
||||
.env
|
||||
.env*.local
|
||||
.env.development
|
||||
.env.test
|
||||
.env.production.local
|
||||
# Environment variables, in any workspace. Next.js inlines NEXT_PUBLIC_* values
|
||||
# into the bundle and the Convex CLI reads .env.local on deploy.
|
||||
**/.env
|
||||
**/.env.*
|
||||
!**/.env.example
|
||||
|
||||
# Docker configuration files (not needed inside build context)
|
||||
Dockerfile*
|
||||
|
||||
+6
-1
@@ -195,7 +195,12 @@ RUN node --version \
|
||||
&& ldd /convex/generate_key \
|
||||
&& ! ldd /convex/convex-local-backend /convex/generate_key | grep -q 'not found'
|
||||
|
||||
RUN useradd --system --user-group --home-dir /app --shell /usr/sbin/nologin otunes
|
||||
# The backend gets its own user so the web server cannot read the database or
|
||||
# instance secret. It joins the otunes group to clean up the web server's HLS
|
||||
# cache in /tmp/otunes.
|
||||
RUN useradd --system --user-group --home-dir /app --shell /usr/sbin/nologin otunes \
|
||||
&& useradd --system --user-group --groups otunes --create-home --home-dir /home/convex \
|
||||
--shell /usr/sbin/nologin convex
|
||||
|
||||
COPY --from=convex-functions /app /opt/otunes/convex
|
||||
COPY docker/generate-auth-keys.mjs /opt/otunes/generate-auth-keys.mjs
|
||||
|
||||
+27
-6
@@ -46,22 +46,34 @@ stop() {
|
||||
}
|
||||
trap 'stop; exit 0' TERM INT
|
||||
|
||||
as_convex=(setpriv --reuid=convex --regid=convex --init-groups env HOME=/home/convex)
|
||||
|
||||
convex_cli() {
|
||||
(
|
||||
cd "$FUNCTIONS_DIR"
|
||||
unset CONVEX_DEPLOYMENT CONVEX_DEPLOY_KEY
|
||||
CONVEX_SELF_HOSTED_URL="$BACKEND_URL" \
|
||||
CONVEX_SELF_HOSTED_ADMIN_KEY="$admin_key" \
|
||||
"$NODE" node_modules/convex/bin/main.js "$@"
|
||||
"${as_convex[@]}" "$NODE" node_modules/convex/bin/main.js "$@"
|
||||
)
|
||||
}
|
||||
|
||||
# Only root (the backend) may read the database and instance secret.
|
||||
# Only the convex user may read the database and instance secret. Volumes from
|
||||
# images that ran the backend as root are still owned by root, and
|
||||
# read_credentials.sh generates a new instance secret if it cannot read the old one.
|
||||
mkdir -p "$CONVEX_DATA_DIR"
|
||||
find "$CONVEX_DATA_DIR" \( ! -user convex -o ! -group convex \) \
|
||||
-exec chown -h convex:convex {} +
|
||||
chmod 700 "$CONVEX_DATA_DIR"
|
||||
|
||||
# The web server writes HLS streams here and a Convex cron deletes stale ones.
|
||||
mkdir -p /tmp/otunes
|
||||
chown otunes:otunes /tmp/otunes
|
||||
chmod -R g+rwX /tmp/otunes
|
||||
chmod g+s,o-rwx /tmp/otunes
|
||||
|
||||
log "Starting Convex backend"
|
||||
(cd /convex && umask 077 && exec ./run_backend.sh) &
|
||||
(cd /convex && umask 077 && exec "${as_convex[@]}" ./run_backend.sh) &
|
||||
backend_pid=$!
|
||||
|
||||
for _ in $(seq 1 120); do
|
||||
@@ -80,17 +92,24 @@ if ! curl -fsS "$BACKEND_URL/version" >/dev/null 2>&1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
admin_key=$(cd /convex && ./generate_admin_key.sh)
|
||||
admin_key=$(cd /convex && umask 077 && "${as_convex[@]}" ./generate_admin_key.sh)
|
||||
|
||||
log "Deploying Convex functions"
|
||||
convex_cli deploy --typecheck disable --codegen disable
|
||||
|
||||
if [ -z "$(convex_cli env get JWKS 2>/dev/null || true)" ]; then
|
||||
# `env get` exits 0 with no output when the variable is unset. Any other failure
|
||||
# must not be read as "no keys": regenerating them signs every user out.
|
||||
if ! jwks=$(convex_cli env get JWKS); then
|
||||
log "Could not read Convex Auth signing keys"
|
||||
stop
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$jwks" ]; then
|
||||
log "Generating Convex Auth signing keys"
|
||||
"$NODE" /opt/otunes/generate-auth-keys.mjs | convex_cli env set --force
|
||||
fi
|
||||
|
||||
unset admin_key
|
||||
unset admin_key jwks
|
||||
|
||||
log "Starting web server"
|
||||
(
|
||||
@@ -100,6 +119,8 @@ log "Starting web server"
|
||||
# Server-side Convex helpers fall back to this at runtime. The browser bundle
|
||||
# is built without it, so browsers still derive their own URL.
|
||||
export NEXT_PUBLIC_CONVEX_URL="$BACKEND_URL"
|
||||
# Lets the convex group member delete stale HLS streams.
|
||||
umask 0002
|
||||
exec setpriv --reuid=otunes --regid=otunes --init-groups \
|
||||
"$NODE" apps/web/server.js
|
||||
) &
|
||||
|
||||
@@ -68,21 +68,6 @@ async function coverPathIfExists(path: string): Promise<string | null> {
|
||||
.catch(() => null)
|
||||
}
|
||||
|
||||
async function shouldReplaceCover(dbCover: string | null) {
|
||||
return dbCover === null || (await coverPathIfExists(dbCover)) === null
|
||||
}
|
||||
|
||||
function isCodecPath(filePath: string, codec: string) {
|
||||
return filePath.startsWith(`${DATA_DIR}/${codec}/`)
|
||||
}
|
||||
|
||||
function releaseDate(common: music.ICommonTagsResult) {
|
||||
if (common.date) {
|
||||
return common.date
|
||||
}
|
||||
return common.year ? `01-01-${common.year}` : ""
|
||||
}
|
||||
|
||||
async function syncArtistCover(
|
||||
ctx: ActionCtx,
|
||||
codec: string,
|
||||
@@ -92,13 +77,13 @@ async function syncArtistCover(
|
||||
) {
|
||||
const onDisk = await coverPathIfExists(diskPath)
|
||||
if (onDisk !== null) {
|
||||
if (await shouldReplaceCover(dbCover)) {
|
||||
if (dbCover !== onDisk) {
|
||||
await ctx.runMutation(internal.library.updateArtistCover, {
|
||||
id,
|
||||
cover: onDisk,
|
||||
})
|
||||
}
|
||||
} else if (dbCover !== null && isCodecPath(dbCover, codec)) {
|
||||
} else if (dbCover !== null && dbCover.includes(codec)) {
|
||||
await ctx.runMutation(internal.library.updateArtistCover, {
|
||||
id,
|
||||
cover: null,
|
||||
@@ -115,13 +100,13 @@ async function syncAlbumCover(
|
||||
) {
|
||||
const onDisk = await coverPathIfExists(diskPath)
|
||||
if (onDisk !== null) {
|
||||
if (await shouldReplaceCover(dbCover)) {
|
||||
if (dbCover !== onDisk) {
|
||||
await ctx.runMutation(internal.library.updateAlbumCover, {
|
||||
id,
|
||||
cover: onDisk,
|
||||
})
|
||||
}
|
||||
} else if (dbCover !== null && isCodecPath(dbCover, codec)) {
|
||||
} else if (dbCover !== null && dbCover.includes(codec)) {
|
||||
await ctx.runMutation(internal.library.updateAlbumCover, {
|
||||
id,
|
||||
cover: null,
|
||||
@@ -417,8 +402,9 @@ export const scheduledUpdateLibrary = internalAction({
|
||||
name: metadata.common.album || potentialAlbum,
|
||||
folder: potentialAlbum,
|
||||
cover,
|
||||
year: metadata.common.year || 0,
|
||||
date: releaseDate(metadata.common),
|
||||
year: metadata.common.year || 2026,
|
||||
date:
|
||||
metadata.common.date || `01-01-${metadata.common.year || 2026}`,
|
||||
artist: dbArtist._id,
|
||||
})
|
||||
} catch {}
|
||||
@@ -508,14 +494,11 @@ export const scheduledUpdateLibrary = internalAction({
|
||||
)
|
||||
|
||||
if (existingSong) {
|
||||
// A tracked path that still exists is a different file with the
|
||||
// same title; replacing it would flip-flop between scans.
|
||||
const trackedPath = existingSong.files[codec]
|
||||
if (
|
||||
trackedPath === undefined ||
|
||||
!fsSync.existsSync(trackedPath)
|
||||
!(codec in existingSong.files) ||
|
||||
existingSong.files[codec] !== path
|
||||
) {
|
||||
const update = { ...existingSong.files, [codec]: path }
|
||||
const update = { [codec]: path, ...existingSong.files }
|
||||
updateSongs.push({
|
||||
id: existingSong._id,
|
||||
files: update,
|
||||
@@ -567,8 +550,10 @@ export const scheduledUpdateLibrary = internalAction({
|
||||
? null
|
||||
: metadata.common.disk.no,
|
||||
track: metadata.common.track.no || 0,
|
||||
year: metadata.common.year || 0,
|
||||
date: releaseDate(metadata.common),
|
||||
year: metadata.common.year || 2026,
|
||||
date:
|
||||
metadata.common.date ||
|
||||
`01-01-${metadata.common.year || 2026}`,
|
||||
genres: metadata.common.genre || [],
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user