From 0dbc6c33edcc97b259cb6e4d5998785ea54dae51 Mon Sep 17 00:00:00 2001 From: Anatoli Nicolae Date: Thu, 21 Mar 2024 15:53:02 +0100 Subject: [PATCH] Dockerfile cleanup and sync Signed-off-by: Anatoli Nicolae --- Dockerfile | 58 +++++++++++++++++++----------------------------- Dockerfile.image | 13 +++++------ 2 files changed, 29 insertions(+), 42 deletions(-) diff --git a/Dockerfile b/Dockerfile index f2d3ec6d4..edd9b5d09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,53 +1,41 @@ -# base node image -FROM node:20-bookworm-slim as base +# Base Node image +FROM node:20-bookworm-slim AS base -# set for base and all layer that inherit from it +# Set for base and all layer that inherit from it +ENV PORT="8080" ENV NODE_ENV="production" - -WORKDIR /myapp +ARG DEBIAN_FRONTEND="noninteractive" +WORKDIR /src # Install openssl for Prisma RUN apt-get update && apt-get install -y openssl # Install all node_modules, including dev dependencies -FROM base as deps - -ADD package.json ./ -RUN npm install --production=false +FROM base AS deps -# Setup production node_modules -FROM base as production-deps +ADD package.json . +RUN npm install --include=dev -COPY --from=deps /myapp/node_modules /myapp/node_modules -ADD package.json ./ -RUN npm prune --production +# Build the app and setup production node_modules +FROM base AS build -# Build the app -FROM base as build +COPY --from=deps /src/node_modules /src/node_modules -COPY --from=deps /myapp/node_modules /myapp/node_modules +ADD . . -ADD /app/database ./app/database RUN npx prisma generate - -ADD . . RUN npm run build +RUN npm prune --omit=dev # Finally, build the production image with minimal footprint -FROM base - -ENV PORT="8080" -ENV NODE_ENV="production" - -COPY --from=production-deps /myapp/node_modules /myapp/node_modules -COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma -COPY --from=build /myapp/node_modules/prisma /myapp/node_modules/prisma -COPY --from=build /myapp/app/database /myapp/app/database +FROM base AS release -COPY --from=build /myapp/build /myapp/build -COPY --from=build /myapp/public /myapp/public -COPY --from=build /myapp/package.json /myapp/package.json -COPY --from=build /myapp/start.sh /myapp/start.sh -RUN chmod +x /myapp/start.sh +COPY --from=build /src/node_modules /src/node_modules +COPY --from=build /src/app/database /src/app/database +COPY --from=build /src/build /src/build +COPY --from=build /src/public /src/public +COPY --from=build /src/package.json /src/package.json +COPY --from=build /src/start.sh /src/start.sh +RUN chmod +x /src/start.sh -ENTRYPOINT [ "/myapp/start.sh" ] +ENTRYPOINT [ "/src/start.sh" ] diff --git a/Dockerfile.image b/Dockerfile.image index 4fdfd4324..3b45aaf70 100644 --- a/Dockerfile.image +++ b/Dockerfile.image @@ -1,24 +1,23 @@ -# base node image -FROM node:20-bookworm-slim as base +# Base Node image +FROM node:20-bookworm-slim AS base -# set for base and all layer that inherit from it +# Set for base and all layer that inherit from it ENV PORT="8080" ENV NODE_ENV="production" ARG DEBIAN_FRONTEND="noninteractive" - WORKDIR /src # Install openssl for Prisma RUN apt-get update && apt-get install -y openssl # Install all node_modules, including dev dependencies -FROM base as deps +FROM base AS deps ADD package.json . RUN npm install --include=dev # Build the app and setup production node_modules -FROM base as build +FROM base AS build COPY --from=deps /src/node_modules /src/node_modules @@ -29,7 +28,7 @@ RUN npm run build RUN npm prune --omit=dev # Finally, build the production image with minimal footprint -FROM base +FROM base AS release COPY --from=build /src/node_modules /src/node_modules COPY --from=build /src/app/database /src/app/database