diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 3d97985..85edd6c 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,45 +1,35 @@ -# Build stage +# Build stage — needs all dependencies including devDependencies FROM node:22-alpine AS build WORKDIR /app -# Copy package files and install dependencies COPY package*.json ./ -RUN npm ci --only=production +RUN npm ci -# Copy source code COPY . . - -# Build the app RUN npm run build -# Production stage +# Production stage — only production dependencies FROM node:22-alpine -# Create app directory with non-root user WORKDIR /app + RUN addgroup -S appgroup && adduser -S appuser -G appgroup && \ chown -R appuser:appgroup /app +# Install only production deps in the final image +COPY --chown=appuser:appgroup package*.json ./ +RUN npm ci --only=production + # Copy built assets from build stage -COPY --from=build --chown=appuser:appgroup /app/node_modules ./node_modules COPY --from=build --chown=appuser:appgroup /app/.next ./.next COPY --from=build --chown=appuser:appgroup /app/public ./public -COPY --from=build --chown=appuser:appgroup /app/package.json ./package.json COPY --from=build --chown=appuser:appgroup /app/next.config.js ./next.config.js -# Security best practices ENV NODE_ENV=production -RUN npm prune --production -# Set permissions and switch to non-root user USER appuser -# Create health check endpoint -COPY --from=build --chown=appuser:appgroup /app/health.js ./health.js - -# Expose port EXPOSE 3000 -# Start the application CMD ["npm", "start"]