Skip to content

Commit 13bbd5c

Browse files
authored
Reduce number of layers for Beam container images (#38440)
1 parent 399d9d7 commit 13bbd5c

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

sdks/go/container/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@
1616
# limitations under the License.
1717
###############################################################################
1818

19-
FROM gcr.io/distroless/base-nossl-debian12:latest
19+
FROM gcr.io/distroless/base-nossl-debian12:latest AS base_image
20+
21+
# Distroless base image has many layers. Squash into single layer
22+
FROM scratch
23+
COPY --from=base_image / /
24+
2025
LABEL Author "Apache Beam <dev@beam.apache.org>"
2126

2227
ARG TARGETOS
2328
ARG TARGETARCH
2429

2530
ADD target/${TARGETOS}_${TARGETARCH}/boot /opt/apache/beam/
2631

27-
COPY target/LICENSE /opt/apache/beam/
28-
COPY target/NOTICE /opt/apache/beam/
32+
COPY target/LICENSE target/NOTICE /opt/apache/beam/
2933

3034
# Add Go licenses.
3135
COPY target/go-licenses/* /opt/apache/beam/third_party_licenses/golang/

sdks/java/container/Dockerfile

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@ ARG TARGETARCH
2424

2525
ARG pull_licenses
2626

27-
ADD target/slf4j-api.jar /opt/apache/beam/jars/
28-
ADD target/slf4j-jdk14.jar /opt/apache/beam/jars/
29-
ADD target/jcl-over-slf4j.jar /opt/apache/beam/jars/
30-
ADD target/log4j-over-slf4j.jar /opt/apache/beam/jars/
31-
ADD target/log4j-to-slf4j.jar /opt/apache/beam/jars/
32-
ADD target/beam-sdks-java-harness.jar /opt/apache/beam/jars/
33-
34-
# Required to use jamm as a javaagent to get accurate object size measuring
35-
# COPY fails if file is not found, so use a wildcard for open-module-agent.jar
36-
# since it is only included in Java 9+ containers
37-
COPY target/jamm.jar target/open-module-agent.jar /opt/apache/beam/jars/
38-
39-
COPY target/${TARGETOS}_${TARGETARCH}/boot /opt/apache/beam/
40-
41-
COPY target/LICENSE /opt/apache/beam/
42-
COPY target/NOTICE /opt/apache/beam/
27+
# Dependency jars
28+
COPY target/slf4j-api.jar \
29+
target/slf4j-jdk14.jar \
30+
target/jcl-over-slf4j.jar \
31+
target/log4j-over-slf4j.jar \
32+
target/log4j-to-slf4j.jar \
33+
# Required to use jamm as a javaagent to get accurate object size measuring
34+
target/jamm.jar \
35+
/opt/apache/beam/jars/
36+
37+
# Built jars
38+
COPY target/open-module-agent.jar target/beam-sdks-java-harness.jar /opt/apache/beam/jars/
39+
40+
# Built binary with licenses
41+
COPY target/${TARGETOS}_${TARGETARCH}/boot target/LICENSE target/NOTICE /opt/apache/beam/
4342

4443
# copy third party licenses
4544
ADD target/third_party_licenses /opt/apache/beam/third_party_licenses/

0 commit comments

Comments
 (0)