-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Switch to custom server * remove app load context * Simplify Dockerfile
- Loading branch information
1 parent
f6b1cf6
commit 7f42c96
Showing
6 changed files
with
242 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,30 @@ | ||
# base node image | ||
FROM node:20-alpine as base | ||
|
||
# set for base and all layer that inherit from it | ||
ENV NODE_ENV production | ||
|
||
# Install all node_modules, including dev dependencies | ||
FROM base as deps | ||
|
||
WORKDIR /myapp | ||
|
||
ADD package.json package-lock.json .npmrc ./ | ||
RUN npm install --production=false | ||
|
||
# Setup production node_modules | ||
FROM base as production-deps | ||
|
||
WORKDIR /myapp | ||
|
||
COPY --from=deps /myapp/node_modules /myapp/node_modules | ||
ADD package.json package-lock.json .npmrc ./ | ||
RUN npm prune --production | ||
|
||
# Build the app | ||
FROM base as build | ||
|
||
WORKDIR /myapp | ||
|
||
COPY --from=deps /myapp/node_modules /myapp/node_modules | ||
|
||
ADD . . | ||
FROM node:20-alpine AS development-dependencies-env | ||
COPY . /app | ||
WORKDIR /app | ||
RUN npm ci | ||
|
||
FROM node:20-alpine AS production-dependencies-env | ||
COPY ./package.json package-lock.json .npmrc /app/ | ||
WORKDIR /app | ||
RUN npm ci --omit=dev | ||
|
||
FROM node:20-alpine AS build-env | ||
COPY . /app/ | ||
COPY --from=development-dependencies-env /app/node_modules /app/node_modules | ||
WORKDIR /app | ||
RUN npm run build | ||
|
||
# Finally, build the production image with minimal footprint | ||
FROM base | ||
FROM node:20-alpine | ||
COPY ./package.json package-lock.json server.js /app/ | ||
|
||
|
||
ENV PORT="8080" | ||
ENV NODE_ENV="production" | ||
|
||
WORKDIR /myapp | ||
COPY --from=production-dependencies-env /app/node_modules /app/node_modules | ||
COPY --from=build-env /app/build /app/build | ||
COPY --from=build-env /app/start.sh /app/start.sh | ||
|
||
COPY --from=production-deps /myapp/node_modules /myapp/node_modules | ||
COPY --from=build /myapp/build /myapp/build | ||
COPY --from=build /myapp/package.json /myapp/package.json | ||
COPY --from=build /myapp/start.sh /myapp/start.sh | ||
|
||
CMD ["npm", "start"] | ||
WORKDIR /app | ||
CMD ["npm", "run", "start"] |
Oops, something went wrong.