-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: containers will now run as the non-root rafiki user (#3277)
* build: containers will now run as the non-root rafiki user * build: frontend build image will now also have read-only access to packages folder
- Loading branch information
Showing
6 changed files
with
66 additions
and
10 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,24 +1,37 @@ | ||
FROM node:20-alpine3.20 | ||
|
||
RUN adduser -D rafiki | ||
WORKDIR /home/rafiki | ||
|
||
RUN corepack enable | ||
# Install Corepack and pnpm as the Rafiki user | ||
USER rafiki | ||
RUN mkdir -p /home/rafiki/.local/bin | ||
ENV PATH="/home/rafiki/.local/bin:$PATH" | ||
RUN corepack enable --install-directory ~/.local/bin | ||
RUN corepack prepare [email protected] --activate | ||
|
||
COPY pnpm-lock.yaml package.json pnpm-workspace.yaml .npmrc tsconfig.json tsconfig.build.json ./ | ||
|
||
# Fetch the pnpm dependencies, but use a local cache. | ||
USER rafiki | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ | ||
pnpm fetch \ | ||
| grep -v "cross-device link not permitted\|Falling back to copying packages from store" | ||
|
||
# Copy the source code and chown the relevant folders back to the Rafiki user | ||
USER root | ||
COPY . ./ | ||
RUN chown -v -R rafiki:rafiki /home/rafiki/localenv | ||
RUN chown -v -R rafiki:rafiki /home/rafiki/packages | ||
RUN chown -v -R rafiki:rafiki /home/rafiki/test | ||
|
||
# As the Rafiki user, install the rest of the dependencies and build the source code | ||
USER rafiki | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ | ||
pnpm install \ | ||
--recursive \ | ||
--offline \ | ||
--frozen-lockfile | ||
|
||
RUN pnpm --filter auth build:deps | ||
|
||
CMD pnpm --filter auth dev |
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
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,24 +1,35 @@ | ||
FROM node:20-alpine3.20 | ||
|
||
RUN adduser -D rafiki | ||
WORKDIR /home/rafiki | ||
|
||
RUN corepack enable | ||
# Install Corepack and pnpm as the Rafiki user | ||
USER rafiki | ||
RUN mkdir -p /home/rafiki/.local/bin | ||
ENV PATH="/home/rafiki/.local/bin:$PATH" | ||
RUN corepack enable --install-directory ~/.local/bin | ||
RUN corepack prepare [email protected] --activate | ||
|
||
COPY pnpm-lock.yaml package.json pnpm-workspace.yaml .npmrc tsconfig.json tsconfig.build.json ./ | ||
|
||
# Fetch the pnpm dependencies, but use a local cache. | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ | ||
pnpm fetch \ | ||
| grep -v "cross-device link not permitted\|Falling back to copying packages from store" | ||
|
||
# Copy the source code and chown the relevant folders back to the Rafiki user | ||
USER root | ||
COPY . ./ | ||
RUN chown -v -R rafiki:rafiki /home/rafiki/localenv | ||
RUN chown -v -R rafiki:rafiki /home/rafiki/packages | ||
RUN chown -v -R rafiki:rafiki /home/rafiki/test | ||
|
||
# As the Rafiki user, install the rest of the dependencies and build the source code | ||
USER rafiki | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ | ||
pnpm install \ | ||
--recursive \ | ||
--offline \ | ||
--frozen-lockfile | ||
|
||
RUN pnpm --filter backend build:deps | ||
|
||
CMD pnpm --filter backend dev |
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
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,16 +1,24 @@ | ||
FROM node:20-alpine3.20 AS base | ||
|
||
RUN adduser -D rafiki | ||
WORKDIR /home/rafiki | ||
|
||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
|
||
RUN corepack enable | ||
# Install Corepack and pnpm as the Rafiki user | ||
USER rafiki | ||
RUN mkdir -p /home/rafiki/.local/bin | ||
ENV PATH="/home/rafiki/.local/bin:$PATH" | ||
RUN corepack enable --install-directory ~/.local/bin | ||
RUN corepack prepare [email protected] --activate | ||
|
||
COPY pnpm-lock.yaml package.json pnpm-workspace.yaml .npmrc tsconfig.json tsconfig.build.json ./ | ||
COPY packages/frontend ./packages/frontend | ||
|
||
# Chown the copied packages folder back to the Rafiki user | ||
USER root | ||
RUN chown -v -R rafiki:rafiki /home/rafiki/packages | ||
|
||
# Fetch the pnpm dependencies, but use a local cache. | ||
USER rafiki | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ | ||
pnpm fetch \ | ||
| grep -v "cross-device link not permitted\|Falling back to copying packages from store" | ||
|
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