Files
mb-grid-solutions.com/Dockerfile
Marc Mintel 855390a27b
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 4s
Build & Deploy / 🧪 QA (push) Successful in 4m28s
Build & Deploy / 🏗️ Build (push) Successful in 2m55s
Build & Deploy / 🚀 Deploy (push) Failing after 31s
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 1s
fix(deploy): use dedicated dist-migrations dir and fix sed path in Dockerfile
2026-03-11 00:46:10 +01:00

78 lines
2.4 KiB
Docker

# Stage 1: Builder
FROM node:20-alpine AS builder
WORKDIR /app
# Clean the workspace
RUN rm -rf ./*
# Arguments for build-time configuration
ARG NEXT_PUBLIC_BASE_URL
ARG NEXT_PUBLIC_TARGET
ARG DIRECTUS_URL
ARG UMAMI_API_ENDPOINT
ARG NEXT_PUBLIC_UMAMI_WEBSITE_ID
ARG NPM_TOKEN
# Environment variables for Next.js build
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
ENV NEXT_PUBLIC_TARGET=$NEXT_PUBLIC_TARGET
ENV DIRECTUS_URL=$DIRECTUS_URL
ENV UMAMI_API_ENDPOINT=$UMAMI_API_ENDPOINT
ENV NEXT_PUBLIC_UMAMI_WEBSITE_ID=$NEXT_PUBLIC_UMAMI_WEBSITE_ID
ENV SKIP_RUNTIME_ENV_VALIDATION=true
ENV CI=true
# Enable pnpm
RUN corepack enable && corepack prepare pnpm@10.3.0 --activate
# Copy lockfile and manifest for dependency installation caching
COPY pnpm-lock.yaml package.json .npmrc* ./
# Install dependencies with cache mount
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
--mount=type=secret,id=NPM_TOKEN \
export NPM_TOKEN=$(cat /run/secrets/NPM_TOKEN 2>/dev/null || echo $NPM_TOKEN) && \
pnpm store prune && \
pnpm install --no-frozen-lockfile
# Copy source code
COPY . .
# Build application
RUN pnpm build
# Transpile migrations to JS for production compatibility (ESM requires extensions)
RUN mkdir -p dist-migrations && \
npx tsc migrations/*.ts --outDir dist-migrations --module esnext --target esnext --moduleResolution node --esModuleInterop --skipLibCheck || true && \
cp migrations/*.json dist-migrations/ 2>/dev/null || true && \
sed -i 's/from "\.\/\([^"]*\)";/from ".\/\1.js";/g' dist-migrations/index.js
# Stage 2: Runner
FROM node:20-alpine AS runner
# ... [skipping middle part as I'm replacing lines 45-64 in a single block] ...
WORKDIR /app
# Install curl for health checks
RUN apk add --no-cache curl
# Create nextjs user and group for security
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs && \
chown -R nextjs:nodejs /app
ENV HOSTNAME="0.0.0.0"
ENV PORT=3000
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Copy standalone output and static files
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/dist-migrations ./migrations
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/.next/cache ./.next/cache
USER nextjs
CMD ["node", "server.js"]