Skip to content

Commit

Permalink
fix Dockerfile and set lefthook to not run in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard committed Sep 15, 2024
1 parent 2231865 commit 676f4d7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
44 changes: 39 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
FROM imbios/bun-node:20-slim
FROM imbios/bun-node:22-slim AS base

# Install dependencies only when needed
FROM base AS deps

WORKDIR /app

# Install dependencies
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile

RUN bun install --production --frozen-lockfile

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Disable telemetry during the build
ENV NEXT_TELEMETRY_DISABLED=1
ENV SKIP_ENV_VALIDATION=true

# Build the application
RUN bunx next build


# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production
RUN bun run build
ENV NEXT_TELEMETRY_DISABLED=1
ENV SKIP_ENV_VALIDATION=true

RUN addgroup --system --gid 1002 nodejs && \
adduser --system --uid 1002 nextjs

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next && chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENTRYPOINT [ "bun", "run", "start" ]
# server.js is created by next build from the standalone output
CMD ["bun", "run", "server.js"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "module",
"scripts": {
"prepare": "lefthook install",
"prepare": "if [ \"$NODE_ENV\" != \"production\" ]; then lefthook install; fi",
"postbuild": "next-sitemap",
"prebuild": "next telemetry disable",
"build": "next build",
Expand Down

0 comments on commit 676f4d7

Please sign in to comment.