diff --git a/Dockerfile.image b/Dockerfile.image index 37916e203..4fdfd4324 100644 --- a/Dockerfile.image +++ b/Dockerfile.image @@ -2,9 +2,11 @@ FROM node:20-bookworm-slim as base # set for base and all layer that inherit from it +ENV PORT="8080" ENV NODE_ENV="production" +ARG DEBIAN_FRONTEND="noninteractive" -WORKDIR /myapp +WORKDIR /src # Install openssl for Prisma RUN apt-get update && apt-get install -y openssl @@ -12,42 +14,30 @@ 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 - -# Setup production node_modules -FROM base as production-deps - -COPY --from=deps /myapp/node_modules /myapp/node_modules -ADD package.json ./ -RUN npm prune --production +ADD package.json . +RUN npm install --include=dev -# Build the app +# Build the app and setup production node_modules FROM base as build -COPY --from=deps /myapp/node_modules /myapp/node_modules - -ADD /app/database ./app/database -RUN npx prisma generate +COPY --from=deps /src/node_modules /src/node_modules ADD . . + +RUN npx prisma generate 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 +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/docker-entrypoint.sh /src/docker-entrypoint.sh -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/docker-entrypoint.sh /myapp/docker-entrypoint.sh -RUN chmod +x /myapp/docker-entrypoint.sh +RUN chmod +x /src/docker-entrypoint.sh -ENTRYPOINT [ "/myapp/docker-entrypoint.sh" ] +ENTRYPOINT [ "/src/docker-entrypoint.sh" ]