Skip to content

Commit a3e1eae

Browse files
authored
Reduce Data Node image size (#262)
The tarball needs to be removed once extracted so it doesn't blow up the image. Add another entry to .dockerignore to keep the build context small.
1 parent 02a20e1 commit a3e1eae

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.git/
22
hooks/
33
test/
4+
/venv/

.empty

Whitespace-only changes.

docker/datanode/Dockerfile

+19-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ FROM ubuntu:22.04
44
ARG GRAYLOG_VERSION
55
ARG VCS_REF
66
ARG BUILD_DATE
7-
ARG LOCAL_BUILD_TGZ
7+
# The LOCAL_BUILD_TGZ variable defaults to an empty file. If the variable is
8+
# empty, Docker copies the full context dir into the container. It basically
9+
# executes the following:
10+
# COPY "" "/tmp/datanode-local.tar.gz"
11+
# That creates a /tmp/datanode-local.tar.gz in the container with all files
12+
# from the build context.
13+
ARG LOCAL_BUILD_TGZ=.empty
814
ARG SNAPSHOT_URL_X64=https://downloads.graylog.org/releases/graylog-datanode/graylog-datanode-${GRAYLOG_VERSION}-linux-x64.tgz
915
ARG SNAPSHOT_URL_AARCH64=https://downloads.graylog.org/releases/graylog-datanode/graylog-datanode-${GRAYLOG_VERSION}-linux-aarch64.tgz
1016
ARG DEBIAN_FRONTEND=noninteractive
@@ -50,19 +56,24 @@ RUN apt-get update \
5056
/var/log/*
5157

5258
RUN install -d -o root -g root -m 0755 "$GDN_APP_ROOT"
59+
5360
COPY "${LOCAL_BUILD_TGZ}" "/tmp/datanode-local.tar.gz"
54-
RUN if [ -f /tmp/datanode-local.tar.gz ]; then \
55-
mv /tmp/datanode-local.tar.gz /tmp/datanode.tar.gz \
56-
; fi
57-
RUN if [ -z "${LOCAL_BUILD_TGZ}" ]; then \
61+
62+
# An empty /tmp/datanode-local.tar.gz file indicates that we don't use a
63+
# custom LOCAL_BUILD_TGZ file.
64+
RUN if [ -f /tmp/datanode-local.tar.gz ] && [ -s /tmp/datanode-local.tar.gz ]; then \
65+
mv /tmp/datanode-local.tar.gz /tmp/datanode.tar.gz; \
66+
fi; \
67+
if [ "${LOCAL_BUILD_TGZ}" == ".empty" ]; then \
5868
if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
5969
export SNAPSHOT_URL="$SNAPSHOT_URL_AARCH64"; \
6070
else \
6171
export SNAPSHOT_URL="$SNAPSHOT_URL_X64"; \
6272
fi; \
63-
curl -fsSL --retry 3 "$SNAPSHOT_URL" -o /tmp/datanode.tar.gz \
64-
; fi
65-
RUN tar -C "$GDN_APP_ROOT" --strip-components=1 -xzf /tmp/datanode.tar.gz \
73+
curl -fsSL --retry 3 "$SNAPSHOT_URL" -o /tmp/datanode.tar.gz; \
74+
fi; \
75+
tar -C "$GDN_APP_ROOT" --strip-components=1 -xzf /tmp/datanode.tar.gz \
76+
&& rm -rf /tmp/datanode-local.tar.gz /tmp/datanode.tar.gz \
6677
&& mv "$GDN_APP_ROOT/config/"* "$GDN_CONFIG_DIR"/ \
6778
&& rmdir "$GDN_APP_ROOT/config" \
6879
&& chown -R "$GDN_USER":"$GDN_GROUP" "$GDN_CONFIG_DIR" \

0 commit comments

Comments
 (0)