From b3bad2340890aef8f080b2598d8fa10333e82811 Mon Sep 17 00:00:00 2001 From: static Date: Wed, 27 Nov 2024 04:10:58 +0900 Subject: [PATCH 1/5] Fix: dockerfile error --- Dockerfile | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0873829c..ae7cc13e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,31 @@ -FROM node:18-alpine +# +# First stage: build the app +# +FROM node:18-alpine as builder WORKDIR /usr/src/app -# Install curl(for taxi-watchtower) and pnpm -RUN apk update && apk add curl && npm install --global pnpm@8.8.0 +# Install pnpm +RUN npm install --global pnpm@8.8.0 # pnpm fetch does require only lockfile COPY pnpm-lock.yaml . +RUN pnpm fetch + +COPY . . +RUN pnpm install --offline +RUN pnpm build -# Note: devDependencies are not fetched -RUN pnpm fetch --prod +# +# Second stage: run the app +# +FROM node:18-alpine + +WORKDIR /usr/src/app -# Copy repository and install dependencies -ADD . ./ -RUN pnpm install --offline --prod +COPY --from=builder /usr/src/app/dist . # Run container EXPOSE 80 ENV PORT 80 -CMD ["pnpm", "run", "serve"] +CMD ["node", "dist/index.js"] From d7ae501bc71956e57a9e9623887ab7e41c58653a Mon Sep 17 00:00:00 2001 From: static Date: Wed, 27 Nov 2024 04:12:33 +0900 Subject: [PATCH 2/5] Fix: dockerfile error 2 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ae7cc13e..41e34a89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # # First stage: build the app # -FROM node:18-alpine as builder +FROM node:18-alpine AS builder WORKDIR /usr/src/app @@ -23,7 +23,7 @@ FROM node:18-alpine WORKDIR /usr/src/app -COPY --from=builder /usr/src/app/dist . +COPY --from=builder /usr/src/app/dist dist # Run container EXPOSE 80 From 6acd1c2f4f022e560d9624bc4a30074a74b84ce7 Mon Sep 17 00:00:00 2001 From: static Date: Wed, 27 Nov 2024 04:15:30 +0900 Subject: [PATCH 3/5] Fix: dockerfile error 3 --- Dockerfile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 41e34a89..3e328249 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,9 +23,17 @@ FROM node:18-alpine WORKDIR /usr/src/app +RUN npm install --global pnpm@8.8.0 + +COPY pnpm-lock.yaml . +RUN pnpm fetch --prod + +COPY package.json . +RUN pnpm install --prod + COPY --from=builder /usr/src/app/dist dist # Run container EXPOSE 80 ENV PORT 80 -CMD ["node", "dist/index.js"] +CMD ["pnpm", "serve"] From a8c91e62ff6ee3ab8de3038b46479418790ccc8e Mon Sep 17 00:00:00 2001 From: static Date: Wed, 27 Nov 2024 04:24:16 +0900 Subject: [PATCH 4/5] Refactor: use offline install in the second stage --- Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3e328249..8a1a8894 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,15 +23,18 @@ FROM node:18-alpine WORKDIR /usr/src/app +# Install pnpm RUN npm install --global pnpm@8.8.0 +# devDependencies are not fetched COPY pnpm-lock.yaml . RUN pnpm fetch --prod COPY package.json . -RUN pnpm install --prod +RUN pnpm install --offline --prod -COPY --from=builder /usr/src/app/dist dist +# Copy the built app from the previous stage +COPY --from=builder /usr/src/app/dist ./dist # Run container EXPOSE 80 From a9e2f50f1433bf1f3761d5ac2ea9cbd840b3c6ed Mon Sep 17 00:00:00 2001 From: static Date: Wed, 27 Nov 2024 04:28:46 +0900 Subject: [PATCH 5/5] Fix: unintended removal of curl package in dockerfile --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 8a1a8894..5ffddaa6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,9 @@ WORKDIR /usr/src/app # Install pnpm RUN npm install --global pnpm@8.8.0 +# Install curl for taxi-watchtower +RUN apk update && apk add curl + # devDependencies are not fetched COPY pnpm-lock.yaml . RUN pnpm fetch --prod