-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
30 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,36 +1,44 @@ | ||
## Build image | ||
FROM node:20-alpine | ||
WORKDIR /src | ||
################### | ||
# BUILD FOR LOCAL DEVELOPMENT | ||
################### | ||
FROM node:20-alpine AS development | ||
|
||
COPY package*.json ./ | ||
COPY .npmrc ./ | ||
RUN npm install | ||
RUN rm -rf .npmrc | ||
WORKDIR /app | ||
|
||
COPY . . | ||
RUN npm run build | ||
COPY --chown=node:node package*.json ./ | ||
|
||
RUN npm ci | ||
|
||
COPY --chown=node:node . . | ||
|
||
USER node | ||
|
||
## Target image | ||
FROM node:20-alpine | ||
|
||
WORKDIR /home/nonroot | ||
################### | ||
# BUILD FOR PRODUCTION | ||
################### | ||
FROM node:20-alpine AS build | ||
WORKDIR /app | ||
|
||
COPY --chown=node:node package*.json ./ | ||
|
||
COPY package*.json ./ | ||
COPY .npmrc ./ | ||
RUN npm install | ||
RUN rm -rf .npmrc | ||
COPY --chown=node:node --from=development /app/node_modules ./node_modules | ||
|
||
COPY --chown=node:node . . | ||
|
||
RUN npm run build | ||
|
||
COPY --from=0 /src/dist ./dist | ||
RUN npm ci --only=production && npm cache clean --force | ||
|
||
ENV PORT=5000 | ||
EXPOSE ${PORT} | ||
USER node | ||
|
||
RUN addgroup nonroot | ||
RUN adduser --disabled-password --gecos "" --ingroup nonroot nonroot | ||
RUN chown -R nonroot:nonroot /home/nonroot | ||
################### | ||
# RUN PRODUCTION | ||
################### | ||
FROM node:20-alpine AS production | ||
|
||
USER nonroot | ||
COPY --chown=node:node --from=build /app/node_modules ./node_modules | ||
COPY --chown=node:node --from=build /app/dist ./dist | ||
COPY --chown=node:node --from=build /app/.env ./.env | ||
|
||
CMD ["npm", "run", "start:prod"] | ||
CMD ["node", "dist/main.js"] |
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