chore: change dockerfile

This commit is contained in:
2025-01-11 17:13:45 +01:00
parent 156ad4a93b
commit 7d75842857
2 changed files with 34 additions and 16 deletions

View File

@@ -1,26 +1,44 @@
# modified from https://github.com/leerob/next-self-host
# Stage 1: Building the code
FROM node:lts-alpine AS builder
FROM node:alpine AS base
# Stage 1: Install dependencies
FROM base AS deps
WORKDIR /app
# Copy package files
COPY package.json yarn.lock ./
# Install dependencies
RUN yarn install --frozen-lockfile
# Stage 2: Build the application
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
# Copy app files
COPY . .
RUN yarn run build
# Stage 3: Production server
FROM base AS runner
# Build app
RUN yarn build
# Stage 2: Production
FROM node:lts-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Copy necessary files
COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/package.json ./
COPY --from=builder /app/yarn.lock ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/prisma ./prisma
# Install production dependencies only
RUN yarn install --frozen-lockfile --production && \
yarn cache clean
# Remove unnecessary files
RUN rm -rf /app/.git \
/app/.next/cache \
/app/README.md
EXPOSE 3000
CMD ["node", "server.js"]
CMD ["yarn", "start"]

View File

@@ -6,7 +6,7 @@
"dev": "docker compose --file dev/docker-compose.yml up -d && next dev --turbo",
"setup": "docker compose --file dev/docker-compose.yml up -d && prisma migrate deploy",
"build": "prisma generate && next build",
"start": "next start",
"start": "prisma migrate deploy && next start",
"lint": "next lint",
"db:generate": "prisma generate",
"db:migrate": "prisma migrate dev --name",