Skip to content
Merged
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
82 changes: 6 additions & 76 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,87 +1,17 @@
# Build image for httpd-datadog GitLab CI.
#
# It contains:
# - LLVM 17 toolchain with musl sysroot for cross-compilation
# - musl toolchain whose binaries also run on glibc (musl-build-env, see
# https://github.com/DataDog/musl-toolchain-glibc-support)
# - httpd 2.4 source code
# - Tools necessary to build httpd and mod_datadog
# - Rust toolchain for RUM (inject-browser-sdk requires Rust 1.91+)
# - uv (fast Python package manager for tests)
#
# Toolchain files are sourced from deps/nginx-datadog/build_env/.
#
# dd-repo-tools supplies the native toolchain architecture in every supported
# entrypoint (GitLab, `make dev-image`, and VS Code initialization).
FROM alpine:3.20.3 AS sysroot

ARG LLVM_VERSION=17.0.6
ARG ARCH
ENV SYSROOT=/sysroot/${ARCH}-none-linux-musl

COPY deps/nginx-datadog/build_env/CHECKSUMS /CHECKSUMS

RUN apk --no-cache add alpine-sdk coreutils sudo bash samurai python3 linux-headers \
compiler-rt clang clang-extra-tools llvm lld wget cmake make binutils musl-dev git patchelf xz lit
RUN wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-project-${LLVM_VERSION}.src.tar.xz && \
grep -F llvm-project-${LLVM_VERSION}.src.tar.xz /CHECKSUMS | sha512sum --check && \
tar -xvf llvm-project-${LLVM_VERSION}.src.tar.xz

COPY deps/nginx-datadog/build_env/locale.h.diff /locale.h.diff
RUN cd /usr/include && patch -p0 < /locale.h.diff

COPY deps/nginx-datadog/build_env/alltypes.h.diff /alltypes.h.diff
RUN cd /usr/include && patch -p0 < /alltypes.h.diff

RUN cd llvm-project-${LLVM_VERSION}.src && mkdir -p build && cd build && \
cmake -G Ninja \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_C_FLAGS="-fno-omit-frame-pointer -D_LIBCPP_HAS_NO_C11_ALIGNED_ALLOC=1" \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_CXX_FLAGS="-fno-omit-frame-pointer -D_LIBCPP_HAS_NO_C11_ALIGNED_ALLOC=1" \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DLIBUNWIND_ENABLE_SHARED=OFF \
-DLIBUNWIND_ENABLE_STATIC=ON \
-DLIBUNWIND_USE_COMPILER_RT=ON \
-DLIBCXXABI_ENABLE_SHARED=OFF \
-DLIBCXXABI_USE_LLVM_UNWINDER=ON \
-DLIBCXXABI_ENABLE_STATIC_UNWINDER=ON \
-DLIBCXXABI_USE_COMPILER_RT=ON \
-DLIBCXX_ENABLE_SHARED=OFF \
-DLIBCXX_HAS_MUSL_LIBC=ON \
-DLIBCXX_USE_COMPILER_RT=ON \
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
-DLLVM_EXTERNAL_LIT=/usr/bin/lit ../runtimes && \
ninja -v install-unwind install-cxxabi install-cxx

RUN cd /usr/lib && ln -s gcc/*/*/ resource_dir
RUN cd /usr/lib && ln -s clang/${LLVM_VERSION%%.*}/lib/linux/libclang_rt.builtins-*.a libclang_rt.builtins.a

RUN rm -rf /llvm-project-${LLVM_VERSION}.src
RUN rm -f llvm-project-${LLVM_VERSION}.src.tar.xz

RUN mkdir -p ${SYSROOT}/usr && \
ln -s /usr/lib ${SYSROOT}/usr/ && \
ln -s /usr/include ${SYSROOT}/usr/ && \
ln -s /lib ${SYSROOT}/ && \
ln -s /usr/lib/llvm${LLVM_VERSION%%.*}/lib/clang/${LLVM_VERSION%%.*}/lib ${SYSROOT}/usr/lib/resource_dir/lib

# Select the native toolchain without storing the unused variant in a layer.
RUN --mount=type=bind,source=deps/nginx-datadog/build_env,target=/tmp/build_env,ro \
cp /tmp/build_env/Toolchain.cmake.${ARCH} ${SYSROOT}/Toolchain.cmake

