-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize dev Dockerfile for rebuild speed and readonly filesystem
- Loading branch information
Showing
3 changed files
with
35 additions
and
14 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,4 +1,9 @@ | ||
.env | ||
.git | ||
.gitattributes | ||
.gitignore | ||
.npmrc.template | ||
node_modules | ||
.vscode | ||
README.md | ||
dist | ||
.vscode | ||
node_modules |
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,20 +1,34 @@ | ||
FROM node:16-bullseye-slim | ||
WORKDIR /home/node/app | ||
FROM node:16-bullseye-slim as dependencies | ||
|
||
# Copy package.json and yarn.lock and npmrc to the container | ||
COPY package.json yarn.lock .npmrc ./ | ||
# RUN apt update -y && apt install python3 -y | ||
WORKDIR /dependencies | ||
|
||
RUN mkdir -p node_modules | ||
# Install dependencies first so rebuild of these layers is only needed when dependencies change | ||
COPY package.json yarn.lock .npmrc . | ||
RUN yarn cache clean && yarn install --frozen-lockfile | ||
|
||
|
||
FROM node:16-bullseye-slim as cli-dependencies | ||
|
||
WORKDIR /dependencies | ||
|
||
# Install dependencies first so rebuild of these layers is only needed when dependencies change | ||
COPY cli/package.json cli/yarn.lock . | ||
RUN --mount=type=secret,id=npmrc,required=true,target=./.npmrc,uid=1000 \ | ||
yarn cache clean && yarn install --frozen-lockfile | ||
|
||
|
||
FROM node:16-bullseye-slim as development | ||
|
||
COPY --from=cli-dependencies /dependencies/node_modules /cli_node_modules | ||
|
||
ENV NODE_PATH=/node_modules | ||
COPY --from=dependencies /dependencies/node_modules /node_modules | ||
|
||
WORKDIR /app | ||
ENV NODE_ENV development | ||
CMD ["yarn", "dev-docker"] | ||
|
||
RUN mkdir -p dist | ||
RUN chown -R node:node /home/node/app/node_modules | ||
RUN chown -R node:node /home/node/app/dist | ||
# Set user last so everything is readonly by default | ||
USER node | ||
CMD ["yarn", "dev"] | ||
|
||
# Copy the rest of the application code to the container | ||
COPY --chown=node:node . . | ||
# Don't need the rest of the sources since they'll be mounted from host |
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