Skip to content

Commit 5ce79a1

Browse files
authored
only use upx compression on x86 platform (#559)
* only use upx compression on x86 platform * pin upx version * restore previous layer size check * alpine has no apt-get * bump alpine upx version to 4.2.4 since it's the one in the repo * fix script * check if upx is already installed * Revert "check if upx is already installed" This reverts commit ff62c8b. * try another version of upx * fix datadog path * fix datadog name * fix filename * the go binary is already stirpped, running it again causes error: the input file '/datadog-agent-go' has no sections * relax size limit
1 parent f70901a commit 5ce79a1

File tree

7 files changed

+15
-12
lines changed

7 files changed

+15
-12
lines changed

.gitlab/scripts/Dockerfile.build_layer

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ ARG DATADOG_WRAPPER=datadog_wrapper
33
ARG SUFFIX
44

55
RUN apt-get update
6-
RUN apt-get install -y zip binutils upx
6+
RUN apt-get install -y zip binutils
77

88
COPY .binaries/datadog-agent-$SUFFIX /datadog-agent-go
9-
RUN strip /datadog-agent-go
10-
RUN upx -1 /datadog-agent-go
9+
RUN if [ "$PLATFORM" = "x86_64" ]; then apt-get install -y upx=3.96-r0 && upx -1 /datadog-agent-go; fi
1110

1211
RUN mkdir /extensions
1312
WORKDIR /extensions

.gitlab/scripts/Dockerfile.go_agent.alpine.compile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ RUN /usr/lib/go/bin/go tool nm datadog-agent | grep -w 'github.com/DataDog/datad
4242
(echo "agentVersionDefault variable doesn't exist" && exit 1)
4343

4444
RUN strip datadog-agent
45+
RUN arch="$(uname -m)"; \
46+
if [ "${arch}" = 'x86_64' ]; then \
47+
apk add --no-cache upx=3.96-r1 && upx -1 datadog-agent; \
48+
fi;
49+
4550

4651
# keep the smallest possible docker image
4752
FROM scratch

.gitlab/scripts/Dockerfile.go_agent.compile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ RUN /usr/local/go/bin/go tool nm datadog-agent | grep -w 'github.com/DataDog/dat
4444
(echo "agentVersionDefault variable doesn't exist" && exit 1)
4545

4646
RUN strip datadog-agent
47+
RUN if [ "$arch" = "x86_64" ]; then apt-get install -y upx=3.96-r0 && upx -1 /datadog-agent; fi
4748

4849
# keep the smallest possible docker imag
4950
FROM scratch

.gitlab/scripts/check_layer_size.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if [ -z "$LAYER_FILE" ]; then
2424
fi
2525

2626
MAX_LAYER_COMPRESSED_SIZE_KB=$(( 23 * 1024)) # 23 MB, amd64 is 22, while arm64 is 20
27-
MAX_LAYER_UNCOMPRESSED_SIZE_KB=$(( 30 * 1024)) # 53 MB -> 30MB with UPX
27+
MAX_LAYER_UNCOMPRESSED_SIZE_KB=$(( 54 * 1024 )) # 53 MB, amd is 53, while arm64 is 47
2828

2929
FILE=".layers"/$LAYER_FILE
3030
FILE_SIZE=$(stat --printf="%s" "$FILE")

scripts/Dockerfile.bottlecap.alpine.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ ARG DATADOG_WRAPPER=datadog_wrapper
3232
ARG GO_AGENT_PATH
3333

3434
RUN apt-get update
35-
RUN apt-get install -y zip binutils upx
35+
RUN apt-get install -y zip binutils
3636

3737
COPY .layers/$GO_AGENT_PATH/extensions/datadog-agent /datadog-agent-go
3838
RUN strip /datadog-agent-go
39-
RUN upx -1 /datadog-agent-go
39+
RUN if [ "$PLATFORM" = "x86_64" ]; then apt-get install -y upx=3.96-r0 && upx -1 /datadog-agent-go; fi
4040

4141

4242
RUN mkdir /extensions

scripts/Dockerfile.bottlecap.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ ARG DATADOG_WRAPPER=datadog_wrapper
2525
ARG GO_AGENT_PATH
2626

2727
RUN apt-get update
28-
RUN apt-get install -y zip binutils upx
28+
RUN apt-get install -y zip binutils
2929
COPY .layers/$GO_AGENT_PATH/extensions/datadog-agent /datadog-agent-go
3030
RUN strip /datadog-agent-go
31-
RUN upx -1 /datadog-agent-go
31+
RUN if [ "$PLATFORM" = "x86_64" ]; then apt-get install -y upx=3.96-r0 && upx -1 /datadog-agent-go; fi
3232

3333

3434
RUN mkdir /extensions

scripts/Dockerfile.bottlecap.dev

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ FROM ubuntu:22.04 as compresser
2323
ARG DATADOG_WRAPPER=datadog_wrapper
2424

2525
RUN apt-get update
26-
RUN apt-get install -y zip binutils upx
26+
RUN apt-get install -y zip binutils
2727
COPY --from=public.ecr.aws/datadog/lambda-extension:64 /opt/datadog-agent-go /datadog-agent-go
28-
RUN du -h /datadog-agent-go
29-
RUN upx -1 /datadog-agent-go
30-
RUN du -h /datadog-agent-go
28+
RUN if [ "$PLATFORM" = "x86_64" ]; then apt-get install -y upx=3.96-r0 && upx -1 /datadog-agent-go; fi
3129
RUN mkdir /extensions
3230
WORKDIR /extensions
3331

0 commit comments

Comments
 (0)