Skip to content

Commit

Permalink
Dockerfile cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoli Nicolae <[email protected]>
  • Loading branch information
anatolinicolae committed Mar 21, 2024
1 parent ed7b51e commit de769bc
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions Dockerfile.image
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,42 @@
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

# 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" ]

0 comments on commit de769bc

Please sign in to comment.