From 546b9ac83491a031c46394825d9c7b1a2d2c80c3 Mon Sep 17 00:00:00 2001 From: Mehmet Ali Bekooglu Date: Tue, 27 Jun 2023 12:46:47 +0200 Subject: [PATCH 1/3] feat: Refactored Dockerfile --- Dockerfile | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index a7e2317..91984b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,4 @@ # https://geshan.com.np/blog/2023/01/nextjs-docker/ -# https://meeg.dev/blog/using-docker-compose-to-deploy-to-a-next-js-app-to-a-linux-app-service-in-azure -# https://steveholgado.com/nginx-for-nextjs/ # https://betterprogramming.pub/write-optimised-dockerfiles-for-next-js-d644b628c570 # build stage @@ -8,14 +6,12 @@ FROM node:18-alpine AS builder # 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 -# Install PM2 globally. PM2 ensuring that our app is always restarted after crashing -# RUN npm install --global pm2 COPY ./package.json ./package-lock.json ./ ARG NEXT_PUBLIC_QWACKER_API_URL ENV NEXT_PUBLIC_QWACKER_API_URL=${NEXT_PUBLIC_QWACKER_API_URL} \ PORT=3000 -# Could not use that +# Adds the npmrc_secret file into docker path .npmrc. It is declared as secret. RUN --mount=type=secret,id=npmrc_secret,target=/root/.npmrc npm ci # Copy the entire app directory to the working directory COPY . . @@ -36,7 +32,6 @@ ENV NEXT_TELEMETRY_DISABLED 1 # Copys the .next directory from builder stage to runner stage COPY --from=builder /app/package.json /app/package-lock.json /app/next.config.js ./ -# COPY --from=builder /app/node_modules ./node_modules RUN --mount=type=secret,id=npmrc_secret,target=/root/.npmrc npm ci COPY --from=builder --chown=node:node /app/.next ./.next COPY --from=builder --chown=node:node /app/public ./public @@ -49,8 +44,4 @@ USER node ENV PORT 3000 # Run the Next.js app -CMD ["npm", "--", "start"] -# CMD [ "pm2-runtime", "npm", "--", "start" ] - -# docker build . -f Dockerfile -t app-helloworld --build-arg NEXT_PUBLIC_QWACKER_API_URL=https://qwacker-api-http-prod-4cxdci3drq-oa.a.run.app/ --secret id=npmrc_secret,src=$HOME/.npmrc -# docker run -p 3000:3000 --env-file ./.env --rm --name app-helloworld app-helloworld \ No newline at end of file +CMD ["npm", "--", "start"] \ No newline at end of file From 29e7ed0729439bfc9a246d370136cc9f151b13c1 Mon Sep 17 00:00:00 2001 From: Mehmet Ali Bekooglu Date: Tue, 27 Jun 2023 12:54:27 +0200 Subject: [PATCH 2/3] feat: Refactored Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 91984b9..9dd30e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ RUN npm run build FROM node:18-alpine AS runner WORKDIR /app -# Set the environment variable for Next.js +# Set the environment variable for Next.js to optimize Next.js for production ENV NODE_ENV production ENV NEXT_TELEMETRY_DISABLED 1 From 030b15acaba5bd5d9a16f5a45aac572c10d65fc1 Mon Sep 17 00:00:00 2001 From: Mehmet Ali Bekooglu Date: Tue, 27 Jun 2023 12:55:46 +0200 Subject: [PATCH 3/3] feat: Refactored Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9dd30e1..9ebcb34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ RUN npm run build FROM node:18-alpine AS runner WORKDIR /app -# Set the environment variable for Next.js to optimize Next.js for production +# Set the environment variable for Next.js to signal that it should enable optimizations. ENV NODE_ENV production ENV NEXT_TELEMETRY_DISABLED 1