Skip to content

Commit

Permalink
Move container image in own Dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoli Nicolae <[email protected]>

Fix workflow property

Signed-off-by: Anatoli Nicolae <[email protected]>
  • Loading branch information
anatolinicolae committed Mar 21, 2024
1 parent b8bb636 commit ed7b51e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
uses: docker/[email protected]
with:
context: .
file: Dockerfile.image
platforms: linux/amd64,linux/arm64
push: true
# Note: provenance fixes unknown/unknown platform to be generated on build
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ 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 /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
COPY --from=build /myapp/start.sh /myapp/start.sh
RUN chmod +x /myapp/start.sh

ENTRYPOINT [ "/myapp/docker-entrypoint.sh" ]
ENTRYPOINT [ "/myapp/start.sh" ]
53 changes: 53 additions & 0 deletions Dockerfile.image
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# base node image
FROM node:20-bookworm-slim as base

# set for base and all layer that inherit from it
ENV NODE_ENV="production"

WORKDIR /myapp

# 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

# Build the app
FROM base as build

COPY --from=deps /myapp/node_modules /myapp/node_modules

ADD /app/database ./app/database
RUN npx prisma generate

ADD . .
RUN npm run build

# 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 /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

ENTRYPOINT [ "/myapp/docker-entrypoint.sh" ]

0 comments on commit ed7b51e

Please sign in to comment.