Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

use outputStandalone to reduce docker image size

Thomas Maird35134c43967
diff --git a/Dockerfile b/Dockerfile
index 16dd9872c..4a76c7112 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,45 +1,52 @@
-# Build image
-FROM node:12.22-alpine AS build
-ARG BASE_PATH
-ARG DATABASE_TYPE
+# Install dependencies only when needed
+FROM node:16-alpine AS deps
+# 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 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 DATABASE_URL "postgresql://umami:umami@db:5432/umami"
ENV DATABASE_TYPE=$DATABASE_TYPE
+WORKDIR /app
+COPY --from=deps /app/node_modules ./node_modules
+COPY . .
-WORKDIR /build
-
-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
+# 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
-COPY . /build
-RUN yarn next telemetry disable
RUN yarn build
-# Production image
-FROM node:12.22-alpine AS production
+# Production image, copy all the files and run next
+FROM node:16-alpine AS runner
WORKDIR /app
-# Copy cached dependencies
-COPY --from=build /build/prod_node_modules ./node_modules
+ENV NODE_ENV production
+# Uncomment the following line in case you want to disable telemetry during runtime.
+ENV NEXT_TELEMETRY_DISABLED 1
+
+RUN addgroup --system --gid 1001 nodejs
+RUN adduser --system --uid 1001 nextjs
-# Copy generated Prisma client
-COPY --from=build /build/node_modules/.prisma/ ./node_modules/.prisma/
+# You only need to copy next.config.js if you are NOT using the default configuration
+COPY --from=builder /app/next.config.js ./
+COPY --from=builder /app/public ./public
+COPY --from=builder /app/package.json ./package.json
-COPY --from=build /build/yarn.lock /build/package.json ./
-COPY --from=build /build/.next ./.next
-COPY --from=build /build/public ./public
+# 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 node
+USER nextjs
EXPOSE 3000
-CMD ["yarn", "start"]
+
+ENV PORT 3000
+
+CMD ["node", "server.js"]
diff --git a/next.config.js b/next.config.js
index 3519b7938..e458b8dcc 100644
--- a/next.config.js
+++ b/next.config.js
@@ -6,6 +6,9 @@ module.exports = {
VERSION: pkg.version,
},
basePath: process.env.BASE_PATH,
+ experimental: {
+ outputStandalone: true,
+ },
eslint: {
ignoreDuringBuilds: true,
},