mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
Merge pull request #1166 from tmair/docker-standalone-output
use outputStandalone to reduce docker image size
This commit is contained in:
commit
3974392eee
67
Dockerfile
67
Dockerfile
@ -1,45 +1,52 @@
|
|||||||
# Build image
|
# Install dependencies only when needed
|
||||||
FROM node:12.22-alpine AS build
|
FROM node:16-alpine AS deps
|
||||||
ARG BASE_PATH
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||||
ARG DATABASE_TYPE
|
RUN apk add --no-cache libc6-compat
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json yarn.lock ./
|
||||||
|
RUN yarn install --frozen-lockfile
|
||||||
|
|
||||||
|
# Rebuild the source code only when needed
|
||||||
|
FROM node:16-alpine AS builder
|
||||||
ENV BASE_PATH=$BASE_PATH
|
ENV BASE_PATH=$BASE_PATH
|
||||||
ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami"
|
ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami"
|
||||||
ENV DATABASE_TYPE=$DATABASE_TYPE
|
ENV DATABASE_TYPE=$DATABASE_TYPE
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
|
||||||
WORKDIR /build
|
# Next.js collects completely anonymous telemetry data about general usage.
|
||||||
|
# Learn more here: https://nextjs.org/telemetry
|
||||||
|
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
RUN yarn config set --home enableTelemetry 0
|
|
||||||
COPY package.json yarn.lock /build/
|
|
||||||
|
|
||||||
# Install only the production dependencies
|
|
||||||
RUN yarn install --production --frozen-lockfile
|
|
||||||
|
|
||||||
# Cache these modules for production
|
|
||||||
RUN cp -R node_modules/ prod_node_modules/
|
|
||||||
|
|
||||||
# Install development dependencies
|
|
||||||
RUN yarn install --frozen-lockfile
|
|
||||||
|
|
||||||
COPY . /build
|
|
||||||
RUN yarn next telemetry disable
|
|
||||||
RUN yarn build
|
RUN yarn build
|
||||||
|
|
||||||
# Production image
|
# Production image, copy all the files and run next
|
||||||
FROM node:12.22-alpine AS production
|
FROM node:16-alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy cached dependencies
|
ENV NODE_ENV production
|
||||||
COPY --from=build /build/prod_node_modules ./node_modules
|
# Uncomment the following line in case you want to disable telemetry during runtime.
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
# Copy generated Prisma client
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
COPY --from=build /build/node_modules/.prisma/ ./node_modules/.prisma/
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
COPY --from=build /build/yarn.lock /build/package.json ./
|
# You only need to copy next.config.js if you are NOT using the default configuration
|
||||||
COPY --from=build /build/.next ./.next
|
COPY --from=builder /app/next.config.js ./
|
||||||
COPY --from=build /build/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
|
COPY --from=builder /app/package.json ./package.json
|
||||||
|
|
||||||
USER node
|
# 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
|
EXPOSE 3000
|
||||||
CMD ["yarn", "start"]
|
|
||||||
|
ENV PORT 3000
|
||||||
|
|
||||||
|
CMD ["node", "server.js"]
|
||||||
|
@ -6,6 +6,9 @@ module.exports = {
|
|||||||
VERSION: pkg.version,
|
VERSION: pkg.version,
|
||||||
},
|
},
|
||||||
basePath: process.env.BASE_PATH,
|
basePath: process.env.BASE_PATH,
|
||||||
|
experimental: {
|
||||||
|
outputStandalone: true,
|
||||||
|
},
|
||||||
eslint: {
|
eslint: {
|
||||||
ignoreDuringBuilds: true,
|
ignoreDuringBuilds: true,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user