Basic Architecture of Sport Web
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
# ---------------------------------------------------------------------------
|
||||
# @sport/admin production image (Next.js standalone output).
|
||||
# ---------------------------------------------------------------------------
|
||||
FROM node:22-alpine AS base
|
||||
RUN corepack enable
|
||||
WORKDIR /app
|
||||
|
||||
FROM base AS pruner
|
||||
RUN apk add --no-cache libc6-compat
|
||||
COPY . .
|
||||
RUN pnpm dlx turbo@2.10.9 prune @sport/admin --docker
|
||||
|
||||
FROM base AS builder
|
||||
RUN apk add --no-cache libc6-compat
|
||||
|
||||
COPY --from=pruner /app/out/json/ .
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
COPY --from=pruner /app/out/full/ .
|
||||
|
||||
ARG NEXT_PUBLIC_API_URL
|
||||
ARG NEXT_PUBLIC_APP_URL
|
||||
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
||||
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
RUN pnpm turbo run build --filter=@sport/admin
|
||||
|
||||
FROM base AS runner
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV PORT=3001
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
|
||||
RUN addgroup -g 1001 -S nodejs && adduser -u 1001 -S nextjs -G nodejs
|
||||
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/admin/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/admin/.next/static ./apps/admin/.next/static
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/admin/public ./apps/admin/public
|
||||
|
||||
USER nextjs
|
||||
EXPOSE 3001
|
||||
|
||||
CMD ["node", "apps/admin/server.js"]
|
||||
@@ -0,0 +1,55 @@
|
||||
# ---------------------------------------------------------------------------
|
||||
# @sport/api production image.
|
||||
#
|
||||
# `turbo prune` produces a subset of the monorepo containing only this app and
|
||||
# its workspace dependencies. That keeps the build context small AND makes the
|
||||
# Docker layer cache work properly: editing the storefront no longer busts the
|
||||
# API's dependency layer.
|
||||
# ---------------------------------------------------------------------------
|
||||
FROM node:22-alpine AS base
|
||||
RUN corepack enable
|
||||
WORKDIR /app
|
||||
|
||||
# --- Stage 1: prune the workspace ------------------------------------------
|
||||
FROM base AS pruner
|
||||
RUN apk add --no-cache libc6-compat
|
||||
COPY . .
|
||||
RUN pnpm dlx turbo@2.10.9 prune @sport/api --docker
|
||||
|
||||
# --- Stage 2: install + build ----------------------------------------------
|
||||
FROM base AS builder
|
||||
RUN apk add --no-cache libc6-compat openssl
|
||||
|
||||
# Lockfile and manifests first: this layer is cached until dependencies change.
|
||||
COPY --from=pruner /app/out/json/ .
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
COPY --from=pruner /app/out/full/ .
|
||||
RUN pnpm turbo run build --filter=@sport/api
|
||||
|
||||
# Drop dev dependencies from the tree we are about to copy.
|
||||
RUN pnpm prune --prod
|
||||
|
||||
# --- Stage 3: runtime -------------------------------------------------------
|
||||
FROM base AS runner
|
||||
RUN apk add --no-cache openssl tini
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# Never run as root.
|
||||
RUN addgroup -g 1001 -S nodejs && adduser -u 1001 -S nestjs -G nodejs
|
||||
|
||||
COPY --from=builder --chown=nestjs:nodejs /app/node_modules ./node_modules
|
||||
COPY --from=builder --chown=nestjs:nodejs /app/packages ./packages
|
||||
COPY --from=builder --chown=nestjs:nodejs /app/apps/api/node_modules ./apps/api/node_modules
|
||||
COPY --from=builder --chown=nestjs:nodejs /app/apps/api/dist ./apps/api/dist
|
||||
COPY --from=builder --chown=nestjs:nodejs /app/apps/api/prisma ./apps/api/prisma
|
||||
COPY --from=builder --chown=nestjs:nodejs /app/apps/api/package.json ./apps/api/package.json
|
||||
|
||||
USER nestjs
|
||||
WORKDIR /app/apps/api
|
||||
EXPOSE 4000
|
||||
|
||||
# tini reaps zombies and forwards SIGTERM, so Nest's shutdown hooks actually run.
|
||||
ENTRYPOINT ["/sbin/tini", "--"]
|
||||
CMD ["node", "dist/main.js"]
|
||||
@@ -0,0 +1,48 @@
|
||||
# ---------------------------------------------------------------------------
|
||||
# @sport/storefront production image (Next.js standalone output).
|
||||
# ---------------------------------------------------------------------------
|
||||
FROM node:22-alpine AS base
|
||||
RUN corepack enable
|
||||
WORKDIR /app
|
||||
|
||||
FROM base AS pruner
|
||||
RUN apk add --no-cache libc6-compat
|
||||
COPY . .
|
||||
RUN pnpm dlx turbo@2.10.9 prune @sport/storefront --docker
|
||||
|
||||
FROM base AS builder
|
||||
RUN apk add --no-cache libc6-compat
|
||||
|
||||
COPY --from=pruner /app/out/json/ .
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
COPY --from=pruner /app/out/full/ .
|
||||
|
||||
# NEXT_PUBLIC_* values are inlined into the client bundle at build time, so they
|
||||
# must be present here — they cannot be injected at container start.
|
||||
ARG NEXT_PUBLIC_API_URL
|
||||
ARG NEXT_PUBLIC_SITE_URL
|
||||
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
||||
ENV NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
RUN pnpm turbo run build --filter=@sport/storefront
|
||||
|
||||
FROM base AS runner
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
|
||||
RUN addgroup -g 1001 -S nodejs && adduser -u 1001 -S nextjs -G nodejs
|
||||
|
||||
# `output: 'standalone'` emits a self-contained server with only the modules it
|
||||
# actually imports — a fraction of the size of copying node_modules.
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/storefront/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/storefront/.next/static ./apps/storefront/.next/static
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/storefront/public ./apps/storefront/public
|
||||
|
||||
USER nextjs
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "apps/storefront/server.js"]
|
||||
Reference in New Issue
Block a user