--------- Co-authored-by: Rem Helper <remhelper@abunchofknowitalls.com> Reviewed-on: https://git.abunchofknowitalls.com/joshuafhiggins/otunes/pulls/10
92 lines
2.8 KiB
Docker
92 lines
2.8 KiB
Docker
# ============================================
|
|
# 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
|
|
|
|
FROM node:${NODE_VERSION} AS runner-base
|
|
|
|
RUN apt-get update && \
|
|
apt-get install -y ffmpeg && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
FROM node:${NODE_VERSION} AS dependencies
|
|
|
|
WORKDIR /app
|
|
|
|
# Only manifests needed for @otunes/web and its workspace dependency (@otunes/convex).
|
|
# Mobile is intentionally omitted so its deps are never installed.
|
|
COPY package.json pnpm-lock.yaml .npmrc ./
|
|
COPY apps/web/package.json ./apps/web/
|
|
COPY packages/convex/package.json ./packages/convex/
|
|
|
|
# Explicit workspace — do not use apps/* so mobile cannot be discovered.
|
|
RUN printf '%s\n' \
|
|
'packages:' \
|
|
' - "apps/web"' \
|
|
' - "packages/convex"' \
|
|
> pnpm-workspace.yaml
|
|
|
|
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 — no need to re-copy node_modules from a blank image.
|
|
FROM dependencies AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Overlay sources; nested node_modules must be dockerignored so they do not
|
|
# replace the install from the dependencies stage with host pnpm symlinks.
|
|
COPY apps/web ./apps/web
|
|
COPY packages/convex ./packages/convex
|
|
|
|
# Re-apply the install tree after source COPY so module resolution cannot be
|
|
# clobbered even if a nested node_modules slips into the build context.
|
|
COPY --from=dependencies /app/node_modules ./node_modules
|
|
COPY --from=dependencies /app/apps/web/node_modules ./apps/web/node_modules
|
|
COPY --from=dependencies /app/packages/convex/node_modules ./packages/convex/node_modules
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
ARG NEXT_PUBLIC_CONVEX_URL
|
|
|
|
WORKDIR /app/apps/web
|
|
|
|
RUN --mount=type=cache,target=/app/apps/web/.next/cache \
|
|
corepack enable pnpm && pnpm build
|
|
|
|
# ============================================
|
|
# Stage 3: Run Next.js application
|
|
# ============================================
|
|
|
|
FROM runner-base AS runner
|
|
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
RUN mkdir /data
|
|
|
|
COPY --from=builder --chown=node:node /app/apps/web/public ./apps/web/public
|
|
COPY --from=builder --chown=node:node /app/apps/web/.next/standalone ./
|
|
COPY --from=builder --chown=node:node /app/apps/web/.next/static ./apps/web/.next/static
|
|
|
|
RUN mkdir -p apps/web/.next && chown -R node:node apps/web/.next
|
|
|
|
USER node
|
|
|
|
EXPOSE 3000
|
|
|
|
CMD ["node", "apps/web/server.js"]
|