Skip to content

Commit 49eb45d

Browse files
committed
build: use build secrets in Dockerfile
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent d26a433 commit 49eb45d

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

Base/Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ ARG CS_VERSION=2.1.10
1414
#Arguments to define the user running Selenium
1515
ARG SEL_USER=seluser
1616
ARG SEL_GROUP=${SEL_USER}
17-
ARG SEL_PASSWD=secret
1817
ARG HOME=/home/${SEL_USER}
1918
ARG UID=1200
2019
ARG GID=1201
@@ -39,7 +38,8 @@ ENV DEBIAN_FRONTEND=noninteractive \
3938
# Miscellaneous packages
4039
# Includes minimal runtime used for executing non GUI Java programs
4140
#========================
42-
RUN if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
41+
RUN --mount=type=secret,id=SEL_PASSWD \
42+
if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
4343
echo "deb http://archive.ubuntu.com/ubuntu noble main universe\n" > /etc/apt/sources.list \
4444
&& echo "deb http://archive.ubuntu.com/ubuntu noble-updates main universe\n" >> /etc/apt/sources.list \
4545
&& echo "deb http://security.ubuntu.com/ubuntu noble-security main universe\n" >> /etc/apt/sources.list ; \
@@ -86,7 +86,7 @@ RUN if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
8686
--uid ${SEL_UID} \
8787
&& usermod -a -G sudo ${SEL_USER} \
8888
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \
89-
&& echo "${SEL_USER}:${SEL_PASSWD}" | chpasswd \
89+
&& echo "${SEL_USER}:$(cat /run/secrets/SEL_PASSWD)" | chpasswd \
9090
#==========
9191
# Selenium & relaxing permissions for OpenShift and other non-sudo environments
9292
#==========
@@ -99,7 +99,6 @@ RUN if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
9999
&& chmod -R 775 /opt/selenium /var/run/supervisor /var/log/supervisor /etc/passwd ${HOME} \
100100
&& wget --no-verbose https://github.com/${AUTHORS}/selenium/releases/download/${RELEASE}/selenium-server-${VERSION}.jar \
101101
-O /opt/selenium/selenium-server.jar \
102-
&& echo "${SEL_PASSWD}" > /opt/selenium/initialPasswd \
103102
&& chgrp -R 0 /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor \
104103
&& chmod -R g=u /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor \
105104
&& setfacl -Rm u:${SEL_USER}:rwx /opt /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor \

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ FFMPEG_TAG_VERSION := $(or $(FFMPEG_TAG_VERSION),$(FFMPEG_TAG_VERSION),ffmpeg-7.
2222
FFMPEG_BASED_NAME := $(or $(FFMPEG_BASED_NAME),$(FFMPEG_BASED_NAME),linuxserver)
2323
FFMPEG_BASED_TAG := $(or $(FFMPEG_BASED_TAG),$(FFMPEG_BASED_TAG),7.0.1)
2424
PLATFORMS := $(or $(PLATFORMS),$(shell echo $$PLATFORMS),linux/amd64)
25+
SEL_PASSWD := $(or $(SEL_PASSWD),$(SEL_PASSWD),secret)
2526

2627
all: hub \
2728
distributor \
@@ -75,7 +76,8 @@ gen_certs:
7576
./Base/certs/gen-cert-helper.sh -d ./Base/certs
7677

7778
base: prepare_resources gen_certs
78-
cd ./Base && docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) --build-arg VERSION=$(BASE_VERSION) --build-arg RELEASE=$(BASE_RELEASE) --build-arg AUTHORS=$(AUTHORS) --sbom=true --attest type=provenance,mode=max -t $(NAME)/base:$(TAG_VERSION) .
79+
cd ./Base && SEL_PASSWD=$(SEL_PASSWD) docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) --build-arg VERSION=$(BASE_VERSION) --build-arg RELEASE=$(BASE_RELEASE) --build-arg AUTHORS=$(AUTHORS) \
80+
--secret id=SEL_PASSWD --sbom=true --attest type=provenance,mode=max -t $(NAME)/base:$(TAG_VERSION) .
7981

8082
base_nightly:
8183
BASE_VERSION=$(BASE_VERSION_NIGHTLY) BASE_RELEASE=$(BASE_RELEASE_NIGHTLY) make base
@@ -99,7 +101,7 @@ event_bus: base
99101
cd ./EventBus && docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) $(FROM_IMAGE_ARGS) -t $(NAME)/event-bus:$(TAG_VERSION) .
100102

101103
node_base: base
102-
cd ./NodeBase && docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) $(FROM_IMAGE_ARGS) -t $(NAME)/node-base:$(TAG_VERSION) .
104+
cd ./NodeBase && SEL_PASSWD=$(SEL_PASSWD) docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) $(FROM_IMAGE_ARGS) --secret id=SEL_PASSWD -t $(NAME)/node-base:$(TAG_VERSION) .
103105

