Skip to content

Commit a6f962a

Browse files
committed
Dockerfile tweaks
* Uses recommended JSON array notation for `CMD` directives. * Suppresses warnings for `sun.misc.Unsafe` usage (for Lucene) emitted by Java 25. * Removes undesired `|| true` and `|| exit 1` occurrences as they don't provide any benefit. * Specifies `--chown` for COPY directives to make ownership more explicit. * Switches from `wget` to `curl` for health check as it has the same flags in Alpine and Debian, which wget does not have. Signed-off-by: nscuro <nscuro@protonmail.com>
1 parent 7e3c0bd commit a6f962a

File tree

4 files changed

+53
-50
lines changed

4 files changed

+53
-50
lines changed

dev/docker-compose.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ name: "dependency-track"
1818

1919
services:
2020
apiserver:
21-
image: dependencytrack/apiserver:snapshot
21+
image: dependencytrack/apiserver:snapshot-alpine
2222
environment:
2323
# Speed up password hashing for faster initial login (default is 14 rounds).
2424
ALPINE_BCRYPT_ROUNDS: "4"
@@ -27,11 +27,6 @@ services:
2727
- "127.0.0.1:8080:8080"
2828
volumes:
2929
- "apiserver-data:/data"
30-
healthcheck:
31-
test: [ "CMD-SHELL", "wget -t 1 -T 3 --no-proxy -q -O /dev/null http://127.0.0.1:8080$${CONTEXT}health || exit 1" ]
32-
interval: 30s
33-
start_period: 60s
34-
timeout: 3s
3530
restart: unless-stopped
3631

3732
frontend:

