Skip to content

Commit 26c39b3

Browse files
[mq] [skip ddci] working branch - merge f270200 on top of main at 1241668
{"baseBranch":"main","baseCommit":"12416689cc4717225d2d3358704eda3712276f1d","createdAt":"2026-07-18T02:26:45.558760Z","headSha":"f270200622d784fcc00a05edb89a1e357b90e88b","id":"bc3551fe-ecd2-4074-80e0-0f04b4267e02","priority":"200","pullRequestNumber":"52887","queuedAt":"2026-07-18T02:26:45.557476Z","status":"STATUS_QUEUED"}
2 parents 0df1cd5 + f270200 commit 26c39b3

11 files changed

Lines changed: 129 additions & 10 deletions

omnibus/config/projects/agent.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
dependency 'datadog-agent-installer-symlinks'
240240
if do_repackage?
241241
dependency "existing-agent-package"
242+
dependency "systemd" if linux_target?
242243
dependency "datadog-agent"
243244
else
244245
dependency "package-artifact"

omnibus/config/software/datadog-agent-installer-symlinks.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
block do
1212
if linux_target? and install_dir == '/opt/datadog-agent'
13-
command "bazel run --//:install_dir=#{install_dir} -- //packages/agent/linux:install --destdir='/'",
13+
destdir = ENV["OMNIBUS_BASE_DIR"] || "/"
14+
command "bazel run --//:install_dir=#{install_dir} -- //packages/agent/linux:install --destdir='#{destdir}'",
1415
:live_stream => Omnibus.logger.live_stream(:info)
1516
project.extra_package_file "/opt/datadog-packages/datadog-agent"
1617
project.extra_package_file "/opt/datadog-packages/run"

omnibus/config/software/datadog-agent.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@
3232

3333
source path: '..',
3434
options: {
35-
exclude: ["**/.cache/**/*", "**/testdata/**/*"],
35+
exclude: [
36+
"**/.cache/**/*",
37+
"**/testdata/**/*",
38+
# Git's fsmonitor daemon creates a Unix socket that breaks builds both
39+
# on the host and in a container with a bind-mounted repo.
40+
"**/.git/fsmonitor--daemon.ipc",
41+
],
3642
}
3743
relative_path 'src/github.com/DataDog/datadog-agent'
3844

omnibus/config/software/datadog-dogstatsd.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
source path: '..',
1212
options: {
13-
exclude: ["**/.cache/**/*"],
13+
exclude: ["**/.cache/**/*", "**/.git/fsmonitor--daemon.ipc"],
1414
}
1515
relative_path 'src/github.com/DataDog/datadog-agent'
1616

omnibus/config/software/datadog-iot-agent.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
source path: '..',
1212
options: {
13-
exclude: ["**/.cache/**/*"],
13+
exclude: ["**/.cache/**/*", "**/.git/fsmonitor--daemon.ipc"],
1414
}
1515
relative_path 'src/github.com/DataDog/datadog-agent'
1616

omnibus/config/software/datadog-otel-agent.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
exclude: [
1616
"**/.cache/**/*",
1717
"**/testdata/**/*",
18+
"**/.git/fsmonitor--daemon.ipc",
1819
],
1920
}
2021
relative_path 'src/github.com/DataDog/datadog-agent'

omnibus/config/software/existing-agent-package.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
description 'A previously built artifact, unpacked'
44

5+
require 'fileutils'
6+
require 'shellwords'
7+
58
always_build true
69

710
source_url = ENV['OMNIBUS_REPACKAGE_SOURCE_URL']
@@ -11,5 +14,25 @@
1114
target_filename: target_package
1215

1316
build do
14-
command "dpkg --unpack #{target_package}"
17+
destdir = ENV["OMNIBUS_BASE_DIR"] || "/"
18+
19+
block "Prepare package extraction root" do
20+
FileUtils.mkdir_p(destdir)
21+
end
22+
23+
command "dpkg-deb -x #{Shellwords.escape(target_package)} #{Shellwords.escape(destdir)}"
24+
25+
if destdir != "/"
26+
staged_install_dir = File.join(destdir, install_dir.sub(%r{\A/+}, ""))
27+
28+
# GNU `chmod -R` skips symlinks; `FileUtils.chmod_R` with a symbolic mode stats each
29+
# entry and raises ENOENT on the package's absolute symlinks, which dangle until the
30+
# install dir is repopulated.
31+
command "chmod -R u+rwX #{Shellwords.escape(staged_install_dir)}"
32+
33+
block "Populate install directory from extracted package" do
34+
FileUtils.mkdir_p(install_dir)
35+
FileUtils.cp_r("#{staged_install_dir}/.", install_dir)
36+
end
37+
end
1538
end

