Skip to content

Commit 8d64f80

Browse files
committed
reduce image size
1 parent b96184f commit 8d64f80

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

kafka/Dockerfile

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,35 @@ WORKDIR /stackable
2727

2828
COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/patches/apply_patches.sh /stackable/kafka-${PRODUCT}-src/patches/apply_patches.sh
2929
COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/patches/${PRODUCT} /stackable/kafka-${PRODUCT}-src/patches/${PRODUCT}
30+
COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/jmx/ /stackable/jmx/
3031

31-
RUN curl "https://repo.stackable.tech/repository/packages/kafka/kafka-${PRODUCT}-src.tgz" | tar -xzC . && \
32-
cd kafka-${PRODUCT}-src && \
33-
./patches/apply_patches.sh ${PRODUCT} && \
34-
# TODO: Try to install gradle via package manager (if possible) instead of fetching it from the internet
35-
# We don't specify "-x test" to skip the tests, as we might bump some Kafka internal dependencies in the future and
36-
# it's a good idea to run the tests in this case.
37-
./gradlew clean releaseTarGz && \
38-
./gradlew cyclonedxBom && \
39-
tar -xf core/build/distributions/kafka_${SCALA}-${PRODUCT}.tgz -C /stackable && \
40-
cp build/reports/bom.json /stackable/kafka_${SCALA}-${PRODUCT}.cdx.json && \
41-
rm -rf /stackable/kafka_${SCALA}-${PRODUCT}/site-docs/ && \
42-
rm -rf /stackable/kafka-${PRODUCT}-src
32+
RUN <<EOF
33+
curl "https://repo.stackable.tech/repository/packages/kafka/kafka-${PRODUCT}-src.tgz" | tar -xzC .
34+
cd kafka-${PRODUCT}-src
35+
./patches/apply_patches.sh ${PRODUCT}
36+
# TODO: Try to install gradle via package manager (if possible) instead of fetching it from the internet
37+
# We don't specify "-x test" to skip the tests, as we might bump some Kafka internal dependencies in the future and
38+
# it's a good idea to run the tests in this case.
39+
./gradlew clean releaseTarGz
40+
./gradlew cyclonedxBom
41+
tar -xf core/build/distributions/kafka_${SCALA}-${PRODUCT}.tgz -C /stackable
42+
cp build/reports/bom.json /stackable/kafka_${SCALA}-${PRODUCT}.cdx.json
43+
rm -rf /stackable/kafka_${SCALA}-${PRODUCT}/site-docs/
44+
rm -rf /stackable/kafka-${PRODUCT}-src
4345

4446
# TODO (@NickLarsenNZ): Compile from source: https://github.com/StyraInc/opa-kafka-plugin
45-
RUN curl https://repo.stackable.tech/repository/packages/kafka-opa-authorizer/opa-authorizer-${OPA_AUTHORIZER}-all.jar \
46-
-o /stackable/kafka_${SCALA}-${PRODUCT}/libs/opa-authorizer-${OPA_AUTHORIZER}-all.jar
47+
curl https://repo.stackable.tech/repository/packages/kafka-opa-authorizer/opa-authorizer-${OPA_AUTHORIZER}-all.jar \
48+
-o /stackable/kafka_${SCALA}-${PRODUCT}/libs/opa-authorizer-${OPA_AUTHORIZER}-all.jar
4749

48-
COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/jmx/ /stackable/jmx/
49-
RUN curl https://repo.stackable.tech/repository/packages/jmx-exporter/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar \
50-
-o /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar && \
51-
chmod +x /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar && \
52-
ln -s /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar /stackable/jmx/jmx_prometheus_javaagent.jar
50+
# JMX exporter
51+
curl https://repo.stackable.tech/repository/packages/jmx-exporter/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar \
52+
-o /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar
53+
chmod +x /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar
54+
ln -s /stackable/jmx/jmx_prometheus_javaagent-${JMX_EXPORTER}.jar /stackable/jmx/jmx_prometheus_javaagent.jar
5355

56+
# change groups
57+
chmod -R g=u /stackable
58+
EOF
5459

5560
FROM stackable/image/java-base AS final
5661

@@ -60,21 +65,23 @@ ARG SCALA
6065
ARG KCAT
6166
ARG STACKABLE_USER_UID
6267

63-
LABEL name="Apache Kafka" \
64-
maintainer="[email protected]" \
65-
vendor="Stackable GmbH" \
66-
version="${PRODUCT}" \
67-
release="${RELEASE}" \
68-
summary="The Stackable image for Apache Kafka." \
69-
description="This image is deployed by the Stackable Operator for Apache Kafka."
68+
LABEL \
69+
name="Apache Kafka" \
70+
maintainer="[email protected]" \
71+
vendor="Stackable GmbH" \
72+
version="${PRODUCT}" \
73+
release="${RELEASE}" \
74+
summary="The Stackable image for Apache Kafka." \
75+
description="This image is deployed by the Stackable Operator for Apache Kafka."
7076

71-
COPY --chown=${STACKABLE_USER_UID}:0 kafka/licenses /licenses
7277
COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/kafka_${SCALA}-${PRODUCT} /stackable/kafka_${SCALA}-${PRODUCT}
7378
COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/kafka_${SCALA}-${PRODUCT}.cdx.json /stackable/kafka_${SCALA}-${PRODUCT}/kafka_${SCALA}-${PRODUCT}.cdx.json
7479
COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-builder /stackable/jmx/ /stackable/jmx/
7580
COPY --chown=${STACKABLE_USER_UID}:0 --from=kcat /stackable/kcat-${KCAT}/kcat /stackable/bin/kcat-${KCAT}
7681
COPY --chown=${STACKABLE_USER_UID}:0 --from=kcat /licenses /licenses
7782

83+
COPY --chown=${STACKABLE_USER_UID}:0 kafka/licenses /licenses
84+
7885
WORKDIR /stackable
7986

8087
RUN <<EOF
@@ -85,21 +92,20 @@ microdnf install \
8592

8693
microdnf clean all
8794
rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}\n" | sort > /stackable/package_manifest.txt
95+
chown ${STACKABLE_USER_UID}:0 /stackable/package_manifest.txt
8896
rm -rf /var/cache/yum
8997

9098
ln -s /stackable/bin/kcat-${KCAT} /stackable/bin/kcat
99+
chown -h ${STACKABLE_USER_UID}:0 /stackable/bin/kcat
91100
# kcat was located in /stackable/kcat - legacy
92101
ln -s /stackable/bin/kcat /stackable/kcat
102+
chown -h ${STACKABLE_USER_UID}:0 /stackable/kcat
93103
ln -s /stackable/kafka_${SCALA}-${PRODUCT} /stackable/kafka
94-
95-
# All files and folders owned by root group to support running as arbitrary users.
96-
# This is best practice as all container users will belong to the root group (0).
97-
chown -R ${STACKABLE_USER_UID}:0 /stackable
98-
chmod -R g=u /stackable
104+
chown -h ${STACKABLE_USER_UID}:0 /stackable/kafka
99105
EOF
100106

101107
# ----------------------------------------
102-
# Attention: We are changing the group of all files in /stackable directly above
108+
# Attention:
103109
# If you do any file based actions (copying / creating etc.) below this comment you
104110
# absolutely need to make sure that the correct permissions are applied!
105111
# chown ${STACKABLE_USER_UID}:0

0 commit comments

Comments
 (0)