Skip to content

Commit 597b311

Browse files
chore: build the layers
1 parent 3c4b9f1 commit 597b311

File tree

3 files changed

+107
-4
lines changed

3 files changed

+107
-4
lines changed

.gitlab/scripts/build_layer.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# Unless explicitly stated otherwise all files in this repository are licensed
4+
# under the Apache License Version 2.0.
5+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
6+
# Copyright 2024 Datadog, Inc.
7+
8+
set -e
9+
10+
if [ -z "$ARCHITECTURE" ]; then
11+
printf "[ERROR]: ARCHITECTURE not specified\n"
12+
exit 1
13+
fi
14+
15+
if [ -z "$ALPINE" ]; then
16+
printf "[ERROR]: ALPINE not specified\n"
17+
exit 1
18+
fi
19+
20+
prepare_folders() {
21+
# Move into the root directory, so this script can be called from any directory
22+
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
23+
ROOT_DIR=$SCRIPTS_DIR/../..
24+
cd $ROOT_DIR
25+
26+
echo $ROOT_DIR
27+
28+
EXTENSION_DIR=".layers"
29+
TARGET_DIR=$(pwd)/$EXTENSION_DIR
30+
31+
rm -rf ${EXTENSION_DIR} 2>/dev/null
32+
mkdir -p $EXTENSION_DIR
33+
34+
cd $ROOT_DIR
35+
}
36+
37+
38+
docker_build() {
39+
local arch=$1
40+
41+
docker buildx build --platform linux/${arch} \
42+
-t datadog/build-extension-${SUFFIX} \
43+
-f ./scripts/Dockerfile.build_layer \
44+
--build-arg SUFFIX=$SUFFIX \
45+
. -o $TARGET_DIR/datadog-extension-${SUFFIX}
46+
47+
cp $TARGET_DIR/datadog-extension-${SUFFIX}/datadog_extension.zip $TARGET_DIR/datadog_extension-${SUFFIX}.zip
48+
unzip $TARGET_DIR/datadog-extension-${SUFFIX}/datadog_extension.zip -d $TARGET_DIR/datadog_extension-${SUFFIX}
49+
rm -rf $TARGET_DIR/datadog-extension-${SUFFIX}/
50+
}
51+
52+
prepare_folders
53+
docker_build $ARCHITECTURE

.gitlab/templates/pipeline.yaml.tpl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
stages:
22
# TODO: swap these back once we're happy with the compile speed
3-
- compile
3+
- compile binaries
44
- check code
5+
- build layers
56
- build
67
- test
78
- sign
@@ -48,7 +49,7 @@ cargo clippy ({{ $flavor.name }}):
4849
{{ end }} # end needs_code_checks
4950

5051
go agent ({{ $flavor.name }}):
51-
stage: compile
52+
stage: compile binaries
5253
image: registry.ddbuild.io/images/docker:20.10
5354
tags: ["arch:amd64"]
5455
needs: []
@@ -68,9 +69,8 @@ go agent ({{ $flavor.name }}):
6869
- cd .. && git clone -b $AGENT_BRANCH --single-branch https://github.com/DataDog/datadog-agent.git && cd datadog-agent && git rev-parse HEAD && cd ../datadog-lambda-extension
6970
- .gitlab/scripts/compile_go_agent.sh
7071

71-
7272
bottlecap ({{ $flavor.name }}):
73-
stage: compile
73+
stage: compile binaries
7474
image: registry.ddbuild.io/images/docker:20.10
7575
tags: ["arch:amd64"]
7676
needs: []
@@ -85,6 +85,30 @@ bottlecap ({{ $flavor.name }}):
8585
script:
8686
- .gitlab/scripts/compile_bottlecap.sh
8787

88+
layer ({{ $flavor.name }}):
89+
stage: build layers
90+
image: registry.ddbuild.io/images/docker:20.10
91+
tags: ["arch:amd64"]
92+
needs:
93+
- go agent ({{ $flavor.name }})
94+
- bottlecap ({{ $flavor.name }})
95+
dependencies:
96+
- go agent ({{ $flavor.name })
97+
- bottlecap ({{ $flavor.name }})
98+
artifacts:
99+
expire_in: 1 hr
100+
paths:
101+
- .layers/datadog_extension-{{ $flavor.suffix }}.zip
102+
- .layers/datadog_extension-{{ $flavor.suffix }}/*
103+
variables:
104+
ARCHITECTURE: {{ $flavor.arch }}
105+
ALPINE: {{ $flavor.alpine }}
106+
SUFFIX: {{ $flavor.suffix }}
107+
script:
108+
- .gitlab/scripts/build_layer.sh
109+
110+
{{ if $flavor.alpine }}
111+
88112
{{ end }} # end flavors
89113
90114
{{ range $architecture := (ds "architectures").architectures }}

scripts/Dockerfile.build_layer

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM ubuntu:22.04 as compresser
2+
ARG DATADOG_WRAPPER=datadog_wrapper
3+
ARG SUFFIX
4+
5+
RUN apt-get update
6+
RUN apt-get install -y zip binutils upx
7+
8+
COPY .binaries/datadog-agent-$SUFFIX /datadog-agent-go
9+
RUN strip /datadog-agent-go
10+
RUN upx -1 /datadog-agent-go
11+
12+
RUN mkdir /extensions
13+
WORKDIR /extensions
14+
15+
COPY .binaries/bottlecap-$SUFFIX /extensions/datadog-agent
16+
17+
COPY ./scripts/$DATADOG_WRAPPER /$DATADOG_WRAPPER
18+
RUN chmod +x /$DATADOG_WRAPPER
19+
20+
RUN zip -r datadog_extension.zip /extensions /$DATADOG_WRAPPER /datadog-agent-go
21+
22+
# keep the smallest possible docker image
23+
FROM scratch
24+
COPY --from=compresser /extensions/datadog_extension.zip /
25+
ENTRYPOINT ["/datadog_extension.zip"]
26+

0 commit comments

Comments
 (0)