Skip to content

Commit eed1883

Browse files
authored
chore: consolidate scripts (#568)
* remove unused files and directories * update images to have explanation on docker layer steps * update `feature_request_template.md` * move `Dockerfile`s to `images` folder * remove `build_and_publish_docker_image.sh` * remove more unused scripts * add check for `SUFFIX` on `compile_*` scripts * update and move bottlecap dev image * update `compile` scripts * make `build_layer.sh` to use suffix check * simplify bottlecap dev script * removed unused script and image
1 parent 6fba976 commit eed1883

26 files changed

Lines changed: 154 additions & 648 deletions

.github/feature_request_template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ about: Suggest an idea
1717

1818
## Specifications
1919

20-
- Datadog Lambda Layer version:
21-
- Python version:
20+
- Datadog Extension version:
21+
- Datadog Lambda Library name and version:
2222

2323
## Stacktrace
2424

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.layers
3+
.binaries
34
.idea
45
.serverless
56
response.x

.gitlab/scripts/build_image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fi
4040

4141
docker buildx build \
4242
--platform $PLATFORM \
43-
-f .gitlab/scripts/${TARGET_IMAGE} \
43+
-f ./images/${TARGET_IMAGE} \
4444
--tag "$DOCKER_TARGET_IMAGE:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}${SUFFIX}" \
4545
--push .
4646
printf "Image built and pushed to $DOCKER_TARGET_IMAGE:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}${SUFFIX} for $PLATFORM\n"

.gitlab/scripts/build_layer.sh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,37 @@ if [ -z "$ARCHITECTURE" ]; then
1212
exit 1
1313
fi
1414

15-
prepare_folders() {
16-
# Move into the root directory, so this script can be called from any directory
17-
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
18-
ROOT_DIR=$SCRIPTS_DIR/../..
19-
cd $ROOT_DIR
20-
21-
echo $ROOT_DIR
15+
if [ -z "$SUFFIX" ]; then
16+
printf "No suffix provided, using ${ARCHITECTURE}\n"
17+
SUFFIX=$ARCHITECTURE
18+
fi
2219

23-
EXTENSION_DIR=".layers"
24-
TARGET_DIR=$(pwd)/$EXTENSION_DIR
20+
# Move into the root directory, so this script can be called from any directory
21+
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
22+
ROOT_DIR=$SCRIPTS_DIR/../..
23+
cd $ROOT_DIR
2524

26-
rm -rf ${EXTENSION_DIR} 2>/dev/null
27-
mkdir -p $EXTENSION_DIR
25+
EXTENSION_DIR=".layers"
26+
TARGET_DIR=$(pwd)/$EXTENSION_DIR
27+
EXTENSION_PATH=$TARGET_DIR/datadog-extension-${SUFFIX}
2828

29-
cd $ROOT_DIR
30-
}
29+
mkdir -p $EXTENSION_DIR
30+
rm -rf ${EXTENSION_PATH} 2>/dev/null
3131

32+
cd $ROOT_DIR
3233

3334
docker_build() {
3435
local arch=$1
3536

3637
docker buildx build --platform linux/${arch} \
3738
-t datadog/build-extension-${SUFFIX} \
38-
-f .gitlab/scripts/Dockerfile.build_layer \
39+
-f ./images/Dockerfile.build_layer \
3940
--build-arg SUFFIX=$SUFFIX \
40-
. -o $TARGET_DIR/datadog-extension-${SUFFIX}
41+
. -o $EXTENSION_PATH
4142

42-
cp $TARGET_DIR/datadog-extension-${SUFFIX}/datadog_extension.zip $TARGET_DIR/datadog_extension-${SUFFIX}.zip
43-
unzip $TARGET_DIR/datadog-extension-${SUFFIX}/datadog_extension.zip -d $TARGET_DIR/datadog_extension-${SUFFIX}
44-
rm -rf $TARGET_DIR/datadog-extension-${SUFFIX}/
43+
cp $EXTENSION_PATH/datadog_extension.zip $TARGET_DIR/datadog_extension-${SUFFIX}.zip
44+
unzip $EXTENSION_PATH/datadog_extension.zip -d $TARGET_DIR/datadog_extension-${SUFFIX}
45+
rm -rf ${EXTENSION_PATH}
4546
}
4647

47-
prepare_folders
4848
docker_build $ARCHITECTURE

.gitlab/scripts/build_private_image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ printf "Tagging container image with version: $VERSION and latest\n"
4444

4545
docker buildx build \
4646
--platform $PLATFORM \
47-
-f .gitlab/scripts/${TARGET_IMAGE} \
47+
-f ./images/${TARGET_IMAGE} \
4848
--tag "$DOCKER_TARGET_IMAGE:${IMAGE_TAG}${SUFFIX}" \
4949
--tag "$DOCKER_TARGET_IMAGE:${VERSION}${SUFFIX}" \
5050
--push .

.gitlab/scripts/compile_bottlecap.sh

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ else
1919
printf "Alpine compile requested: ${ALPINE}\n"
2020
fi
2121

22+
if [ -z "$SUFFIX" ]; then
23+
printf "No suffix provided, using ${ARCHITECTURE}\n"
24+
SUFFIX=$ARCHITECTURE
25+
fi
2226

2327
if [ "$ALPINE" = "0" ]; then
24-
COMPILE_FILE=Dockerfile.bottlecap.compile
28+
COMPILE_IMAGE=Dockerfile.bottlecap.compile
2529
else
2630
printf "Compiling for alpine\n"
27-
COMPILE_FILE=Dockerfile.bottlecap.alpine.compile
31+
COMPILE_IMAGE=Dockerfile.bottlecap.alpine.compile
2832
fi
2933

30-
prepare_folders() {
31-
# Move into the root directory, so this script can be called from any directory
32-
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
33-
ROOT_DIR=$SCRIPTS_DIR/../..
34-
cd $ROOT_DIR
35-
36-
echo $ROOT_DIR
3734

38-
BINARY_DIR=".binaries"
39-
TARGET_DIR=$(pwd)/$BINARY_DIR
35+
# Move into the root directory, so this script can be called from any directory
36+
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
37+
ROOT_DIR=$SCRIPTS_DIR/../..
38+
cd $ROOT_DIR
4039

41-
rm -rf $BINARY_DIR 2>/dev/null
42-
mkdir -p $BINARY_DIR
40+
BINARY_DIR=".binaries"
41+
TARGET_DIR=$(pwd)/$BINARY_DIR
42+
BINARY_PATH=$TARGET_DIR/compiled-bottlecap-${SUFFIX}
4343

44-
cd $ROOT_DIR
45-
}
44+
mkdir -p $BINARY_DIR
4645

46+
cd $ROOT_DIR
4747

4848
docker_build() {
4949
local arch=$1
@@ -56,13 +56,13 @@ docker_build() {
5656

5757
docker buildx build --platform linux/${arch} \
5858
-t datadog/compile-bottlecap-${SUFFIX} \
59-
-f .gitlab/scripts/${file} \
59+
-f ./images/${file} \
6060
--build-arg PLATFORM=$PLATFORM \
61-
. -o $TARGET_DIR/compiled-bottlecap-${SUFFIX}
61+
. -o $BINARY_PATH
6262

63-
cp $TARGET_DIR/compiled-bottlecap-${SUFFIX}/bottlecap $TARGET_DIR/bottlecap-${SUFFIX}
63+
# Copy the compiled binary to the target directory with the expected name
64+
# If it already exist, it will be replaced
65+
cp $BINARY_PATH/bottlecap $TARGET_DIR/bottlecap-${SUFFIX}
6466
}
6567

66-
prepare_folders
67-
docker_build $ARCHITECTURE $COMPILE_FILE
68-
68+
docker_build $ARCHITECTURE $COMPILE_IMAGE

.gitlab/scripts/compile_go_agent.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ fi
3838

3939

4040
if [ "$ALPINE" = "0" ]; then
41-
COMPILE_FILE=Dockerfile.go_agent.compile
41+
COMPILE_IMAGE=Dockerfile.go_agent.compile
4242
else
4343
printf "Compiling for alpine\n"
44-
COMPILE_FILE=Dockerfile.go_agent.alpine.compile
44+
COMPILE_IMAGE=Dockerfile.go_agent.alpine.compile
45+
fi
46+
47+
if [ -z "$SUFFIX" ]; then
48+
printf "No suffix provided, using ${ARCHITECTURE}\n"
49+
SUFFIX=$ARCHITECTURE
4550
fi
4651

4752
# Allow override build tags
@@ -58,9 +63,7 @@ MAIN_DIR=$(pwd) # datadog-lambda-extension
5863

5964
BINARY_DIR=".binaries"
6065
TARGET_DIR=$MAIN_DIR/$BINARY_DIR
61-
62-
# Make sure the folder does not exist
63-
rm -rf $BINARY_DIR 2>/dev/null
66+
BINARY_PATH=$TARGET_DIR/compiled-datadog-agent-${SUFFIX}
6467

6568
mkdir -p $BINARY_DIR
6669

@@ -82,14 +85,15 @@ function docker_compile {
8285

8386
docker buildx build --platform linux/${arch} \
8487
-t datadog/compile-go-agent-${SUFFIX}:${VERSION} \
85-
-f ${MAIN_DIR}/.gitlab/scripts/${file} \
88+
-f ${MAIN_DIR}/images/${file} \
8689
--build-arg EXTENSION_VERSION="${VERSION}" \
8790
--build-arg AGENT_VERSION="${AGENT_VERSION}" \
8891
--build-arg BUILD_TAGS="${BUILD_TAGS}" \
89-
. -o $TARGET_DIR/compiled-datadog-agent-${SUFFIX}
92+
. -o $BINARY_PATH
9093

91-
cp $TARGET_DIR/compiled-datadog-agent-${SUFFIX}/datadog-agent $TARGET_DIR/datadog-agent-${SUFFIX}
94+
# Copy the compiled binary to the target directory with the expected name
95+
# If it already exist, it will be replaced
96+
cp $BINARY_PATH/datadog-agent $TARGET_DIR/datadog-agent-${SUFFIX}
9297
}
9398

94-
docker_compile $ARCHITECTURE $COMPILE_FILE
95-
99+
docker_compile $ARCHITECTURE $COMPILE_IMAGE

.gitlab/scripts/Dockerfile.bottlecap.alpine.compile renamed to images/Dockerfile.bottlecap.alpine.compile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM alpine:3.16 AS compiler
22
ARG PLATFORM
3+
4+
# Install dependencies
35
RUN apk add --no-cache curl gcc musl-dev make unzip bash autoconf automake libtool g++
46

57
SHELL ["/bin/bash", "-c"]
@@ -13,18 +15,21 @@ RUN curl https://sh.rustup.rs -sSf | \
1315
ENV PATH=/root/.cargo/bin:$PATH
1416
RUN rustup component add rust-src --toolchain stable-$PLATFORM-unknown-linux-musl
1517

16-
# Build Bottlecap
18+
# Copy source code
1719
RUN mkdir -p /tmp/dd
1820
COPY ./bottlecap/src /tmp/dd/bottlecap/src
1921
COPY ./bottlecap/Cargo.toml /tmp/dd/bottlecap/Cargo.toml
2022
COPY ./bottlecap/Cargo.lock /tmp/dd/bottlecap/Cargo.lock
23+
24+
# Build the binary
25+
#
2126
# Added `-C link-arg=-lgcc` for alpine.
2227
ENV RUSTFLAGS="-C panic=abort -C link-arg=-lgcc"
2328
WORKDIR /tmp/dd/bottlecap
2429
RUN --mount=type=cache,target=/root/.cargo/registry cargo +stable build --release --target $PLATFORM-unknown-linux-musl
2530
RUN cp /tmp/dd/bottlecap/target/$PLATFORM-unknown-linux-musl/release/bottlecap /tmp/dd/bottlecap/bottlecap
2631

27-
# keep the smallest possible docker image
32+
# Use the smallest image possible
2833
FROM scratch
2934
COPY --from=compiler /tmp/dd/bottlecap/bottlecap /
3035
ENTRYPOINT ["/bottlecap"]

.gitlab/scripts/Dockerfile.bottlecap.compile renamed to images/Dockerfile.bottlecap.compile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
FROM public.ecr.aws/lambda/provided:al2 AS compiler
22
ARG PLATFORM
3+
4+
# Install dependencies
35
RUN yum install -y curl gcc gcc-c++ make unzip
46

57
# Install Protocol Buffers compiler by hand, since AL2 does not have a recent enough version.
68
COPY ./scripts/install-protoc.sh /
79
RUN chmod +x /install-protoc.sh && /install-protoc.sh
10+
11+
# Install Rust Toolchain
812
RUN curl https://sh.rustup.rs -sSf | \
913
sh -s -- --profile minimal --default-toolchain stable-$PLATFORM-unknown-linux-gnu -y
1014
ENV PATH=/root/.cargo/bin:$PATH
1115
RUN rustup component add rust-src --toolchain stable-$PLATFORM-unknown-linux-gnu
16+
17+
# Copy source code
1218
RUN mkdir -p /tmp/dd
1319
COPY ./bottlecap/src /tmp/dd/bottlecap/src
1420
COPY ./bottlecap/Cargo.toml /tmp/dd/bottlecap/Cargo.toml
1521
COPY ./bottlecap/Cargo.lock /tmp/dd/bottlecap/Cargo.lock
22+
23+
# Build the binary
1624
ENV RUSTFLAGS="-C panic=abort"
1725
WORKDIR /tmp/dd/bottlecap
1826
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo +stable build --release --target $PLATFORM-unknown-linux-gnu
1927
RUN cp /tmp/dd/bottlecap/target/$PLATFORM-unknown-linux-gnu/release/bottlecap /tmp/dd/bottlecap/bottlecap
2028

21-
# keep the smallest possible docker image
29+
# Use smallest image possible
2230
FROM scratch
2331
COPY --from=compiler /tmp/dd/bottlecap/bottlecap /
2432
ENTRYPOINT ["/bottlecap"]

images/Dockerfile.bottlecap.dev

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM ubuntu:22.04 AS compresser
2+
ARG SUFFIX
3+
4+
RUN apt-get update && apt-get install -y zip binutils
5+
6+
# Copy Go Agent from last release
7+
COPY --from=public.ecr.aws/datadog/lambda-extension:latest /opt/datadog-agent-go /datadog-agent-go
8+
RUN mkdir /extensions
9+
WORKDIR /extensions
10+
11+
COPY .binaries/bottlecap-${SUFFIX} /extensions/datadog-agent
12+
COPY ./scripts/datadog_wrapper /datadog_wrapper
13+
RUN chmod +x /datadog_wrapper
14+
RUN zip -r datadog_extension.zip /extensions /datadog_wrapper /datadog-agent-go
15+
16+
# keep the smallest possible docker image
17+
FROM scratch
18+
COPY --from=compresser /extensions/datadog_extension.zip /
19+
ENTRYPOINT ["/datadog_extension.zip"]

0 commit comments

Comments
 (0)