Skip to content

Commit

Permalink
Leaner and faster Docker image with multi-stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ismaaa committed Nov 6, 2024
1 parent e4a3bf9 commit 86f4333
Show file tree
Hide file tree
Showing 4 changed files with 571 additions and 1,724 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-quality-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
node-version: '18'

- name: Install dependencies
run: npm install
run: npm ci

- name: Run ESLint
run: npm run lint
Expand Down
39 changes: 22 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
FROM node:18-alpine
ARG CACHE_BURST=1

ARG NEXT_PUBLIC_SUPABASE_URL
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY

ENV NODE_ENV="development" \
NEXT_TELEMETRY_DISABLED=1 \
NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL \
NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY
# Build stage
FROM node:18-alpine AS builder

WORKDIR /app

COPY package*.json ./
COPY package.json package-lock.json ./

# Install ALL dependencies
RUN npm install
RUN npm ci

COPY . .

RUN rm -rf .next

RUN npm run build

# Switch to production after build
ENV NODE_ENV="production"
# Production stage
FROM node:18-alpine AS runner

WORKDIR /app

ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1

COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

# Clean up development dependencies
RUN npm prune --production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs

EXPOSE 3000

Expand Down
13 changes: 0 additions & 13 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
/** @type {import('next').NextConfig} */

/**
* We're ignoring ESLint and TypeScript errors during builds to allow deployments in emergency situations.
* These issues are still caught and reported by our separate code quality GitHub Action,
* but won't block deployment if urgent changes are needed.
*
* @see .github/workflows/code-quality-checks.yml for the quality checks implementation
*/
const nextConfig = {
reactStrictMode: true,
experimental: {
serverActions: true,
},
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
};

export default nextConfig;
Loading

0 comments on commit 86f4333

Please sign in to comment.