The pnpm 12 audit moved overrides into pnpm-workspace.yaml, but the Dockerfile wrote its own workspace file, so frozen installs failed with ERR_PNPM_LOCKFILE_CONFIG_MISMATCH. pnpm 12 also ignores the "pnpm" field in package.json, which silently dropped the mobile patches, so they move to the workspace file too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
218 lines
7.8 KiB
Docker
218 lines
7.8 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
# ============================================
|
|
# Stage 1: Dependencies Installation Stage
|
|
# ============================================
|
|
|
|
# IMPORTANT: Node.js Version Maintenance
|
|
# This Dockerfile uses Node.js 24.13.0-slim, which was the latest LTS version at the time of writing.
|
|
# To ensure security and compatibility, regularly update the NODE_VERSION ARG to the latest LTS version.
|
|
ARG NODE_VERSION=24.13.0-slim
|
|
|
|
# The Convex backend runs inside the oTunes image. Pin to a commit tag from
|
|
# https://github.com/get-convex/convex-backend/pkgs/container/convex-backend
|
|
ARG CONVEX_BACKEND_IMAGE=ghcr.io/convex/convex-backend:5c7cb5bc7db457290f1769f95f1d1340912f7fd7
|
|
|
|
# Audio-only static ffmpeg. The distro package links video filters that pull
|
|
# in LLVM and Mesa (~420MB) for codecs this app never uses.
|
|
ARG FFMPEG_VERSION=7.1.5
|
|
ARG FFMPEG_SHA256=de668509caf9e35e3cd162473441fdb29538c6d96ed080292b3cf9e6fc5d558f
|
|
|
|
FROM node:${NODE_VERSION} AS node
|
|
|
|
FROM node:${NODE_VERSION} AS dependencies
|
|
|
|
WORKDIR /app
|
|
|
|
# Only manifests needed for @otunes/web and its workspace dependency (@otunes/convex).
|
|
# Mobile's manifest is never copied, so the workspace globs cannot discover it.
|
|
# The workspace file must be the real one: its overrides and patches are
|
|
# checked against the lockfile.
|
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
|
|
# pnpm validates patches even when their packages are outside the install filter.
|
|
COPY patches ./patches
|
|
COPY apps/web/package.json ./apps/web/
|
|
COPY packages/convex/package.json ./packages/convex/
|
|
|
|
RUN printf '\n%s\n' \
|
|
'supportedArchitectures.os=current' \
|
|
'supportedArchitectures.cpu=current' \
|
|
'supportedArchitectures.libc=current' \
|
|
>> .npmrc
|
|
|
|
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
|
corepack enable pnpm && \
|
|
pnpm install --frozen-lockfile --filter @otunes/web...
|
|
|
|
# ============================================
|
|
# Stage 2: Build Next.js application in standalone mode
|
|
# ============================================
|
|
|
|
# Reuse the installed workspace. Copying node_modules into a new layer retars
|
|
# hundreds of thousands of files on every source change.
|
|
FROM dependencies AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
COPY apps/web /tmp/src/apps/web
|
|
COPY packages/convex /tmp/src/packages/convex
|
|
|
|
# Merge sources onto the install. cp does not remove the existing
|
|
# node_modules tree, and the build context already dockerignores it.
|
|
RUN cp -a /tmp/src/apps/web/. ./apps/web/ \
|
|
&& cp -a /tmp/src/packages/convex/. ./packages/convex/ \
|
|
&& rm -rf /tmp/src
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
WORKDIR /app/apps/web
|
|
|
|
RUN --mount=type=cache,target=/app/apps/web/.next/cache \
|
|
corepack enable pnpm && pnpm build
|
|
|
|
# ============================================
|
|
# Stage 3: Convex functions, deployed to the bundled backend on boot
|
|
# ============================================
|
|
|
|
FROM node:${NODE_VERSION} AS convex-functions
|
|
|
|
WORKDIR /app
|
|
|
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
|
|
COPY patches ./patches
|
|
COPY packages/convex/package.json ./packages/convex/
|
|
|
|
RUN printf '\n%s\n' \
|
|
'supportedArchitectures.os=current' \
|
|
'supportedArchitectures.cpu=current' \
|
|
'supportedArchitectures.libc=current' \
|
|
>> .npmrc
|
|
|
|
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
|
corepack enable pnpm && \
|
|
pnpm install --frozen-lockfile --prod --filter @otunes/convex...
|
|
|
|
COPY packages/convex ./packages/convex
|
|
|
|
# Source maps and the Convex package's TypeScript sources are not used at runtime.
|
|
RUN find /app -type f -name '*.map' -delete \
|
|
&& rm -rf /app/node_modules/.pnpm/convex@*/node_modules/convex/src
|
|
|
|
# ============================================
|
|
# Stage 4: Audio-only ffmpeg
|
|
# ============================================
|
|
|
|
FROM ubuntu:24.04 AS ffmpeg
|
|
|
|
ARG FFMPEG_VERSION
|
|
ARG FFMPEG_SHA256
|
|
|
|
RUN apt-get update && \
|
|
apt-get install -y --no-install-recommends \
|
|
build-essential ca-certificates curl nasm pkg-config xz-utils zlib1g-dev && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /src
|
|
|
|
RUN curl -fsSL -o ffmpeg.tar.xz "https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz" \
|
|
&& echo "${FFMPEG_SHA256} ffmpeg.tar.xz" | sha256sum -c - \
|
|
&& tar -xJf ffmpeg.tar.xz --strip-components=1 \
|
|
&& rm ffmpeg.tar.xz
|
|
|
|
# Decoders cover the library formats (FLAC, ALAC/AAC in m4a, MP3, Opus,
|
|
# Vorbis, WavPack, WMA, E-AC-3/TrueHD for Atmos). Encoders are only the two
|
|
# the app writes: AAC (HLS and ADTS) and FLAC.
|
|
RUN ./configure \
|
|
--prefix=/opt/ffmpeg \
|
|
--disable-shared \
|
|
--enable-static \
|
|
--disable-debug \
|
|
--disable-doc \
|
|
--disable-ffplay \
|
|
--disable-ffprobe \
|
|
--disable-network \
|
|
--disable-autodetect \
|
|
--disable-everything \
|
|
--enable-ffmpeg \
|
|
--enable-protocol=file,pipe \
|
|
--enable-demuxer=aac,ac3,aiff,ape,asf,au,caf,dsf,flac,matroska,mov,mp3,ogg,wav,wv \
|
|
--enable-decoder=aac,aac_latm,ac3,alac,ape,dsd_lsbf,dsd_msbf,eac3,flac,mlp,mp3,opus,pcm_f32le,pcm_s16be,pcm_s16le,pcm_s24be,pcm_s24le,pcm_s32be,pcm_s32le,pcm_u8,truehd,vorbis,wavpack,wmav1,wmav2 \
|
|
--enable-encoder=aac,flac \
|
|
--enable-muxer=adts,flac,hls,mpegts \
|
|
--enable-parser=aac,aac_latm,ac3,flac,mpegaudio,opus,vorbis \
|
|
--enable-bsf=aac_adtstoasc \
|
|
--enable-filter=aresample,aformat \
|
|
--enable-zlib \
|
|
--extra-cflags="-Os" \
|
|
--extra-ldflags="-static" \
|
|
--pkg-config-flags="--static" \
|
|
&& make -j"$(nproc)" \
|
|
&& make install \
|
|
&& strip /opt/ffmpeg/bin/ffmpeg
|
|
|
|
# ============================================
|
|
# Stage 5: Run Convex and Next.js together
|
|
# ============================================
|
|
|
|
FROM ${CONVEX_BACKEND_IMAGE} AS convex-backend
|
|
|
|
# Fresh Ubuntu instead of the Convex image. That image installs libclang,
|
|
# which pulls LLVM (~200MB) even though the backend only links libstdc++.
|
|
FROM ubuntu:24.04 AS runner
|
|
|
|
RUN apt-get update && \
|
|
apt-get install -y --no-install-recommends ca-certificates curl openssl tini && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /convex
|
|
|
|
COPY --from=convex-backend --chmod=755 \
|
|
/convex/convex-local-backend \
|
|
/convex/generate_key \
|
|
/convex/run_backend.sh \
|
|
/convex/generate_admin_key.sh \
|
|
/convex/read_credentials.sh \
|
|
./
|
|
|
|
COPY --from=node --chmod=755 /usr/local/bin/node /usr/local/bin/node
|
|
COPY --from=ffmpeg --chmod=755 /opt/ffmpeg/bin/ffmpeg /usr/local/bin/ffmpeg
|
|
|
|
# Fail the build if a binary is missing a shared library.
|
|
RUN node --version \
|
|
&& ffmpeg -hide_banner -version \
|
|
&& openssl version \
|
|
&& command -v tini \
|
|
&& command -v curl \
|
|
&& ldd /convex/convex-local-backend \
|
|
&& ldd /convex/generate_key \
|
|
&& ! ldd /convex/convex-local-backend /convex/generate_key | grep -q 'not found'
|
|
|
|
# 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
|
|
COPY --chmod=755 docker/entrypoint.sh /usr/local/bin/otunes-entrypoint
|
|
|
|
WORKDIR /app
|
|
|
|
COPY --from=builder --chown=otunes:otunes /app/apps/web/public ./apps/web/public
|
|
COPY --from=builder --chown=otunes:otunes /app/apps/web/.next/standalone ./
|
|
COPY --from=builder --chown=otunes:otunes /app/apps/web/.next/static ./apps/web/.next/static
|
|
|
|
RUN mkdir -p apps/web/.next /data && chown -R otunes:otunes apps/web/.next
|
|
|
|
ENV PATH="/usr/local/bin:${PATH}"
|
|
|
|
EXPOSE 3000 3210
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=60s \
|
|
CMD curl -fsS http://127.0.0.1:3210/version && curl -fsS -o /dev/null http://127.0.0.1:3000/signin
|
|
|
|
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/otunes-entrypoint"]
|
|
CMD []
|