Skip to content

Commit 55e05b1

Browse files
authored
build: optimize image layers in base images (#2212)
1 parent 35968ad commit 55e05b1

File tree

8 files changed

+152
-245
lines changed

8 files changed

+152
-245
lines changed

.github/workflows/build-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ jobs:
4747
echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
4848
make set_nightly_env
4949
cat .env | xargs -I {} echo {} >> $GITHUB_ENV
50-
echo "GH_ORG=${GH_ORG}" >> $GITHUB_ENV
50+
echo "AUTHORS=${AUTHORS}" >> $GITHUB_ENV
5151
env:
52-
GH_ORG: ${{ vars.GH_ORG || 'SeleniumHQ' }}
52+
AUTHORS: ${{ vars.AUTHORS || 'SeleniumHQ' }}
5353
- name: Build Docker images
5454
run: VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make build
5555
- name: Count image layers

.github/workflows/deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
echo "NAME=${NAMESPACE}" >> $GITHUB_ENV
2828
env:
2929
NAMESPACE: ${{ vars.DOCKER_NAMESPACE || 'selenium' }}
30-
GH_ORG: ${{ vars.GH_ORG || 'SeleniumHQ' }}
30+
AUTHORS: ${{ vars.AUTHORS || 'SeleniumHQ' }}
3131
- name: Sets prerelease to false by default
3232
run: echo "PRERELEASE=false" >> $GITHUB_ENV
3333
- name: Build base image to get Grid version

.github/workflows/helm-chart-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ jobs:
101101
echo "IMAGE_REGISTRY=artifactory/selenium" >> $GITHUB_ENV
102102
make set_nightly_env
103103
cat .env | xargs -I {} echo {} >> $GITHUB_ENV
104-
echo "GH_ORG=${GH_ORG}" >> $GITHUB_ENV
104+
echo "AUTHORS=${AUTHORS}" >> $GITHUB_ENV
105105
env:
106-
GH_ORG: ${{ vars.GH_ORG || 'SeleniumHQ' }}
106+
AUTHORS: ${{ vars.AUTHORS || 'SeleniumHQ' }}
107107
- name: Setup Kubernetes environment
108108
uses: nick-invision/retry@master
109109
with:

.github/workflows/nightly.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ jobs:
2323
run: |
2424
echo "PRERELEASE=true" >> $GITHUB_ENV
2525
echo "NAME=${NAMESPACE}" >> $GITHUB_ENV
26-
echo "GH_ORG=${GH_ORG}" >> $GITHUB_ENV
26+
echo "AUTHORS=${AUTHORS}" >> $GITHUB_ENV
2727
env:
2828
NAMESPACE: ${{ vars.DOCKER_NAMESPACE || 'selenium' }}
29-
GH_ORG: ${{ vars.GH_ORG || 'SeleniumHQ' }}
29+
AUTHORS: ${{ vars.AUTHORS || 'SeleniumHQ' }}
3030
- name: Build base image to get Grid version
3131
run: VERSION="local" BUILD_DATE=${BUILD_DATE} make base_nightly
3232
- name: Get Grid version

.github/workflows/test-video.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ jobs:
6363
echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
6464
make set_nightly_env
6565
cat .env | xargs -I {} echo {} >> $GITHUB_ENV
66-
echo "GH_ORG=${GH_ORG}" >> $GITHUB_ENV
66+
echo "AUTHORS=${AUTHORS}" >> $GITHUB_ENV
6767
env:
68-
GH_ORG: ${{ vars.GH_ORG || 'SeleniumHQ' }}
68+
AUTHORS: ${{ vars.AUTHORS || 'SeleniumHQ' }}
6969
- name: Pre-build to reduce logs in test phase
7070
run: |
7171
VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make hub

Base/Dockerfile

+58-82
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LABEL authors="Selenium <selenium-developers@googlegroups.com>"
44
# Arguments to define the version of dependencies to download
55
ARG VERSION
66
ARG RELEASE=selenium-${VERSION}
7-
ARG GH_ORG=SeleniumHQ
7+
ARG AUTHORS=SeleniumHQ
88
# Default value should be aligned with upstream Selenium (https://github.com/SeleniumHQ/selenium/blob/trunk/java/maven_deps.bzl)
99
ARG OPENTELEMETRY_VERSION=1.36.0
1010
ARG GRPC_VERSION=1.62.2
@@ -15,27 +15,31 @@ ARG SEL_GROUP=${SEL_USER}
1515
ARG SEL_PASSWD=secret
1616
ARG UID=1200
1717
ARG GID=1201
18-
19-
USER root
20-
#================================================
21-
# Customize sources for apt-get
22-
#================================================
23-
RUN echo "deb http://archive.ubuntu.com/ubuntu jammy main universe\n" > /etc/apt/sources.list \
24-
&& echo "deb http://archive.ubuntu.com/ubuntu jammy-updates main universe\n" >> /etc/apt/sources.list \
25-
&& echo "deb http://security.ubuntu.com/ubuntu jammy-security main universe\n" >> /etc/apt/sources.list
18+
ARG TZ="UTC"
19+
ARG JRE_VERSION=17
2620
ARG TARGETARCH=amd64
2721
ARG TARGETVARIANT
2822

29-
# No interactive frontend during docker build
23+
USER root
24+
3025
ENV DEBIAN_FRONTEND=noninteractive \
31-
DEBCONF_NONINTERACTIVE_SEEN=true
26+
# No interactive frontend during docker build
27+
DEBCONF_NONINTERACTIVE_SEEN=true \
28+
SEL_USER=${SEL_USER} \
29+
SEL_UID=${UID} \
30+
SEL_GID=${GID} \
31+
HOME=/home/${SEL_USER} \
32+
TZ=${TZ} \
33+
SEL_DOWNLOAD_DIR=${HOME}/Downloads
3234

3335
#========================
3436
# Miscellaneous packages
3537
# Includes minimal runtime used for executing non GUI Java programs
3638
#========================
37-
ARG JRE_VERSION=17
38-
RUN apt-get -qqy update \
39+
RUN echo "deb http://archive.ubuntu.com/ubuntu jammy main universe\n" > /etc/apt/sources.list \
40+
&& echo "deb http://archive.ubuntu.com/ubuntu jammy-updates main universe\n" >> /etc/apt/sources.list \
41+
&& echo "deb http://security.ubuntu.com/ubuntu jammy-security main universe\n" >> /etc/apt/sources.list \
42+
&& apt-get -qqy update \
3943
&& apt-get upgrade -yq \
4044
&& apt-get -qqy --no-install-recommends install \
4145
acl \
@@ -56,40 +60,24 @@ RUN apt-get -qqy update \
5660
&& echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list >dev/null \
5761
&& apt-get -qqy update \
5862
&& apt-get -qqy --no-install-recommends install temurin-${JRE_VERSION}-jre -y \
59-
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
60-
61-
#===================
62-
63-
RUN if [ $TARGETARCH = "arm" ] && [ $TARGETVARIANT = "v7" ]; then \
63+
&& if [ "${TARGETARCH}" = "arm" ] && [ "${TARGETVARIANT}" = "v7" ]; then \
6464
export ARCH=armhf ; \
6565
else \
66-
export ARCH=$TARGETARCH ; \
66+
export ARCH=${TARGETARCH} ; \
6767
fi \
68-
&& sed -i 's/securerandom\.source=file:\/dev\/random/securerandom\.source=file:\/dev\/urandom/' ./usr/lib/jvm/temurin-${JRE_VERSION}-jre-$ARCH/conf/security/java.security
69-
70-
68+
&& sed -i 's/securerandom\.source=file:\/dev\/random/securerandom\.source=file:\/dev\/urandom/' ./usr/lib/jvm/temurin-${JRE_VERSION}-jre-${ARCH}/conf/security/java.security \
69+
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
7170
#===================
7271
# Timezone settings
7372
# Possible alternative: https://github.com/docker/docker/issues/3359#issuecomment-32150214
7473
#===================
75-
ENV TZ "UTC"
76-
RUN ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime && \
74+
&& ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime && \
7775
dpkg-reconfigure -f noninteractive tzdata && \
78-
cat /etc/timezone
79-
80-
#======================================
81-
# Configure environement
82-
#======================================
83-
ENV SEL_USER=${SEL_USER}
84-
ENV SEL_UID=${UID}
85-
ENV SEL_GID=${GID}
86-
ENV HOME=/home/${SEL_USER}
87-
ENV SEL_DOWNLOAD_DIR=${HOME}/Downloads
88-
76+
cat /etc/timezone \
8977
#========================================
90-
# Add normal user and group with passwordless sudo
78+
# Add normal user and group without password sudo
9179
#========================================
92-
RUN groupadd ${SEL_GROUP} \
80+
&& groupadd ${SEL_GROUP} \
9381
--gid ${SEL_GID} \
9482
&& useradd ${SEL_USER} \
9583
--create-home \
@@ -98,75 +86,63 @@ RUN groupadd ${SEL_GROUP} \
9886
--uid ${SEL_UID} \
9987
&& usermod -a -G sudo ${SEL_USER} \
10088
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \
101-
&& echo "${SEL_USER}:${SEL_PASSWD}" | chpasswd
102-
103-
#======================================
104-
# Add Grid check script
105-
#======================================
106-
COPY --chown="${SEL_UID}:${SEL_GID}" check-grid.sh entry_point.sh /opt/bin/
107-
108-
#======================================
109-
# Add Supervisor configuration file
110-
#======================================
111-
COPY supervisord.conf /etc
112-
89+
&& echo "${SEL_USER}:${SEL_PASSWD}" | chpasswd \
11390
#==========
11491
# Selenium & relaxing permissions for OpenShift and other non-sudo environments
11592
#==========
116-
RUN mkdir -p /opt/selenium /opt/selenium/assets /var/run/supervisor /var/log/supervisor ${SEL_DOWNLOAD_DIR} \
93+
&& mkdir -p /opt/selenium /opt/selenium/assets /var/run/supervisor /var/log/supervisor ${SEL_DOWNLOAD_DIR} \
11794
${HOME}/.mozilla ${HOME}/.vnc $HOME/.pki/nssdb \
95+
# NSSDB initialization with an empty password
96+
&& certutil -d sql:$HOME/.pki/nssdb -N --empty-password \
11897
&& touch /opt/selenium/config.toml \
11998
&& chown -R ${SEL_USER}:${SEL_GROUP} /opt/selenium /var/run/supervisor /var/log/supervisor /etc/passwd ${HOME} \
12099
&& chmod -R 775 /opt/selenium /var/run/supervisor /var/log/supervisor /etc/passwd ${HOME} \
121-
&& wget --no-verbose https://github.com/${GH_ORG}/selenium/releases/download/${RELEASE}/selenium-server-${VERSION}.jar \
100+
&& wget --no-verbose https://github.com/${AUTHORS}/selenium/releases/download/${RELEASE}/selenium-server-${VERSION}.jar \
122101
-O /opt/selenium/selenium-server.jar \
123102
&& echo "${SEL_PASSWD}" > /opt/selenium/initialPasswd \
124103
&& chgrp -R 0 /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor \
125104
&& chmod -R g=u /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor \
126105
&& setfacl -Rm u:${SEL_USER}:rwx /opt /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor \
127-
&& setfacl -Rm g:${SEL_GROUP}:rwx /opt /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor
128-
106+
&& setfacl -Rm g:${SEL_GROUP}:rwx /opt /opt/selenium ${HOME} /opt/selenium/assets /var/run/supervisor /var/log/supervisor \
129107
#=====
130-
# Download observability related jaegar jars and make them available in a separate directory
108+
# Download observability related OpenTelemetry jars and make them available in a separate directory
131109
# so that the container can skip downloading them everytime it comes up
132110
#=====
133-
RUN curl -fLo /tmp/cs https://github.com/coursier/launchers/raw/master/coursier \
111+
&& curl -fLo /tmp/cs https://github.com/coursier/launchers/raw/master/coursier \
134112
&& chmod +x /tmp/cs \
135113
&& mkdir -p /external_jars \
136-
&& chmod -R 775 /external_jars
137-
138-
RUN /tmp/cs fetch --classpath --cache /external_jars \
114+
&& chmod -R 775 /external_jars \
115+
&& /tmp/cs fetch --classpath --cache /external_jars \
139116
io.opentelemetry:opentelemetry-exporter-otlp:${OPENTELEMETRY_VERSION} \
140-
io.grpc:grpc-netty:${GRPC_VERSION} > /external_jars/.classpath.txt
117+
io.grpc:grpc-netty:${GRPC_VERSION} > /external_jars/.classpath.txt \
118+
&& chmod 664 /external_jars/.classpath.txt \
119+
&& rm -fr /root/.cache/* \
120+
# (Note that .bashrc is only executed in interactive bash shells.)
121+
&& echo 'if [[ $(ulimit -n) -gt 200000 ]]; then echo "WARNING: Very high value reported by \"ulimit -n\". Consider passing \"--ulimit nofile=32768\" to \"docker run\"."; fi' >> ${HOME}/.bashrc
141122

142-
RUN chmod 664 /external_jars/.classpath.txt
143-
RUN rm -fr /root/.cache/*
123+
#======================================
124+
# Add Grid check script
125+
#======================================
126+
COPY --chown="${SEL_UID}:${SEL_GID}" check-grid.sh entry_point.sh /opt/bin/
127+
128+
#======================================
129+
# Add Supervisor configuration file
130+
#======================================
131+
COPY supervisord.conf /etc
144132

145133
#===================================================
146134
# Run the following commands as non-privileged user
147135
#===================================================
148136
USER ${SEL_UID}:${SEL_GID}
149137

150-
#==========
151-
# NSSDB initialization with an empty password
152-
#==========
153-
RUN certutil -d sql:$HOME/.pki/nssdb -N --empty-password
154-
155-
# Boolean value, maps "--bind-host"
156-
ENV SE_BIND_HOST false
157-
# Boolean value, maps "--reject-unsupported-caps"
158-
ENV SE_REJECT_UNSUPPORTED_CAPS false
159-
160-
ENV SE_OTEL_JAVA_GLOBAL_AUTOCONFIGURE_ENABLED true
161-
ENV SE_OTEL_TRACES_EXPORTER "otlp"
162-
163-
# A too high maximum number of file descriptors (with the default value
164-
# inherited from the docker host) can cause issues with some of our tools:
165-
# - sanitizers hanging: https://github.com/google/sanitizers/issues/1662
166-
# - valgrind crashing: https://stackoverflow.com/a/75293014
167-
# This is not be a problem on our CI hosts, but developers who run the image
168-
# on their machines may run into this (e.g., on Arch Linux), so warn them.
169-
# (Note that .bashrc is only executed in interactive bash shells.)
170-
RUN echo 'if [[ $(ulimit -n) -gt 200000 ]]; then echo "WARNING: Very high value reported by \"ulimit -n\". Consider passing \"--ulimit nofile=32768\" to \"docker run\"."; fi' >> ${HOME}/.bashrc
138+
#======================================
139+
# Configure environement
140+
#======================================
141+
# Boolean value, maps "--bind-host"
142+
ENV SE_BIND_HOST=false \
143+
# Boolean value, maps "--reject-unsupported-caps"
144+
SE_REJECT_UNSUPPORTED_CAPS=false \
145+
SE_OTEL_JAVA_GLOBAL_AUTOCONFIGURE_ENABLED=true \
146+
SE_OTEL_TRACES_EXPORTER="otlp"
171147

172148
CMD ["/opt/bin/entry_point.sh"]

Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
NAME := $(or $(NAME),$(NAME),selenium)
22
CURRENT_DATE := $(shell date '+%Y%m%d')
33
BUILD_DATE := $(or $(BUILD_DATE),$(BUILD_DATE),$(CURRENT_DATE))
4-
GH_ORG := $(or $(GH_ORG),$(GH_ORG),SeleniumHQ)
54
BASE_RELEASE := $(or $(BASE_RELEASE),$(BASE_RELEASE),selenium-4.19.0)
65
BASE_VERSION := $(or $(BASE_VERSION),$(BASE_VERSION),4.19.1)
76
BINDING_VERSION := $(or $(BINDING_VERSION),$(BINDING_VERSION),4.19.0)
@@ -50,10 +49,10 @@ build: all
5049
ci: build test
5150

5251
base:
53-
cd ./Base && docker build $(BUILD_ARGS) --build-arg VERSION=$(BASE_VERSION) --build-arg RELEASE=$(BASE_RELEASE) --build-arg GH_ORG=$(GH_ORG) -t $(NAME)/base:$(TAG_VERSION) .
52+
cd ./Base && docker build $(BUILD_ARGS) --build-arg VERSION=$(BASE_VERSION) --build-arg RELEASE=$(BASE_RELEASE) --build-arg AUTHORS=$(AUTHORS) -t $(NAME)/base:$(TAG_VERSION) .
5453

5554
base_nightly:
56-
cd ./Base && docker build $(BUILD_ARGS) --build-arg VERSION=$(BASE_VERSION_NIGHTLY) --build-arg RELEASE=$(BASE_RELEASE_NIGHTLY) --build-arg GH_ORG=$(GH_ORG) -t $(NAME)/base:$(TAG_VERSION) .
55+
cd ./Base && docker build $(BUILD_ARGS) --build-arg VERSION=$(BASE_VERSION_NIGHTLY) --build-arg RELEASE=$(BASE_RELEASE_NIGHTLY) --build-arg AUTHORS=$(AUTHORS) -t $(NAME)/base:$(TAG_VERSION) .
5756

5857
hub: base
5958
cd ./Hub && docker build $(BUILD_ARGS) $(FROM_IMAGE_ARGS) -t $(NAME)/hub:$(TAG_VERSION) .

0 commit comments

Comments
 (0)