aboutsummaryrefslogtreecommitdiffstats
path: root/Dockerfile
diff options
context:
space:
mode:
authorGravatar piotrruss <mail@pruss.it> 2025-01-24 19:31:05 +0100
committerGravatar piotrruss <mail@pruss.it> 2025-01-25 23:23:13 +0100
commite647fbcef903067fcf5391e4d5bc8e404d482e20 (patch)
treef52adc8bb538e310898676f37c143a93e15bbc42 /Dockerfile
parent57095a47c4c3c2e8615854436c7770e7ee101197 (diff)
downloadmy_apps-e647fbcef903067fcf5391e4d5bc8e404d482e20.tar.gz
my_apps-e647fbcef903067fcf5391e4d5bc8e404d482e20.tar.bz2
my_apps-e647fbcef903067fcf5391e4d5bc8e404d482e20.zip
upgrades - node, react, next, etc
Diffstat (limited to 'Dockerfile')
-rw-r--r--Dockerfile49
1 files changed, 31 insertions, 18 deletions
diff --git a/Dockerfile b/Dockerfile
index 9a478dd..404ab2f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,17 +1,25 @@
+# syntax=docker.io/docker/dockerfile:1
+
+FROM node:20-alpine AS base
+
# Install dependencies only when needed
-FROM node:16-alpine AS deps
+FROM base 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
-# If using npm with a `package-lock.json` comment out above and use below instead
-# COPY package.json package-lock.json ./
-# RUN npm ci
+# Install dependencies based on the preferred package manager
+COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
+RUN \
+ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
+ elif [ -f package-lock.json ]; then npm ci; \
+ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
+ else echo "Lockfile not found." && exit 1; \
+ fi
+
# Rebuild the source code only when needed
-FROM node:16-alpine AS builder
+FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
@@ -19,27 +27,29 @@ COPY . .
# 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
+# ENV NEXT_TELEMETRY_DISABLED=1
-RUN yarn build
+RUN \
+ if [ -f yarn.lock ]; then yarn run build; \
+ elif [ -f package-lock.json ]; then npm run build; \
+ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
+ else echo "Lockfile not found." && exit 1; \
+ fi
# Production image, copy all the files and run next
-FROM node:16-alpine AS runner
+FROM base AS runner
WORKDIR /app
-ENV NODE_ENV production
+ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
-# ENV NEXT_TELEMETRY_DISABLED 1
+# ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
-# 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=builder --chown=nextjs:nodejs /app/public ./public
-# Automatically leverage output traces to reduce image size
+# 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
@@ -48,6 +58,9 @@ USER nextjs
EXPOSE 3000
-ENV PORT 3000
+ENV PORT=3000
+# server.js is created by next build from the standalone output
+# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
+ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]