src/main/docker/Dockerfile

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,41 +64,43 @@ ENV TZ=Etc/UTC \
6464
# Create a user and assign home directory to a ${DATA_DIR}
6565
# Ensure UID 1000 & GID 1000 own all the needed directories
6666
RUN mkdir -p ${APP_DIR} ${DATA_DIR} \
67-
&& groupadd --system --gid ${GID} dtrack || true \
68-
&& useradd --system --no-user-group --gid dtrack --no-create-home --home-dir ${DATA_DIR} --comment "dtrack user" --shell /bin/false --uid ${UID} dtrack || true \
67+
&& groupadd --system --gid ${GID} dtrack \
68+
&& useradd --system --no-user-group --gid dtrack --no-create-home --home-dir ${DATA_DIR} --comment "dtrack user" --shell /bin/false --uid ${UID} dtrack \
6969
&& chown -R dtrack:0 ${DATA_DIR} ${APP_DIR} \
7070
&& chmod -R g=u ${DATA_DIR} ${APP_DIR} \
7171
\
72-
# Install wget for health check
72+
# Install curl for health check
7373
&& apt-get -yqq update \
74-
&& DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends wget \
74+
&& DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends curl \
7575
&& rm -rf /var/lib/apt/lists/*
7676

77-
# Copy JRE from temurin base image
78-
COPY --from=jre-build /opt/java/openjdk $JAVA_HOME
79-
80-
# Copy the compiled WAR to the application directory created above
81-
COPY ./target/${WAR_FILENAME} ./src/main/docker/logback-json.xml ${APP_DIR}
82-
83-
# Specify the user to run as (in numeric format for compatibility with Kubernetes/OpenShift's SCC)
8477
USER ${UID}
85-
86-
# Specify the container working directory
8778
WORKDIR ${APP_DIR}
8879

80+
COPY --from=jre-build --chown=${UID}:0 /opt/java/openjdk $JAVA_HOME
81+
COPY --chown=${UID}:0 ./target/${WAR_FILENAME} ./src/main/docker/logback-json.xml ./
82+
8983
# Launch Dependency-Track
90-
CMD exec java ${JAVA_OPTIONS} ${EXTRA_JAVA_OPTIONS} \
91-
--add-opens java.base/java.util.concurrent=ALL-UNNAMED \
92-
-Dlogback.configurationFile=${LOGGING_CONFIG_PATH} \
93-
-DdependencyTrack.logging.level=${LOGGING_LEVEL} \
94-
-jar ${WAR_FILENAME} \
95-
-context ${CONTEXT}
84+
CMD [ \
85+
"/bin/sh", "-c", \
86+
"exec java \
87+
${JAVA_OPTIONS} ${EXTRA_JAVA_OPTIONS} \
88+
--add-opens java.base/java.util.concurrent=ALL-UNNAMED \
89+
--sun-misc-unsafe-memory-access=allow \
90+
-Dlogback.configurationFile=${LOGGING_CONFIG_PATH} \
91+
-DdependencyTrack.logging.level=${LOGGING_LEVEL} \
92+
-jar ${WAR_FILENAME} \
93+
-context ${CONTEXT}" \
94+
]
9695

9796
# Specify which port Dependency-Track listens on
9897
EXPOSE 8080
9998

10099
# Add a healthcheck using the Dependency-Track version API
101-
HEALTHCHECK --interval=30s --start-period=60s --timeout=3s CMD wget -t 1 -T 3 --no-proxy -q -O /dev/null http://127.0.0.1:8080${CONTEXT}health || exit 1
100+
HEALTHCHECK --interval=30s --start-period=60s --timeout=3s CMD [ \
101+
"/bin/sh", "-c", \
102+
"curl -f -s --max-time 3 --noproxy '*' -o /dev/null http://127.0.0.1:8080${CONTEXT}health" \
103+
]
102104

103105
# metadata labels
104106
LABEL \

src/main/docker/Dockerfile.alpine

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,37 +73,39 @@ ENV TZ=Etc/UTC \
7373
# Create a user and assign home directory to a ${DATA_DIR}
7474
# Ensure UID 1000 & GID 1000 own all the needed directories
7575
RUN mkdir -p ${APP_DIR} ${DATA_DIR} \
76-
&& addgroup -S -g ${GID} dtrack || true \
77-
&& adduser -S -D -G dtrack -H -h ${DATA_DIR} -g "dtrack user" -s /bin/false -u ${UID} dtrack || true \
76+
&& addgroup -S -g ${GID} dtrack \
77+
&& adduser -S -D -G dtrack -H -h ${DATA_DIR} -g "dtrack user" -s /bin/false -u ${UID} dtrack \
7878
&& chown -R dtrack:0 ${DATA_DIR} ${APP_DIR} \
7979
&& chmod -R g=u ${DATA_DIR} ${APP_DIR} \
80-
&& apk add --no-cache tzdata
80+
&& apk add --no-cache tzdata curl
8181

82-
# Copy JRE from temurin base image
83-
COPY --from=jre-build /work/jre ${JAVA_HOME}
84-
85-
# Copy the compiled WAR to the application directory created above
86-
COPY ./target/${WAR_FILENAME} ./src/main/docker/logback-json.xml ${APP_DIR}
87-
88-
# Specify the user to run as (in numeric format for compatibility with Kubernetes/OpenShift's SCC)
8982
USER ${UID}
90-
91-
# Specify the container working directory
9283
WORKDIR ${APP_DIR}
9384

85+
COPY --from=jre-build --chown=${UID}:0 /work/jre ${JAVA_HOME}
86+
COPY --chown=${UID}:0 ./target/${WAR_FILENAME} ./src/main/docker/logback-json.xml ./
87+
9488
# Launch Dependency-Track
95-
CMD exec java ${JAVA_OPTIONS} ${EXTRA_JAVA_OPTIONS} \
96-
--add-opens java.base/java.util.concurrent=ALL-UNNAMED \
97-
-Dlogback.configurationFile=${LOGGING_CONFIG_PATH} \
98-
-DdependencyTrack.logging.level=${LOGGING_LEVEL} \
99-
-jar ${WAR_FILENAME} \
100-
-context ${CONTEXT}
89+
CMD [ \
90+
"/bin/sh", "-c", \
91+
"exec java \
92+
${JAVA_OPTIONS} ${EXTRA_JAVA_OPTIONS} \
93+
--add-opens java.base/java.util.concurrent=ALL-UNNAMED \
94+
--sun-misc-unsafe-memory-access=allow \
95+
-Dlogback.configurationFile=${LOGGING_CONFIG_PATH} \
96+
-DdependencyTrack.logging.level=${LOGGING_LEVEL} \
97+
-jar ${WAR_FILENAME} \
98+
-context ${CONTEXT}" \
99+
]
101100

102101
# Specify which port Dependency-Track listens on
103102
EXPOSE 8080
104103

105104
# Add a healthcheck using the Dependency-Track version API
106-
HEALTHCHECK --interval=30s --start-period=60s --timeout=3s CMD wget -t 1 -T 3 --proxy off -q -O /dev/null http://127.0.0.1:8080${CONTEXT}health || exit 1
105+
HEALTHCHECK --interval=30s --start-period=60s --timeout=3s CMD [ \
106+
"/bin/sh", "-c", \
107+
"curl -f -s --max-time 3 --noproxy '*' -o /dev/null http://127.0.0.1:8080${CONTEXT}health" \
108+
]
107109

108110
# metadata labels
109111
LABEL \

src/main/docker/docker-compose.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ services:
110110
- '8081:8080'
111111
volumes:
112112
- 'dtrack-data:/data'
113-
healthcheck:
114-
test: [ "CMD-SHELL", "wget -t 1 -T 3 --no-proxy -q -O /dev/null http://127.0.0.1:8080$${CONTEXT}health || exit 1" ]
115-
interval: 30s
116-
start_period: 60s
117-
timeout: 3s
113+
# Older versions of Podman Compose do not support the HEALTHCHECK directive
114+
# that is defined in the image's Dockerfile. If you're using Podman and are
115+
# facing healthcheck-related issues, try un-commenting the section below.
116+
#
117+
# healthcheck:
118+
# test: [ "CMD-SHELL", "curl -f -s --max-time 3 --noproxy '*' -o /dev/null http://127.0.0.1:8080$${CONTEXT}health" ]
119+
# interval: 30s
120+
# start_period: 60s
121+
# timeout: 3s
118122
restart: unless-stopped
119123

120124
frontend:

0 commit comments

Comments
 (0)