Skip to content

Commit dddd6f4

Browse files
frontend dockerization (#17151)
* frontend dockerized * run nginx as unprivileged user * bump node to bugfix version 20.15.1, as per Chainguard requirement * add Dockerfile * re-add run.container.sh script * update dpendabot to include Dockerfile in updates * resolve new CVE in glibc * update nginx.conf --------- Co-authored-by: Joseph Andersen <[email protected]>
1 parent 130f09b commit dddd6f4

File tree

7 files changed

+83
-3
lines changed

7 files changed

+83
-3
lines changed

.github/dependabot.yml

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ updates:
1919
directory: "/.environment/docker/docker-compose"
2020
schedule:
2121
interval: "weekly"
22+
- package-ecosystem: "docker"
23+
directory: "/frontend-react"
24+
schedule:
25+
interval: "weekly"
26+
versioning-strategy: digest
2227

2328
# slack-boltjs-app (chatops)
2429
- package-ecosystem: "gitsubmodule"

frontend-react/.dockerignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.dockerignore
2-
*.sh
32
build
43
Dockerfile*
5-
node_modules
4+
node_modules
5+
**/.DS_Store

frontend-react/.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.15
1+
20.15.1

frontend-react/Dockerfile

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Start with the latest version of hardened builder image
2+
FROM cgr.dev/chainguard/wolfi-base:latest AS builder
3+
4+
# Install required dependencies
5+
RUN apk add --no-cache bash curl git ca-certificates libstdc++ coreutils && \
6+
update-ca-certificates && \
7+
touch ~/.bash_profile
8+
9+
# Get desired Node.js version and install it
10+
COPY .nvmrc /tmp/.nvmrc
11+
RUN export NODE_VERSION=$(cat /tmp/.nvmrc | tr -d '[:space:]') && \
12+
ARCH=$(uname -m) && \
13+
echo $ARCH && \
14+
case $ARCH in \
15+
x86_64) ARCH_NAME="x64";; \
16+
aarch64) ARCH_NAME="arm64";; \
17+
*) echo "Unsupported architecture: $ARCH" && exit 1;; \
18+
esac && \
19+
echo "Architecture: $ARCH_NAME" && \
20+
PLATFORM_ARCH="linux-${ARCH_NAME}" && \
21+
echo "Platform architecture: $PLATFORM_ARCH https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-${PLATFORM_ARCH}.tar.gz" && \
22+
echo "Installing Node.js version: ${NODE_VERSION} for $ARCH_NAME" && \
23+
DOWNLOAD_URL="https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-${PLATFORM_ARCH}.tar.gz" && \
24+
echo "Downloading from: $DOWNLOAD_URL" && \
25+
curl -fsSL --retry 3 "$DOWNLOAD_URL" -o /tmp/node.tar.gz && \
26+
tar -xzf /tmp/node.tar.gz -C /usr/local --strip-components=1 && \
27+
rm /tmp/node.tar.gz /tmp/.nvmrc && \
28+
echo -n "Node.js installed version: " && node -v && \
29+
echo -n "npm installed version: " && npm -v && \
30+
apk del glibc # Remove glibc package to resolve CVE CVE-2025-0395
31+
32+
33+
# Install yarn and resolve vulnerability in cross-spawn, by upgrading it to a version with resolved CVE
34+
# Newly found CVEs can be resolved in similar manner - by upgrading to the closest fixed version
35+
RUN apk add --no-cache yarn && \
36+
npm install -g [email protected]
37+
# Extract Node.js version from the image
38+
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
39+
RUN node --version | awk -F'v' '{print $2}'
40+
WORKDIR /app
41+
# Prep package manager as root and drop privileges
42+
USER root
43+
COPY --chown=nonroot . .
44+
RUN chown nonroot:nonroot ./ && npm install -g corepack
45+
# Run install/buiuld as unprivileged user
46+
USER nonroot
47+
RUN yarn install --immutable && yarn build:production
48+
49+
# Web server stage
50+
# This image runs as a unprivileged user by default, so there's no need to explicitly set user - see the Note block in the link below for more context
51+
# https://edu.chainguard.dev/chainguard/chainguard-images/getting-started/nginx/#advanced-usage
52+
FROM cgr.dev/chainguard/nginx AS server
53+
COPY nginx.conf /etc/nginx/nginx.conf
54+
COPY --from=builder /app/build /usr/share/nginx/html
55+
EXPOSE 8080
56+
CMD ["nginx", "-g", "daemon off;"]

frontend-react/nginx.conf

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pid /var/run/nginx.pid;
2+
3+
http {
4+
include mime.types;
5+
6+
server {
7+
listen 8080;
8+
server_name localhost;
9+
10+
location / {
11+
root /usr/share/nginx/html;
12+
index index.html index.htm;
13+
try_files $uri /index.html; # Pass all non-files to our react app
14+
}
15+
}
16+
}
17+
18+
events {}

frontend-react/run.container.sh

100644100755
File mode changed.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker build . --build-arg NODE_VERSION=$(cat .nvmrc) -t rs-frontend:latest

0 commit comments

Comments
 (0)