omnibus/config/software/installer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
source path: '..',
1313
options: {
14-
exclude: ["**/.cache/**/*", "**/testdata/**/*"],
14+
exclude: ["**/.cache/**/*", "**/testdata/**/*", "**/.git/fsmonitor--daemon.ipc"],
1515
}
1616
relative_path 'src/github.com/DataDog/datadog-agent'
1717

omnibus/lib/project_extension.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,35 @@ def notarize_and_staple
280280

281281
Packager::PKG.prepend PackagerPKGNotarizer
282282

283+
# Repackaged builds may extract external package files under OMNIBUS_BASE_DIR
284+
# because non-root dev environments cannot write paths like /usr/bin. Keep the
285+
# declared extra_package_file path as the final package path, but source missing
286+
# absolute files from the staged root when available.
287+
module PackagerExtraPackageFileStagedRoot
288+
def copy_file(source, destination)
289+
staged_source = staged_extra_package_source(source)
290+
if staged_source != source.to_s && File.directory?(staged_source)
291+
FileUtils.cp_r(staged_source.chomp("/"), destination)
292+
else
293+
super(staged_source, destination)
294+
end
295+
end
296+
297+
private
298+
299+
def staged_extra_package_source(source)
300+
base_dir = ENV["OMNIBUS_BASE_DIR"]
301+
source = source.to_s
302+
return source if base_dir.nil? || base_dir.empty? || !source.start_with?("/")
303+
304+
staged_source = File.join(base_dir, source.sub(%r{\A/+}, ""))
305+
File.exist?(staged_source) ? staged_source : source
306+
end
307+
end
308+
309+
Packager::DEB.prepend PackagerExtraPackageFileStagedRoot
310+
Packager::RPM.prepend PackagerExtraPackageFileStagedRoot
311+
283312
# The legacy Omnibus RPM packager builds its file list by globbing the staging
284313
# tree. When Omnibus stages an external extra_package_file, it creates parent
285314
# directories in that tree as an implementation detail. Without filtering,

tasks/omnibus.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import hashlib
22
import os
33
import re
4+
import shutil
45
import subprocess
56
import sys
67
import tempfile
@@ -64,6 +65,15 @@ def omnibus_run_task(
6465
ctx.run(cmd.format(**args), env=env, replace_env=True, err_stream=sys.stdout)
6566

6667

68+
def _clear_agent_install_directory(agent_path):
69+
with os.scandir(agent_path) as entries:
70+
for entry in entries:
71+
if entry.is_dir(follow_symlinks=False):
72+
shutil.rmtree(entry.path)
73+
else:
74+
os.unlink(entry.path)
75+
76+
6777
def bundle_install_omnibus(ctx, gem_path=None, env=None, max_try=2):
6878
with ctx.cd("omnibus"):
6979
# make sure bundle install starts from a clean state
@@ -462,9 +472,7 @@ def build_repackaged_agent(ctx, log_level="info"):
462472
):
463473
raise Exit("Operation cancelled")
464474

465-
import shutil
466-
467-
shutil.rmtree("/opt/datadog-agent")
475+
_clear_agent_install_directory(agent_path)
468476

469477
architecture = ctx.run("dpkg --print-architecture", hide=True).stdout.strip()
470478

@@ -485,6 +493,10 @@ def build_repackaged_agent(ctx, log_level="info"):
485493

486494
env['OMNIBUS_REPACKAGE_SOURCE_URL'] = f"https://apt.datad0g.com/{latest_package.filename}"
487495
env['OMNIBUS_REPACKAGE_SOURCE_SHA256'] = latest_package.sha256
496+
base_dir = _resolve_omnibus_path_override(None, "OMNIBUS_BASE_DIR")
497+
if base_dir:
498+
env['OMNIBUS_BASE_DIR'] = base_dir
499+
488500
# Set up compiler flags (assumes an environment based on our glibc-targeting toolchains)
489501
if architecture == "amd64":
490502
env.update(
@@ -509,7 +521,7 @@ def build_repackaged_agent(ctx, log_level="info"):
509521
ctx,
510522
"build",
511523
"agent",
512-
base_dir=None,
524+
base_dir=base_dir,
513525
env=env,
514526
log_level=log_level,
515527
cache_dir=_resolve_omnibus_path_override(None, "OMNIBUS_CACHE_DIR"),

0 commit comments

Comments
 (0)