Run the whole stack in Docker
- API and web images built with turbo prune; the API image also runs the worker and migrations. Non-root, health-checked, Debian slim. - docker compose up -d --build starts Postgres, Redis (persistent), a one-shot migrate job, API, worker and web, in dependency order. - Fix the API production build (tsup flags moved to a config file) and bundle the migration script; silence Postgres NOTICE noise. - npm run infra:up now starts only Postgres and Redis for hot-reload dev. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzFywujuH9TiuXbr9vjoX8
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
# Builds the web app as a Next.js standalone server. Build from the repo root:
|
||||
# docker build -f apps/web/Dockerfile --build-arg NEXT_PUBLIC_API_URL=https://api.example.com .
|
||||
|
||||
FROM node:22-bookworm-slim AS base
|
||||
WORKDIR /app
|
||||
|
||||
FROM base AS prepare
|
||||
RUN npm install -g turbo@2.11.7
|
||||
COPY . .
|
||||
RUN turbo prune @musicshare/web --docker
|
||||
|
||||
FROM base AS builder
|
||||
COPY --from=prepare /app/out/json/ .
|
||||
RUN npm ci
|
||||
COPY --from=prepare /app/out/full/ .
|
||||
# turbo prune only copies workspaces; the shared tsconfig they extend lives at the root
|
||||
COPY --from=prepare /app/tsconfig.base.json ./tsconfig.base.json
|
||||
# NEXT_PUBLIC_* values are inlined into the browser bundle at build time,
|
||||
# so the API URL is a build argument, not a runtime setting.
|
||||
ARG NEXT_PUBLIC_API_URL=http://localhost:4000
|
||||
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL \
|
||||
NEXT_TELEMETRY_DISABLED=1
|
||||
RUN npx turbo run build --filter=@musicshare/web
|
||||
|
||||
FROM base AS runner
|
||||
ENV NODE_ENV=production \
|
||||
NEXT_TELEMETRY_DISABLED=1 \
|
||||
PORT=3737 \
|
||||
HOSTNAME=0.0.0.0
|
||||
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
|
||||
USER node
|
||||
EXPOSE 3737
|
||||
HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=3 \
|
||||
CMD node -e "fetch('http://127.0.0.1:' + process.env.PORT).then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"
|
||||
CMD ["node", "apps/web/server.js"]
|
||||
@@ -1,7 +1,12 @@
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import type { NextConfig } from 'next';
|
||||
|
||||
const config: NextConfig = {
|
||||
transpilePackages: ['@musicshare/shared'],
|
||||
// Self-contained server bundle for the Docker image (only the files it needs).
|
||||
output: 'standalone',
|
||||
// Monorepo: trace files from the repo root so the shared package is included.
|
||||
outputFileTracingRoot: fileURLToPath(new URL('../..', import.meta.url)),
|
||||
};
|
||||
|
||||
export default config;
|
||||
|
||||
Reference in New Issue
Block a user