Skip to content

Commit

Permalink
chore: cleanup dockerfile and add dockerignore
Browse files Browse the repository at this point in the history
  • Loading branch information
procaconsul committed Sep 9, 2024
1 parent 302b2ca commit 12f82aa
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,40 @@
FROM node:18-alpine AS base
# Stage 1: Build
FROM node:18-alpine AS builder

# Prisma base image only for installing prisma
FROM base AS prisma_base
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm install prisma --omit=dev

FROM prisma_base AS builder
ENV NEXT_TELEMETRY_DISABLED=1
WORKDIR /app

# Won't need to re-install prisma, since it's already installed in the prisma_base image
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
COPY package.json package-lock.json* ./
RUN npm ci
COPY . .
RUN npx prisma generate
RUN npm run build

FROM base AS runner

# Stage 2: Production
FROM node:18-alpine AS runner

ENV NEXT_TELEMETRY_DISABLED=1
WORKDIR /app

# Make UPLOAD_DIRs
ENV UPLOAD_DIR=/uploads
RUN mkdir $UPLOAD_DIR
RUN mkdir $UPLOAD_DIR/banners $UPLOAD_DIR/cvs $UPLOAD_DIR/avatars $UPLOAD_DIR/logos $UPLOAD_DIR/attachments

WORKDIR /app

# Take ownership of the app folder and uploads
RUN chown node:node /app
RUN chown -R node:node $UPLOAD_DIR


# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown node:node .next

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/public ./public
COPY --from=builder --chown=node:node /app/.next/standalone ./
COPY --from=builder --chown=node:node /app/.next/static ./.next/static
COPY --from=builder --chown=node:node /app/prisma ./prisma
COPY --from=prisma_base /app/node_modules ./node_modules

USER node

Expand Down

0 comments on commit 12f82aa

Please sign in to comment.