From 48c8f46781782aecdaaa201f1755df4faa626673 Mon Sep 17 00:00:00 2001 From: philipcheung Date: Sun, 16 Mar 2025 14:13:13 +0800 Subject: [PATCH] update the dockerfile --- Dockerfile | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 09a64a9..3e85748 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,36 @@ - -FROM node:18-alpine - -RUN mkdir -p /app +FROM node:18-alpine AS build WORKDIR /app -COPY package.json ./ +# Copy package files first for better layer caching +COPY package.json package-lock.json* ./ -RUN npm install - -RUN npm install --save-dev - - -COPY . /app - -# Build the Next.js app -RUN npm run build - -# Expose the port the app will run on -EXPOSE 3000 +# Install dependencies +RUN npm ci +# Copy the rest of the application COPY . . -CMD ["npm", "run", "dev"] \ No newline at end of file +# Build the application +RUN npm run build + +# Production stage +FROM node:18-alpine AS production + +WORKDIR /app + +# Copy only the built assets and necessary files from the build stage +COPY --from=build /app/dist ./dist +COPY --from=build /app/package.json ./ + +# Install only production dependencies +RUN npm ci --omit=dev + +# Expose the port Vite uses by default +EXPOSE 5173 + +# Use a static file server for production builds +RUN npm install -g serve + +# Serve the built application +CMD ["serve", "-s", "dist", "-l", "5173"] \ No newline at end of file