diff --git a/Dockerfile b/Dockerfile index f5f1999..b6a8ae4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,35 @@ -FROM node:20.19.0 AS base +FROM node:20.19.0-alpine AS deps + WORKDIR /app -FROM base AS deps -COPY package.json yarn.lock ./ -RUN yarn install --frozen-lockfile +# Install dependencies (use lockfile if present for reproducible builds) +COPY package.json yarn.lock* ./ +RUN if [ -f yarn.lock ]; then yarn install --frozen-lockfile; else yarn install; fi -FROM base AS builder -COPY --from=deps /app/node_modules ./node_modules -COPY . . -RUN yarn run build +FROM node:20.19.0-alpine AS builder -FROM base AS runner +WORKDIR /app ENV NODE_ENV=production + +COPY . . +COPY --from=deps /app/node_modules ./node_modules + +RUN yarn run build:staging + +FROM node:20.19.0-alpine AS runner + WORKDIR /app -COPY --from=builder /app/package.json ./package.json -COPY --from=builder /app/next.config.js ./next.config.js +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 +ENV PORT=3005 + +# Copy only the minimal standalone output COPY --from=builder /app/public ./public -COPY --from=builder /app/.next ./.next -COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/.env ./.env + EXPOSE 3005 -CMD ["yarn", "run", "start:staging"] + +CMD ["node", "server.js"] + diff --git a/docker-compose.yml b/docker-compose.yml index 21a9a41..e6bd8e5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,10 @@ services: - web: - build: . + app: + build: + context: . + dockerfile: Dockerfile ports: - "3005:3005" + environment: + - NEXTAUTH_SECRET=${NEXTAUTH_SECRET} + - NEXTAUTH_URL=${NEXTAUTH_URL} diff --git a/next.config.js b/next.config.js index d9b71a4..7aca8ce 100644 --- a/next.config.js +++ b/next.config.js @@ -20,6 +20,7 @@ module.exports = async () => { defaultLocale: 'en', }, assetPrefix: isLocal ? '' : '/uxcore_next', + output: 'standalone', async rewrites() { return [ { @@ -47,9 +48,6 @@ module.exports = async () => { experimental: { manualClientBasePath: true, }, - env: { - NEXTAUTH_URL: process.env.NEXTAUTH_URL, - }, compiler: { removeConsole: process.env.NODE_ENV === 'prod' ? { exclude: ['error'] } : false,