Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ scripts/.cache
scripts/.src
reports.log
__pycache__
integration_tests/recorder/target
local_tests/logs.txt
local_tests/META_INF
local_tests/python
Expand Down
47 changes: 47 additions & 0 deletions .gitlab/scripts/build_recorder_layer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2024 Datadog, Inc.

set -e

if [ -z "$ARCHITECTURE" ]; then
printf "[ERROR]: ARCHITECTURE not specified\n"
exit 1
fi

if [ -z "$FILE_SUFFIX" ]; then
printf "[WARNING] No FILE_SUFFIX provided, using ${ARCHITECTURE}\n"
FILE_SUFFIX=$ARCHITECTURE
fi

# Move into the root directory, so this script can be called from any directory
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT_DIR=$SCRIPTS_DIR/../..
cd $ROOT_DIR

EXTENSION_DIR=".layers"
TARGET_DIR=$(pwd)/$EXTENSION_DIR
EXTENSION_PATH=$TARGET_DIR/datadog_recorder-${FILE_SUFFIX}

mkdir -p $EXTENSION_DIR
rm -rf ${EXTENSION_PATH} 2>/dev/null

cd $ROOT_DIR

docker_build() {
local arch=$1

docker buildx build --platform linux/${arch} \
-t datadog/build-extension-${FILE_SUFFIX} \
-f ./images/Dockerfile.recorder.layer \
--build-arg FILE_SUFFIX=$FILE_SUFFIX \
. -o $EXTENSION_PATH

cp $EXTENSION_PATH/datadog_recorder.zip $TARGET_DIR/datadog_recorder-${FILE_SUFFIX}.zip
unzip $EXTENSION_PATH/datadog_recorder.zip -d $TARGET_DIR/datadog_recorder-${FILE_SUFFIX}
}

docker_build $ARCHITECTURE
76 changes: 76 additions & 0 deletions .gitlab/scripts/compile_recorder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2024 Datadog, Inc.

set -e

if [ -z "$ARCHITECTURE" ]; then
printf "[ERROR]: ARCHITECTURE not specified\n"
exit 1
fi

if [ -z "$FILE_SUFFIX" ]; then
printf "[WARNING] No FILE_SUFFIX provided, using ${ARCHITECTURE}\n"
FILE_SUFFIX=$ARCHITECTURE
fi

if [ -z "$ALPINE" ]; then
printf "[ERROR]: ALPINE not specified\n"
exit 1
else
printf "Alpine compile requested: ${ALPINE}\n"
fi

if [ -z "$FIPS" ]; then
printf "[ERROR]: FIPS not specified\n"
exit 1
else
printf "Fips compile requested: ${FIPS}\n"
fi

if [ "$ALPINE" = "0" ]; then
COMPILE_IMAGE=Dockerfile.recorder.compile
else
exit 1
fi


# Move into the root directory, so this script can be called from any directory
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT_DIR=$SCRIPTS_DIR/../..
cd $ROOT_DIR

BINARY_DIR=".binaries"
TARGET_DIR=$(pwd)/$BINARY_DIR
BINARY_PATH=$TARGET_DIR/compiled-recorder-$FILE_SUFFIX

mkdir -p $BINARY_DIR

cd $ROOT_DIR

docker_build() {
local arch=$1
local file=$2
if [ "$arch" == "amd64" ]; then
PLATFORM="x86_64"
else
PLATFORM="aarch64"
fi

docker buildx build --platform linux/${arch} \
--progress plain \
-t datadog/compile-recorder \
-f ./images/${file} \
--build-arg PLATFORM=$PLATFORM \
--build-arg FIPS="${FIPS}" \
. -o $BINARY_PATH

# Copy the compiled binary to the target directory with the expected name
# If it already exist, it will be replaced
cp $BINARY_PATH/recorder $TARGET_DIR/recorder-$FILE_SUFFIX
}

docker_build $ARCHITECTURE $COMPILE_IMAGE
36 changes: 36 additions & 0 deletions images/Dockerfile.recorder.compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM public.ecr.aws/lambda/provided:al2 AS compiler
ARG PLATFORM

ARG FIPS

# Install dependencies
RUN --mount=type=cache,target=/var/cache/yum \
yum install -y clang cmake3 compiler-rt curl go make perl unzip

COPY ./scripts/install-protoc.sh /
RUN chmod +x /install-protoc.sh && /install-protoc.sh

# Install Rust Toolchain
RUN curl https://sh.rustup.rs -sSf | \
sh -s -- --profile minimal \
--default-host "${PLATFORM}-unknown-linux-gnu" \
--default-toolchain "stable-${PLATFORM}-unknown-linux-gnu" \
--component rust-src \
-y
ENV PATH="${PATH}:/root/.cargo/bin"

ENV RUSTFLAGS="-Cpanic=abort"

WORKDIR /tmp/dd/integration_tests/recorder
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=bind,source=.,target=/tmp/dd,rw \
--mount=type=cache,target=/tmp/dd/integration_tests/recorder/target \
cargo +stable build --verbose --locked --no-default-features --release && \
mkdir -p /tmp/out && cp "/tmp/dd/integration_tests/recorder/target/release/recorder" /tmp/out/recorder

# Use smallest image possible
FROM scratch
COPY --from=compiler /tmp/out/recorder /
ENTRYPOINT ["/recorder"]

22 changes: 22 additions & 0 deletions images/Dockerfile.recorder.layer
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM registry.ddbuild.io/images/mirror/ubuntu:22.04 AS compresser
ARG FILE_SUFFIX

# Install dependencies
RUN apt-get update
RUN apt-get install -y zip binutils wget tar xz-utils


RUN mkdir /extensions
WORKDIR /extensions

# Copy Rust Agent binary
COPY .binaries/recorder-$FILE_SUFFIX /extensions/datadog-recorder

# Zip all binaries together
RUN zip -r datadog_recorder.zip /extensions /datadog-recorder

# Use smallest image possible
FROM scratch
COPY --from=compresser /extensions/datadog_recorder.zip /
ENTRYPOINT ["/datadog_recorder.zip"]

Loading
Loading