Description
Hi DataDog Agent Team,
We need to make a small change to the datadog agent code. It's been challenging figuring out how to build a custom version of the datadog/agent Docker image. I found several conflicting sets of instructions for building for development, but none of them work for a prod image.
- https://datadoghq.dev/datadog-agent/setup/
- https://github.com/DataDog/datadog-agent/blob/7.61.0/docs/dev/agent_build.md
- https://github.com/DataDog/datadog-agent/blob/7.61.0/README.md#getting-started
- https://github.com/DataDog/datadog-agent/blob/7.61.0/docs/dev/agent_omnibus.md
- https://github.com/DataDog/datadog-agent-buildimages/blob/14a41bca/README.md
I tried manually evaluating the docker_build_agent7 GitLab CI config, through about 15 levels of inheritance and dependencies, and came up with a simple Dockerfile that will build the agent into /src/bin/agent/
.
Then I tried to use Dockerfiles/agent/Dockerfile to build the image, but it expects a datadog-agent*.tar.xz
file and I couldn't find the code that creates this file to see what goes into it.
So I tried replacing the binary in the existing image:
# Dockerfile
# This is adapted from
# https://github.com/DataDog/datadog-agent/blob/fc8851b47920afe200f134b23b890fa2173fe9aa/.gitlab/container_build/docker_linux.yml
# To build on your ARM (Apple Silicon) laptop, switch to the arm64 image.
FROM datadog/agent-buildimages-deb_x64:v53759313-14a41bca AS build
#FROM datadog/agent-buildimages-deb_arm64:v53759313-14a41bca AS build
ADD --keep-git-dir=true "https://github.com/DataDog/datadog-agent.git#7.61.0" /src
# TODO: Apply our patch.
WORKDIR /src
ENV CI_PROJECT_DIR=/src
ENV PATH=/usr/local/rvm/gems/ruby-2.7.2/bin:/usr/local/rvm/gems/ruby-2.7.2@global/bin:/usr/local/rvm/rubies/ruby-2.7.2/bin:/root/miniforge3/envs/ddpy3/bin:/root/miniforge3/condabin:/root/.cargo/bin:/opt/clang/bin:/go/bin:/usr/local/go/bin:/root/miniforge3/condabin:~/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/rvm/bin
RUN --mount=type=cache,target=/go/pkg/mod/cache inv -e agent.build
FROM datadog/agent:7.61.0
COPY --from=build /src/bin/agent/agent /opt/datadog-agent/bin/agent/agent
Unfortunately, the system does not build a statically-linked binary and the binary fails when trying to import libs on macOS ARM:
% docker build .
...
=> => writing image sha256:69119de5d5e57b9ff8140ad6d31dd276e9f134da94f27a549fdaaff9d32798bc 0.0s
...
mleonhard@Mac datadog-agent % docker run -it sha256:69119de5d5e57b9ff8140ad6d31dd276e9f134da94f27a549fdaaff9d32798bc /usr/bin/env /opt/datadog-agent/bin/agent/agent --version
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
And also fails on Linux AMD64 in our production-like environment:
agent: error while loading shared libraries: libdatadog-agent-rtloader.so.2: cannot open shared object file: No such file or directory
Would you please provide a Dockerfile that will build the agent from source to run on Linux AMD64?