diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000000..4f75c9513f5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules +.git +.gitignore +*.md +dist diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..0609559966b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +# Inspired by https://pnpm.io/docker#example-3-build-on-cicd +# Inspired by https://pnpm.io/docker#minimizing-docker-image-size-and-build-time + +FROM node:20-slim AS base + +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN apt-get update +RUN apt-get install -y git +RUN npm install -g corepack +RUN corepack enable +RUN corepack prepare pnpm@latest --activate +RUN pnpm install turbo@^2 --global + +FROM base AS builder +# Set working directory +WORKDIR /app +# Replace with the major version installed in your repository. For example: +RUN pnpm install turbo@^2 --global +COPY . . + +# Generate a partial monorepo with a pruned lockfile for a target workspace. +# Assuming "web" is the name entered in the project's package.json: { name: "web" } +RUN turbo prune @zitadel/login --docker + +# Add lockfile and package.json's of isolated subworkspace +FROM base AS installer + +WORKDIR /app + +# First install the dependencies (as they change less often) +COPY --from=builder /app/out/json/ . +RUN pnpm install --frozen-lockfile + +# Build the project +COPY --from=builder /app/out/full/ . + +RUN turbo run build + +FROM base AS runner +WORKDIR /app + +# Don't run production as root +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs +USER nextjs + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=installer --chown=nextjs:nodejs /app/apps/login/.next/standalone ./ +COPY --from=installer --chown=nextjs:nodejs /app/apps/login/.next/static ./apps/login/.next/static +COPY --from=installer --chown=nextjs:nodejs /app/apps/login/public ./apps/login/public + +ENV HOSTNAME="0.0.0.0" +CMD node apps/login/server.js \ No newline at end of file diff --git a/apps/login/next.config.mjs b/apps/login/next.config.mjs index 32209b11e7a..12ca5f18981 100755 --- a/apps/login/next.config.mjs +++ b/apps/login/next.config.mjs @@ -36,6 +36,7 @@ const secureHeaders = [ const nextConfig = { basePath: process.env.NEXT_PUBLIC_BASE_PATH, + output: 'standalone', reactStrictMode: true, // Recommended for the `pages` directory, default in `app`. experimental: { dynamicIO: true,