From 7be1ac0bcb1e5f589220e2e6d5b51898359afe5b Mon Sep 17 00:00:00 2001 From: MaxtuneLee Date: Wed, 17 Jul 2024 23:06:15 +0800 Subject: [PATCH] ci: docker file --- .dockerignore | 1 + Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ next.config.mjs | 1 + 3 files changed, 40 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4693d89 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM node:20-slim AS base +WORKDIR /app +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN npm config set registry https://registry.npmmirror.com +RUN npm i -g pnpm + +# Install dependencies and build the application +FROM base AS builder +WORKDIR /app +COPY package.json pnpm-lock.yaml ./ +ENV NEXT_TELEMETRY_DISABLED 1 +ENV OUTPUT_STANDALONE 1 +# Use the npm mirror to speed up the installation +RUN pnpm config set registry https://registry.npmmirror.com && pnpm install --frozen-lockfile +COPY . . +RUN pnpm run build + +# Install production dependencies only +RUN pnpm install --prod --ignore-scripts --prefer-offline + +# Use alpine for the final image to reduce the image size +FROM node:20-alpine AS runner +WORKDIR /app + + +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/public ./public + +# Set environment variables +ENV NODE_ENV production +ENV PORT 3000 + +EXPOSE 3000 + +# Just pass HOSTNAME to node server.js +CMD HOSTNAME="0.0.0.0" node server.js \ No newline at end of file diff --git a/next.config.mjs b/next.config.mjs index 5bba9e8..1d0d324 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -17,6 +17,7 @@ const nextConfig = { }, ], }, + output: "standalone", }; export default nextConfig;