From 82e20ab2e2b6c806f1c255306babba2d1f3be91b Mon Sep 17 00:00:00 2001 From: Mogyuchi Date: Tue, 17 Oct 2023 17:38:35 +0900 Subject: [PATCH 1/2] fix Dockerfile --- Dockerfile | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 31440967..012c57e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,25 @@ -FROM node:18 as builder +# syntax=docker/dockerfile:1 +FROM node:18 AS deps +ARG NODE_ENV=production WORKDIR /app - -COPY ./* ./ - +COPY ./package*.json . RUN npm install -RUN npm run build -FROM node:18-alpine as runner +FROM deps AS builder +ARG NODE_ENV=development +WORKDIR /app +COPY ./src/ ./src/ +RUN npm install +RUN --mount=type=bind,source=build.js,target=build.js \ + npm run build +FROM gcr.io/distroless/nodejs18-debian12:nonroot AS runner WORKDIR /app ENV NODE_ENV=production -COPY --from=builder /app/dist/main.js ./dist +COPY --from=builder /app/dist/ ./dist/ COPY ./package.json ./ +COPY --from=deps /app/node_modules/ ./node_modules/ -RUN npm install - -CMD ["node", "main.js"] +CMD ["dist/main.js"] From eeee00a2a5cd374f1bbc23f3cf5198c4d6f5e456 Mon Sep 17 00:00:00 2001 From: Mogyuchi Date: Mon, 23 Oct 2023 19:33:45 +0900 Subject: [PATCH 2/2] fix Dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - npm ci を使用するように変更。 - 記法統一 Co-authored-by: InkoHX --- Dockerfile | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 012c57e8..a9c60d71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,23 +3,22 @@ FROM node:18 AS deps ARG NODE_ENV=production WORKDIR /app -COPY ./package*.json . -RUN npm install +COPY ./package*.json ./ +RUN npm ci -FROM deps AS builder +FROM node:18 AS builder ARG NODE_ENV=development WORKDIR /app +COPY ./build.js ./ +COPY ./package*.json ./ +RUN npm ci COPY ./src/ ./src/ -RUN npm install -RUN --mount=type=bind,source=build.js,target=build.js \ - npm run build +RUN npm run build FROM gcr.io/distroless/nodejs18-debian12:nonroot AS runner WORKDIR /app ENV NODE_ENV=production - -COPY --from=builder /app/dist/ ./dist/ COPY ./package.json ./ +COPY --from=builder /app/dist/ ./dist/ COPY --from=deps /app/node_modules/ ./node_modules/ - CMD ["dist/main.js"]