104106
chrome: node_base
105107
case "$(PLATFORMS)" in \
@@ -200,7 +202,7 @@ standalone_edge_beta: edge_beta
200202
cd ./Standalone && docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) --build-arg NAMESPACE=$(NAME) --build-arg VERSION=beta --build-arg BASE=node-edge -t $(NAME)/standalone-edge:beta .
201203

202204
video:
203-
cd ./Video && docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) --build-arg NAMESPACE=$(FFMPEG_BASED_NAME) --build-arg BASED_TAG=$(FFMPEG_BASED_TAG) -t $(NAME)/video:$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) .
205+
cd ./Video && SEL_PASSWD=$(SEL_PASSWD) docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) --build-arg NAMESPACE=$(FFMPEG_BASED_NAME) --build-arg BASED_TAG=$(FFMPEG_BASED_TAG) --secret id=SEL_PASSWD --sbom=true --attest type=provenance,mode=max -t $(NAME)/video:$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) .
204206

205207
count_image_layers:
206208
docker history $(NAME)/base:$(TAG_VERSION) -q | wc -l

NodeBase/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ ENV LANG_WHICH=${LANG_WHICH} \
6767
# Following line fixes https://github.com/SeleniumHQ/docker-selenium/issues/87
6868
DBUS_SESSION_BUS_ADDRESS=/dev/null
6969

70-
RUN apt-get update -qqy \
70+
RUN --mount=type=secret,id=SEL_PASSWD \
71+
apt-get update -qqy \
7172
&& apt-get -qqy --no-install-recommends install \
7273
#==============
7374
# Xvfb
@@ -130,7 +131,7 @@ RUN apt-get update -qqy \
130131
# Generating the VNC password using initial password in Base image
131132
# Changing ownership to ${SEL_USER}, so the service can be started
132133
#==============================
133-
&& x11vnc -storepasswd $(cat /opt/selenium/initialPasswd) ${HOME}/.vnc/passwd \
134+
&& x11vnc -storepasswd $(cat /run/secrets/SEL_PASSWD) ${HOME}/.vnc/passwd \
134135
&& chown -R "${SEL_USER}:${SEL_GROUP}" ${HOME}/.vnc \
135136
&& chmod -R 775 ${HOME} /tmp/.X11-unix \
136137
&& chgrp -R 0 ${HOME} /tmp/.X11-unix \

Video/Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ ARG RCLONE_VERSION=current
77
#Arguments to define the user running the container
88
ARG SEL_USER=seluser
99
ARG SEL_GROUP=${SEL_USER}
10-
ARG SEL_PASSWD=secret
1110
ARG HOME=/home/${SEL_USER}
1211
ARG UID=1200
1312
ARG GID=1201
@@ -34,7 +33,7 @@ ENV DEBIAN_FRONTEND=noninteractive \
3433
RUN apt-get -qqy update \
3534
&& apt-get upgrade -yq \
3635
&& apt-get -qqy --no-install-recommends install \
37-
supervisor x11-xserver-utils x11-utils libxcb1-dev curl jq python3-pip tzdata acl unzip python3-psutil \
36+
supervisor x11-xserver-utils x11-utils libxcb1-dev curl jq python3-pip tzdata acl unzip python3-psutil python3-setuptools \
3837
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
3938

4039
#===================
@@ -57,7 +56,8 @@ ENV SEL_USER=${SEL_USER} \
5756
#========================================
5857
# Add normal user and group with passwordless sudo
5958
#========================================
60-
RUN groupadd ${SEL_GROUP} \
59+
RUN --mount=type=secret,id=SEL_PASSWD \
60+
groupadd ${SEL_GROUP} \
6161
--gid ${SEL_GID} \
6262
&& useradd ${SEL_USER} \
6363
--create-home \
@@ -66,7 +66,7 @@ RUN groupadd ${SEL_GROUP} \
6666
--uid ${SEL_UID} \
6767
&& usermod -a -G sudo ${SEL_USER} \
6868
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \
69-
&& echo "${SEL_USER}:${SEL_PASSWD}" | chpasswd
69+
&& echo "${SEL_USER}:$(cat /run/secrets/SEL_PASSWD)" | chpasswd
7070

7171
#======================================
7272
# Add Supervisor configuration files
@@ -83,9 +83,8 @@ RUN curl -fLo /tmp/rclone.zip https://downloads.rclone.org/rclone-${RCLONE_VERSI
8383
&& rm -rf /tmp/rclone-*
8484
COPY --chown="${SEL_UID}:${SEL_GID}" upload.sh upload.conf /opt/bin/
8585
ENV SE_VIDEO_UPLOAD_ENABLED=false \
86-
SE_UPLOAD_DESTINATION_PREFIX="" \
8786
SE_VIDEO_INTERNAL_UPLOAD=false \
88-
UPLOAD_OPTS="-P"
87+
SE_UPLOAD_DESTINATION_PREFIX=""
8988

9089
RUN mkdir -p /var/run/supervisor /var/log/supervisor ${VIDEO_FOLDER} \
9190
&& chown -R ${SEL_USER}:${SEL_GROUP} /var/run/supervisor /var/log/supervisor ${VIDEO_FOLDER} ${HOME} \

0 commit comments

Comments
 (0)