Skip to content

Commit

Permalink
Dockerfile cleanup and sync
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 de769bc commit 0dbc6c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 42 deletions.
58 changes: 23 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
13 changes: 6 additions & 7 deletions Dockerfile.image
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down

0 comments on commit 0dbc6c3

Please sign in to comment.