chore: improved docker image weight

This commit is contained in:
Sonny
2023-11-11 01:47:47 +01:00
parent 18747ae0f8
commit 49c4b0824c
3 changed files with 47 additions and 8 deletions

View File

@@ -1,11 +1,50 @@
FROM node:18-alpine3.17
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
WORKDIR /app
COPY ./ /app
RUN npm install
# Install dependencies based on the preferred package manager
COPY package.json package-lock.json* ./
RUN npm ci
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED 1
RUN npx prisma generate
RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
CMD npx prisma migrate deploy && npm run start
ENV PORT 3000
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"
CMD npx prisma migrate deploy && node server.js

View File

@@ -18,11 +18,10 @@ services:
mylinks:
restart: always
container_name: MyLinks
image: sonny93/my-links:latest
# build:
# context: .
build:
context: .
ports:
- 127.0.0.1:5000:3000
- 127.0.0.1:3000:3000
env_file:
- .env
# depends_on:

View File

@@ -19,6 +19,7 @@ const config = {
experimental: {
webpackBuildWorker: true,
},
output: "standalone",
};
module.exports = config;