# see https://github.com/llvm/llvm-project/issues/60572
RUN set -- /usr/lib/gcc/*-alpine-linux-musl/13.2.1/include && \
gcc_include=$1 && \
mv ${gcc_include}/stdatomic.h ${gcc_include}/stdatomic.h_ && \
cp /usr/lib/llvm${LLVM_VERSION%%.*}/lib/clang/${LLVM_VERSION%%.*}/include/stdatomic.h ${gcc_include}/stdatomic.h
FROM registry.datadoghq.com/musl-build-env:1.0.6@sha256:fd1ab35b2a51538623740c499606a0f6240947b509b39bd1c754d7a5ee4b8c6b

COPY deps/nginx-datadog/build_env/glibc_compat.c /sysroot/
RUN clang --sysroot ${SYSROOT}/ -fpie -O2 -fno-omit-frame-pointer \
-ggdb3 -c /sysroot/glibc_compat.c -o /tmp/glibc_compat.o && \
ar rcs ${SYSROOT}/usr/lib/libglibc_compat.a /tmp/glibc_compat.o && \
rm /tmp/glibc_compat.o
# Install Ninja build tool and clang-tidy
RUN apk add --no-cache clang-extra-tools samurai

# Install dependencies for httpd
RUN apk add --no-cache autoconf expat expat-dev gpg gpg-agent libtool pcre-dev pcre2-dev py-pip zip
Expand All @@ -103,7 +33,7 @@ COPY --from=ghcr.io/astral-sh/uv:0.9.28 /uv /usr/local/bin/uv
COPY scripts/setup-httpd.py setup-httpd.py
RUN python3 ./setup-httpd.py -o httpd 2.4.58 \
&& cd httpd \
&& ./configure --with-included-apr --prefix=$(pwd)/httpd-build --enable-mpms-shared="all" \
&& CC=clang ./configure --with-included-apr --prefix=$(pwd)/httpd-build --enable-mpms-shared="all" \
&& make -j \
&& make -j install

Expand Down
1 change: 0 additions & 1 deletion .devcontainer/context.files
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# rsync --files-from allowlist (anything COPY'd by the Dockerfile).
# Runtime-only files (bind-mounted at `docker run`) stay out of the hash.
.devcontainer/Dockerfile
deps/nginx-datadog/build_env/
scripts/setup-httpd.py
27 changes: 19 additions & 8 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ variables:
# is too slow under qemu to run any other way.
DEVCONTAINER_REPO_NAME: httpd-datadog
DEVCONTAINER_PER_ARCH: "true"
# Only build_env is hashed into the image context; nested dependencies are
# runtime/build-job inputs and do not belong in the image-builder checkout.
DEVCONTAINER_GIT_SUBMODULE_STRATEGY: normal
DEVCONTAINER_GIT_SUBMODULE_PATHS: deps/nginx-datadog
# Most jobs consume build artifacts and do not need any submodules. Build
# jobs override this with the two top-level dependencies they compile.
GIT_SUBMODULE_STRATEGY: none
Expand Down Expand Up @@ -118,14 +114,17 @@ devcontainer-ghcr-policy-check:
.test-integration-template:
stage: test
variables:
# The shared make entrypoint validates its devcontainer context inputs,
# including the nginx build_env files, before running pytest.
GIT_SUBMODULE_STRATEGY: normal
GIT_SUBMODULE_PATHS: deps/nginx-datadog
MODULE_PATH: $CI_PROJECT_DIR/artifacts/$ARCH/mod_datadog.so
script:
- make test-integration

# Check glibc compatibility on Debian (because we build on a musl-based image).
.check-module-load-template:
stage: test
image: registry.ddbuild.io/images/mirror/debian:13
script:
- test/check-module-load.sh artifacts/$ARCH/mod_datadog.so

.amd64:
image: $DEVCONTAINER_IMAGE_AMD64_CI
variables:
Expand Down Expand Up @@ -196,6 +195,16 @@ test-integration:arm64:
- .test-integration-template
- .test-arm64

check-module-load:amd64:
extends:
- .test-amd64
- .check-module-load-template

check-module-load:arm64:
extends:
- .test-arm64
- .check-module-load-template

.upload-template:
stage: aws
needs:
Expand All @@ -209,6 +218,8 @@ test-integration:arm64:
- job: "test-rum:arm64"
- job: "test-integration:amd64"
- job: "test-integration:arm64"
- job: "check-module-load:amd64"
- job: "check-module-load:arm64"
tags: ["arch:amd64"]
image: registry.ddbuild.io/images/aws-cli:2.33.12
script:
Expand Down
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
[submodule "deps/dd-trace-cpp"]
path = deps/dd-trace-cpp
url = https://github.com/DataDog/dd-trace-cpp.git
[submodule "deps/nginx-datadog"]
path = deps/nginx-datadog
url = https://github.com/DataDog/httpd-datadog.git
branch = mirror-nginx-datadog
[submodule "deps/inject-browser-sdk"]
path = deps/inject-browser-sdk
url = https://github.com/DataDog/inject-browser-sdk.git
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
DEV_CONTAINER_IMAGE_NAME := registry.ddbuild.io/ci/httpd-datadog/devcontainer
DEV_CONTAINER_PER_ARCH := true

# Fail devcontainer targets early when their toolchain input is absent.
# The shared makefile applies this guard only to relevant targets.
DEV_CONTAINER_REQUIRED_PATHS := deps/nginx-datadog/build_env/Toolchain.cmake.x86_64

include .devcontainer/devcontainer.mk

# CI supplies MODULE_PATH to reuse its architecture-specific build.
Expand All @@ -22,7 +18,7 @@ PRESET ?= ci-dev
.PHONY: ci-build
ci-build:
git config --global --add safe.directory "$(CURDIR)"
git submodule update --init --depth=1 deps/dd-trace-cpp deps/nginx-datadog
git submodule update --init --depth=1 deps/dd-trace-cpp
cmake --preset=$(PRESET) -B build .
cmake --build build -j --verbose
cmake --install build --prefix dist
Expand Down
3 changes: 3 additions & 0 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ if (HTTPD_DATADOG_ENABLE_RUM)
# mod_datadog/CMakeLists.txt references ${injectbrowsersdk_SOURCE_DIR}, which
# FetchContent used to set; replicate it for the submodule layout.
set(injectbrowsersdk_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/inject-browser-sdk" CACHE INTERNAL "")
# Drop Corrosion's -lunwind -lc: the toolchain links both, and this -lc
# would embed musl libc statically.
set(Rust_CARGO_TARGET_LINK_NATIVE_LIBS "" CACHE INTERNAL "")
add_subdirectory(inject-browser-sdk EXCLUDE_FROM_ALL)
set(INJECT_BROWSER_SDK_VERSION "${INJECT_BROWSER_SDK_VERSION}" PARENT_SCOPE)

Expand Down
1 change: 0 additions & 1 deletion deps/nginx-datadog
Submodule nginx-datadog deleted from b5bbb8
2 changes: 1 addition & 1 deletion doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
When cloning the repo, initialize the submodules you need. For a standard build:

```shell
git submodule update --init deps/dd-trace-cpp deps/nginx-datadog
git submodule update --init deps/dd-trace-cpp
```

The `deps/inject-browser-sdk` submodule is a private repository and is only required for RUM builds
Expand Down
8 changes: 4 additions & 4 deletions scripts/clang-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ if [[ ! -x "$run_clang_tidy" ]]; then
fi

git config --global --add safe.directory "$repo_root" >/dev/null 2>&1 || true
if [[ ! -f deps/dd-trace-cpp/CMakeLists.txt ]] || [[ ! -f deps/nginx-datadog/CMakeLists.txt ]]; then
git submodule update --init --depth=1 deps/dd-trace-cpp deps/nginx-datadog
if [[ ! -f deps/dd-trace-cpp/CMakeLists.txt ]]; then
git submodule update --init --depth=1 deps/dd-trace-cpp
fi

cmake --fresh --preset=ci-dev -B "$build_dir" \
Expand All @@ -71,10 +71,10 @@ for entry in json.load(open(db_path)):
if not relative_path.endswith((".c", ".cc", ".cpp", ".cxx")):
continue
command = entry.get("command") or ""
if "/sysroot" not in command:
if "-stdlib=libc++" not in command:
sys.stderr.write(
"BUILD_DIR was not configured with preset ci-dev; refusing to run tidy.\n"
" missing /sysroot in " + relative_path + "\n"
" missing -stdlib=libc++ in " + relative_path + "\n"
)
sys.exit(1)
verified_source_count += 1
Expand Down
30 changes: 30 additions & 0 deletions test/check-module-load.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

# Check that mod_datadog loads in the Apache of Debian, serves a request, and
# unloads without crashing.
#
# Usage: test/check-module-load.sh <path to mod_datadog.so>

set -eu

module_path=$(realpath "$1")
# Use a port other than 80 because other containers of the CI job may use it.
port=7777

apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends apache2 curl >/dev/null
sed -i "s/80/$port/" /etc/apache2/ports.conf /etc/apache2/sites-enabled/000-default.conf
cat >/etc/apache2/conf-enabled/datadog.conf <<EOF
LoadModule datadog_module $module_path
DatadogTracing On
EOF

# The configuration test loads and unloads the module.
apache2ctl -t
apache2ctl -DFOREGROUND &
server_pid=$!
curl --fail --silent --show-error --retry 10 --retry-connrefused --retry-delay 1 \
--output /dev/null "http://localhost:$port/"
apache2ctl -k stop
wait "$server_pid" || { echo "Apache exited with status $?" >&2; exit 1; }
echo "mod_datadog loaded, served a request, and unloaded."
Loading