Skip to content

Commit

Permalink
Add process_agent.build_docker_agent task (#4627)
Browse files Browse the repository at this point in the history
Adds a process_agent.build_docker_agent which can be used to quickly build a docker image containing custom builds of the system-probe and process-agent. This is useful for in container environments.
  • Loading branch information
leeavital authored Feb 21, 2020
1 parent 2e4c5fb commit e0f199b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
43 changes: 42 additions & 1 deletion tasks/process_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import re
import shutil
import sys

import shutil
import tempfile
from invoke import task
from invoke.exceptions import Exit
from subprocess import check_output

from .utils import bin_name, get_gopath, get_build_flags, REPO_PATH, get_version, get_git_branch_name, get_go_version, get_git_commit, get_version_numeric_only
Expand Down Expand Up @@ -96,3 +98,42 @@ def build(ctx, race=False, go_version=None, incremental_build=False,
}

ctx.run(cmd.format(**args), env=env)


@task
def build_dev_image(ctx, image=None, push=False, base_image="datadog/agent:latest"):
"""
Build a dev image of the process-agent based off an existing datadog-agent image
image: the image name used to tag the image
push: if true, run a docker push on the image
base_image: base the docker image off this already build image (default: datadog/agent:latest)
"""
if image is None:
raise Exit(message="image was not specified")

with TempDir() as docker_context:
ctx.run("cp tools/ebpf/Dockerfiles/Dockerfile-process-agent-dev {to}".format(
to=docker_context + "/Dockerfile"))

ctx.run("cp bin/process-agent/process-agent {to}".format(
to=docker_context + "/process-agent"))

ctx.run("cp bin/system-probe/system-probe {to}".format(
to=docker_context + "/system-probe"))

with ctx.cd(docker_context):
ctx.run("docker build --tag {image} --build-arg AGENT_BASE={base_image} .".format(image=image, base_image=base_image))

if push:
ctx.run("docker push {image}".format(image=image))


class TempDir():
def __enter__(self):
self.fname = tempfile.mkdtemp()
print("created tempdir: {name}".format(name=self.fname))
return self.fname
def __exit__(self, exception_type, exception_value, traceback):
print("deleting tempdir: {name}".format(name=self.fname))
shutil.rmtree(self.fname)
11 changes: 11 additions & 0 deletions tools/ebpf/Dockerfiles/Dockerfile-process-agent-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG AGENT_BASE=datadog/agent:latest
FROM $AGENT_BASE

# include some useful dev tools since this will be used or development
RUN apt-get update -y && apt-get install -y jq conntrack netcat dnsutils

# inv -e process-agent.build-dev-image will set up a temporary
# build directory where this Dockerfile and the necessary binaries
# are in the same directory
COPY process-agent /opt/datadog-agent/embedded/bin/process-agent
COPY system-probe /opt/datadog-agent/embedded/bin/system-probe

0 comments on commit e0f199b

Please sign in to comment.