1
- FROM node:18.17 AS build
2
- ENV NODE_ENV=development APP_ENV=development
3
- # ENV PATH /frontend/node_modules/.bin:$PATH
4
- COPY . /frontend
1
+ FROM node:18-alpine AS base
2
+
3
+ # Install dependencies only when needed
4
+ FROM base AS deps
5
+ # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6
+ RUN apk add --no-cache libc6-compat
5
7
WORKDIR /frontend
6
- RUN yarn install --frozen-lockfile --network-timeout 100000 --non-interactive
7
- RUN yarn build --standalone
8
- EXPOSE ${NUXT_PORT}
9
-
10
- FROM build AS run-dev
11
- # ENTRYPOINT ["yarn"]
12
- CMD ["yarn" , "dev" ]
13
-
14
- FROM build AS run-start
15
- ENV NODE_ENV=production APP_ENV=production
16
- ENTRYPOINT ["yarn" ]
17
- CMD ["start" ]
18
-
19
- FROM node:18.17-alpine AS run-minimal
20
- # ARG NEXT_VERSION=^13.5.4
21
- # ARG TAILWINDCSS_VERSION=^4.0.0
22
- # ARG AUTOPREFIXER_VERSION=^10.4.13
23
- # ARG POSTCSS_VERSION=^8.4.18
24
- # ARG ASPECT_RATIO_VERSION=^0.4.2
25
- # ARG FORMS_VERSION=^0.5.3
26
- # ARG TYPOGRAPHY_VERSION=^0.5.7
27
- # ARG HEADLESSUI_VERSION=^1.7.3
28
- # ARG HEROICONS_VERSION=^2.0.12
29
- # ENV NODE_ENV=production APP_ENV=production
30
- # WORKDIR /frontend
31
- RUN yarn install
32
- # nuxt@${NUXT_VERSION} @nuxt/content@${NUXT_CONTENT_VERSION} tailwindcss@${TAILWINDCSS_VERSION} autoprefixer@${AUTOPREFIXER_VERSION} postcss@${POSTCSS_VERSION} @tailwindcss/aspect-ratio@${ASPECT_RATIO_VERSION} @tailwindcss/forms@${FORMS_VERSION} @tailwindcss/typography@${TYPOGRAPHY_VERSION} @headlessui/vue@${HEADLESSUI_VERSION} @heroicons/vue@${HEROICONS_VERSION} @pinia/nuxt@${PINIA_VERSION} @pinia-plugin-persistedstate/nuxt${PINIA_PERSISTED_VERSION} vee-validate@${VEE_VERSION} @vee-validate/i18n${VEE_INT_VERSION} @vee-validate/rules${VEE_RULES_VERSION} qrcode.vue${QR_CODE_VERSION} @nuxtjs/i18n${I18N_VERSION} @nuxtjs/robots${NUXT_ROBOTS_VERSION} @vite-pwa/nuxt${VITE_PWA_NUXT_VERSION}
33
- # COPY --from=build /app/.next ./.next
34
- # COPY --from=build /app/app/api ./api
35
- # COPY --from=build /app/app/assets ./assets
36
- # COPY --from=build /app/app/components ./components
37
- # COPY --from=build /app/app/config ./config
38
- # COPY --from=build /app/app/content ./content
39
- # COPY --from=build /app/app/interfaces ./interfaces
40
- # COPY --from=build /app/app/layouts ./layouts
41
- # COPY --from=build /app/app/locales ./locales
42
- # COPY --from=build /app/app/middleware ./middleware
43
- # COPY --from=build /app/app/pages ./pages
44
- # COPY --from=build /app/app/plugins ./plugins
45
- # COPY --from=build /app/public ./public
46
- # COPY --from=build /app/app/static ./static
47
- # COPY --from=build /app/app/stores ./stores
48
- # COPY --from=build /app/app/utilities ./utilities
49
- # COPY --from=build /app/.env.local ./
50
- # COPY --from=build /app/next.config* ./
51
- # COPY --from=build /app/tailwind.config* ./
52
- # COPY --from=build /app/tsconfig.json ./
53
- ENTRYPOINT [ "yarn" ]
54
- CMD [ "start" ]
8
+
9
+ # Install dependencies based on the preferred package manager
10
+ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
11
+ RUN \
12
+ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
13
+ elif [ -f package-lock.json ]; then npm ci; \
14
+ elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
15
+ else echo "Lockfile not found." && exit 1; \
16
+ fi
17
+
18
+ # Rebuild the source code only when needed
19
+ FROM base AS builder
20
+ WORKDIR /frontend
21
+ COPY --from=deps /frontend/node_modules ./node_modules
22
+ COPY . .
23
+
24
+ # Next.js collects completely anonymous telemetry data about general usage.
25
+ # Learn more here: https://nextjs.org/telemetry
26
+ # Uncomment the following line in case you want to disable telemetry during the build.
27
+ ENV NEXT_TELEMETRY_DISABLED 1
28
+
29
+ # If using npm comment out above and use below instead
30
+ RUN npm run build
31
+
32
+ # Production image, copy all the files and run next
33
+ FROM base AS runner
34
+ WORKDIR /frontend
35
+
36
+ ENV NODE_ENV production
37
+ # Uncomment the following line in case you want to disable telemetry during runtime.
38
+ ENV NEXT_TELEMETRY_DISABLED 1
39
+
40
+ RUN addgroup --system --gid 1001 nodejs
41
+ RUN adduser --system --uid 1001 nextjs
42
+
43
+ COPY --from=builder /frontend/public ./public
44
+
45
+ # Set the correct permission for prerender cache
46
+ RUN mkdir .next
47
+ RUN chown nextjs:nodejs .next
48
+
49
+ # Automatically leverage output traces to reduce image size
50
+ # https://nextjs.org/docs/advanced-features/output-file-tracing
51
+ COPY --from=builder --chown=nextjs:nodejs /frontend/.next/standalone ./
52
+ COPY --from=builder --chown=nextjs:nodejs /frontend/.next/static ./.next/static
53
+
54
+ USER nextjs
55
+
56
+ EXPOSE 3000
57
+ ENV PORT 3000
58
+
59
+ # set hostname to localhost
60
+ ENV HOSTNAME "0.0.0.0"
61
+
62
+ CMD [ "node" , "server.js" ]
0 commit comments