-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to build custom datadog/agent
image
#33509
Comments
Alternatively, it would be helpful to know:
|
Hi, and thanks for reaching out! As you noticed, things are not easy enough when attempting to build the agent locally. TL;DR: run |
Thanks for sharing the Build failure
This builds the Datadog agent binary so it can run from the Docker image: # This is adapted from https://github.com/DataDog/datadog-agent/blob/fc8851b47920afe200f134b23b890fa2173fe9aa/.gitlab/container_build/docker_linux.yml
# Datadog does not name the images with the Docker $TARGETARCH values 'amd64' and 'arm/v7'.
# To build on an 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.
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
WORKDIR /src
# The Invoke framework builds a dynamically-linked binary which fails to import libs.
#ENV CI_PROJECT_DIR=/src
#RUN --mount=type=cache,target=/go/pkg/mod/cache inv -e agent.build
# To work around this, we build using the same command-line options used to build the released binary.
# We discovered the options by running https://github.com/sg0hsmt/gobuildinfo.git against the binary.
# Removed tag: sds, likely https://github.com/DataDog/dd-sensitive-data-scanner
# Removed tag: python, likely only needed for https://docs.datadoghq.com/integrations/python/
RUN --mount=type=cache,target=/go/pkg/mod/cache CGO_ENABLED=1 CGO_CFLAGS="-I. -I/opt/datadog-agent/embedded/include -Werror -Wno-deprecated-declarations -I/opt/datadog-agent/embedded/include" CGO_LDFLAGS="-Wl,-rpath,/opt/datadog-agent/embedded/lib -L/opt/datadog-agent/embedded/lib -L/opt/datadog-agent/embedded/lib" go build -buildmode=exe -compiler=gc -ldflags="-X github.com/DataDog/datadog-agent/pkg/version.Commit=202f54bcf5 -X github.com/DataDog/datadog-agent/pkg/version.AgentVersion=7.61.0 -X github.com/DataDog/datadog-agent/pkg/serializer.AgentPayloadVersion=v5.0.137 -X github.com/DataDog/datadog-agent/pkg/config/setup.InstallPath=/opt/datadog-agent -X github.com/DataDog/datadog-agent/pkg/config/setup.ForceDefaultPython=true -X github.com/DataDog/datadog-agent/pkg/config/setup.DefaultPython=3 -r /opt/datadog-agent/embedded/lib '-extldflags=-Wl,-z,lazy ' " -tags=systemd,etcd,cri,consul,jetson,kubelet,containerd,kubeapiserver,orchestrator,trivy,docker,jmx,ec2,datadog.no_waf,zk,podman,oracle,zstd,netcgo,gce,process,crio,zlib,bundle_agent,otlp,apm -o ./bin/agent/agent ./cmd/agent/
FROM datadog/agent:7.61.0
COPY --from=build /src/bin/agent/agent /opt/datadog-agent/bin/agent/agent |
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.
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:
Unfortunately, the system does not build a statically-linked binary and the binary fails when trying to import libs on macOS ARM:
And also fails on Linux AMD64 in our production-like environment:
Would you please provide a Dockerfile that will build the agent from source to run on Linux AMD64?
The text was updated successfully, but these errors were encountered: