2024-05-14 15:30:25 +00:00
|
|
|
ARG NODEJS_IMAGE=node:20.13.1-alpine3.19
|
2022-12-09 16:47:37 +00:00
|
|
|
FROM --platform=$BUILDPLATFORM $NODEJS_IMAGE AS base
|
2022-02-17 19:47:26 +00:00
|
|
|
|
2021-09-16 11:52:32 +00:00
|
|
|
# Install dependencies only when needed
|
2022-02-17 19:47:26 +00:00
|
|
|
FROM base AS deps
|
2021-09-16 11:52:32 +00:00
|
|
|
# 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
|
2022-10-08 17:23:27 +00:00
|
|
|
|
|
|
|
# Install dependencies based on the preferred package manager
|
|
|
|
COPY package.json package-lock.json ./
|
2022-01-05 12:09:51 +00:00
|
|
|
COPY npm npm
|
2024-02-27 22:12:39 +00:00
|
|
|
COPY internal-ui internal-ui
|
2023-10-13 22:29:21 +00:00
|
|
|
COPY migrate.sh prebuild.ts ./
|
2023-11-18 13:30:04 +00:00
|
|
|
RUN npm install
|
2024-03-04 21:44:49 +00:00
|
|
|
RUN npm rebuild --arch=x64 --platform=linux --libc=musl sharp
|
2022-10-08 17:23:27 +00:00
|
|
|
|
2022-01-05 12:09:51 +00:00
|
|
|
|
|
|
|
# Rebuild the source code only when needed
|
2022-02-17 19:47:26 +00:00
|
|
|
FROM base AS builder
|
2022-01-05 12:09:51 +00:00
|
|
|
WORKDIR /app
|
2022-10-08 17:23:27 +00:00
|
|
|
|
2022-01-05 12:09:51 +00:00
|
|
|
COPY --from=deps /app/npm ./npm
|
2024-02-27 22:12:39 +00:00
|
|
|
COPY --from=deps /app/internal-ui ./internal-ui
|
2022-01-05 12:09:51 +00:00
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
2022-10-08 17:23:27 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
RUN npm run build
|
|
|
|
|
2021-09-16 11:52:32 +00:00
|
|
|
# Production image, copy all the files and run next
|
2022-12-09 16:47:37 +00:00
|
|
|
FROM $NODEJS_IMAGE AS runner
|
2021-09-16 11:52:32 +00:00
|
|
|
WORKDIR /app
|
2021-09-16 09:48:24 +00:00
|
|
|
|
2023-02-07 12:40:13 +00:00
|
|
|
ENV NODE_OPTIONS="--max-http-header-size=81920 --dns-result-order=ipv4first"
|
2022-10-08 17:23:27 +00:00
|
|
|
|
|
|
|
|
2021-09-16 10:14:33 +00:00
|
|
|
ENV NODE_ENV production
|
2022-10-08 17:23:27 +00:00
|
|
|
# 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
|
2021-09-16 09:48:24 +00:00
|
|
|
|
2022-01-05 12:09:51 +00:00
|
|
|
|
|
|
|
COPY --from=builder /app/public ./public
|
2022-10-08 17:23:27 +00:00
|
|
|
|
|
|
|
# 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
|
2023-10-13 22:29:21 +00:00
|
|
|
# Support for DB migration
|
|
|
|
COPY --from=builder --chown=nextjs:nodejs /app/migrate.sh ./migrate.sh
|
|
|
|
COPY npm npm
|
|
|
|
RUN chmod +x migrate.sh
|
|
|
|
# mongodb peer dependency would be automatically installed for migrate-mongo
|
|
|
|
RUN npm install -g ts-node migrate-mongo typeorm reflect-metadata mssql mysql2 pg
|
2022-01-05 12:09:51 +00:00
|
|
|
USER nextjs
|
2021-09-16 09:48:24 +00:00
|
|
|
|
2022-02-21 14:33:31 +00:00
|
|
|
EXPOSE 5225
|
2021-09-16 09:48:24 +00:00
|
|
|
|
2022-10-08 17:23:27 +00:00
|
|
|
ENV PORT 5225
|
|
|
|
|
|
|
|
CMD ["node", "server.js"]
|