Skip to content
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

[CI] Artifactory for Python #14473

Merged
merged 25 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ variables:
ARTIFACTORY_TOKEN_SSM_NAME: ci.datadog-agent.artifactory_token
ARTIFACTORY_URL: datadog.jfrog.io
ARTIFACTORY_GEMS_PATH: artifactory/api/gems/agent-gems
ARTIFACTORY_PYPI_PATH: artifactory/api/pypi/agent-pypi/simple
USE_CACHING_PROXY_RUBY: "true"
USE_CACHING_PROXY_PYTHON: "true"
CLANG_LLVM_VER: 12.0.1

#
Expand Down
1 change: 1 addition & 0 deletions .gitlab/maintenance_jobs/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ delete_docker_tag:
before_script:
- DOCKER_REGISTRY_LOGIN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.$DOCKER_REGISTRY_LOGIN_SSM_KEY --with-decryption --query "Parameter.Value" --out text)
- PASS=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.$DOCKER_REGISTRY_PWD_SSM_KEY --with-decryption --query "Parameter.Value" --out text)
- !reference [.setup_python_mirror_linux]
- python3 -m pip install -r requirements.txt
- |
export DOCKER_TOKEN=`curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'$DOCKER_REGISTRY_LOGIN'", "password": "'$PASS'"}' https://hub.docker.com/v2/users/login/ | python -c 'import sys, json; print(json.load(sys.stdin)["token"].strip())'`
Expand Down
2 changes: 2 additions & 0 deletions .gitlab/notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ notify:
script:
- set +x
- export GITLAB_TOKEN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.gitlab_read_api_token --with-decryption --query "Parameter.Value" --out text)
- !reference [.setup_python_mirror_linux]
- python3 -m pip install -r tasks/libs/requirements-notifications.txt
- |
# Do not send notifications if this is a child pipeline of another repo
Expand All @@ -51,5 +52,6 @@ send_pipeline_stats:
- set +x
- export GITLAB_TOKEN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.gitlab_read_api_token --with-decryption --query "Parameter.Value" --out text)
- export DD_API_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.datadog_api_key_org2 --with-decryption --query "Parameter.Value" --out text)
- !reference [.setup_python_mirror_linux]
- python3 -m pip install -r tasks/libs/requirements-stats.txt
- invoke -e pipeline.send-stats
2 changes: 2 additions & 0 deletions .gitlab/package_build/deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
script:
- echo "About to build for $RELEASE_VERSION"
- !reference [.setup_ruby_mirror_linux]
- !reference [.setup_python_mirror_linux]
- !reference [.retrieve_linux_go_deps]
# remove artifacts from previous pipelines that may come from the cache
- rm -rf $OMNIBUS_PACKAGE_DIR/*
Expand Down Expand Up @@ -131,6 +132,7 @@ agent_deb-arm64-a7:
.iot_agent_build_common_deb:
script:
- !reference [.setup_ruby_mirror_linux]
- !reference [.setup_python_mirror_linux]
- !reference [.retrieve_linux_go_deps]
- echo "About to build for $RELEASE_VERSION_7"
- echo "Detected host architecture $(uname -m)"
Expand Down
1 change: 1 addition & 0 deletions .gitlab/package_build/dmg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- export GITHUB_KEY_B64=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.macos_github_key_b64 --with-decryption --query "Parameter.Value" --out text)
- export GITHUB_APP_ID=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.macos_github_app_id --with-decryption --query "Parameter.Value" --out text)
- export GITHUB_INSTALLATION_ID=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.macos_github_installation_id --with-decryption --query "Parameter.Value" --out text)
- !reference [.setup_python_mirror_linux]
- python3 -m pip install -r tasks/libs/requirements-github.txt
- inv -e github.trigger-macos-build --datadog-agent-ref "$CI_COMMIT_SHA" --release-version "$RELEASE_VERSION" --major-version "$AGENT_MAJOR_VERSION" --python-runtimes "$PYTHON_RUNTIMES" --destination "$OMNIBUS_PACKAGE_DIR"
- !reference [.upload_sbom_artifacts]
Expand Down
2 changes: 2 additions & 0 deletions .gitlab/package_build/rpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
script:
- echo "About to build for $RELEASE_VERSION"
- !reference [.setup_ruby_mirror_linux]
- !reference [.setup_python_mirror_linux]
- !reference [.retrieve_linux_go_deps]
# remove artifacts from previous pipelines that may come from the cache
- rm -rf $OMNIBUS_PACKAGE_DIR/*
Expand Down Expand Up @@ -124,6 +125,7 @@ agent_rpm-arm64-a7:
script:
- echo "About to build iot agent for $RELEASE_VERSION_7"
- !reference [.setup_ruby_mirror_linux]
- !reference [.setup_python_mirror_linux]
- !reference [.retrieve_linux_go_deps]
- echo "Detected host architecture $(uname -m)"
# $DD_TARGET_ARCH is only set by Arm build images, so assume amd64 if not present
Expand Down
2 changes: 2 additions & 0 deletions .gitlab/package_build/suse_rpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
script:
- echo "About to build for $RELEASE_VERSION"
- !reference [.setup_ruby_mirror_linux]
- !reference [.setup_python_mirror_linux]
- !reference [.retrieve_linux_go_deps]
# remove artifacts from previous pipelines that may come from the cache
- rm -rf $OMNIBUS_PACKAGE_DIR_SUSE/*
Expand Down Expand Up @@ -100,6 +101,7 @@ iot_agent_suse-x64:
script:
- echo "About to build iot agent for $RELEASE_VERSION_7"
- !reference [.setup_ruby_mirror_linux]
- !reference [.setup_python_mirror_linux]
- !reference [.retrieve_linux_go_deps]
- echo "Detected host architecture $(uname -m)"
# $DD_TARGET_ARCH is only set by Arm build images, so assume amd64 if not present
Expand Down
6 changes: 4 additions & 2 deletions .gitlab/package_build/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
- mkdir omnibus\pkg
- $vcpkgBlobSaSUrl = (aws ssm get-parameter --region us-east-1 --name ci.datadog-agent-buildimages.vcpkg_blob_sas_url --with-decryption --query "Parameter.Value" --out text)
- !reference [.setup_ruby_mirror_win]
- docker run --rm -m 4096M -v "$(Get-Location):c:\mnt" -e CI_JOB_ID=${CI_JOB_ID} -e CI_PIPELINE_ID=${CI_PIPELINE_ID} -e CI_COMMIT_BRANCH=${CI_COMMIT_BRANCH} -e OMNIBUS_TARGET=${OMNIBUS_TARGET} -e WINDOWS_BUILDER=true -e RELEASE_VERSION="$RELEASE_VERSION" -e MAJOR_VERSION="$AGENT_MAJOR_VERSION" -e PY_RUNTIMES="$PYTHON_RUNTIMES" -e INTEGRATIONS_CORE_VERSION="$INTEGRATIONS_CORE_VERSION" -e GOMODCACHE="c:\modcache" -e AWS_NETWORKING=true -e SIGN_WINDOWS=true -e TARGET_ARCH="$ARCH" -e DEBUG_CUSTOMACTION="$DEBUG_CUSTOMACTION" -e BUCKET_BRANCH="$BUCKET_BRANCH" -e S3_OMNIBUS_CACHE_BUCKET="$S3_OMNIBUS_CACHE_BUCKET" -e USE_S3_CACHING="$USE_S3_CACHING" -e INTEGRATION_WHEELS_CACHE_BUCKET="$INTEGRATION_WHEELS_CACHE_BUCKET" -e VCPKG_BINARY_SOURCES="clear;x-azblob,${vcpkgBlobSaSUrl}" -e GO_VERSION_CHECK="true" -e BUNDLE_MIRROR__RUBYGEMS__ORG=${BUNDLE_MIRROR__RUBYGEMS__ORG} 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-agent-buildimages/windows_1809_${ARCH}:${Env:DATADOG_AGENT_WINBUILDIMAGES} c:\mnt\tasks\winbuildscripts\buildwin.bat
- !reference [.setup_python_mirror_win]
- docker run --rm -m 4096M -v "$(Get-Location):c:\mnt" -e CI_JOB_ID=${CI_JOB_ID} -e CI_PIPELINE_ID=${CI_PIPELINE_ID} -e CI_COMMIT_BRANCH=${CI_COMMIT_BRANCH} -e OMNIBUS_TARGET=${OMNIBUS_TARGET} -e WINDOWS_BUILDER=true -e RELEASE_VERSION="$RELEASE_VERSION" -e MAJOR_VERSION="$AGENT_MAJOR_VERSION" -e PY_RUNTIMES="$PYTHON_RUNTIMES" -e INTEGRATIONS_CORE_VERSION="$INTEGRATIONS_CORE_VERSION" -e GOMODCACHE="c:\modcache" -e AWS_NETWORKING=true -e SIGN_WINDOWS=true -e TARGET_ARCH="$ARCH" -e DEBUG_CUSTOMACTION="$DEBUG_CUSTOMACTION" -e BUCKET_BRANCH="$BUCKET_BRANCH" -e S3_OMNIBUS_CACHE_BUCKET="$S3_OMNIBUS_CACHE_BUCKET" -e USE_S3_CACHING="$USE_S3_CACHING" -e INTEGRATION_WHEELS_CACHE_BUCKET="$INTEGRATION_WHEELS_CACHE_BUCKET" -e VCPKG_BINARY_SOURCES="clear;x-azblob,${vcpkgBlobSaSUrl}" -e GO_VERSION_CHECK="true" -e BUNDLE_MIRROR__RUBYGEMS__ORG=${BUNDLE_MIRROR__RUBYGEMS__ORG} -e PIP_INDEX_URL=${PIP_INDEX_URL} 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-agent-buildimages/windows_1809_${ARCH}:${Env:DATADOG_AGENT_WINBUILDIMAGES} c:\mnt\tasks\winbuildscripts\buildwin.bat
- If ($lastExitCode -ne "0") { throw "Previous command returned $lastExitCode" }
- get-childitem omnibus\pkg
- !reference [.upload_sbom_artifacts_windows]
Expand Down Expand Up @@ -68,7 +69,8 @@ windows_zip_agent_binaries_x64-a7:
- if (Test-Path omnibus\pkg) { remove-item -recurse -force omnibus\pkg }
- mkdir omnibus\pkg
- !reference [.setup_ruby_mirror_win]
- docker run --rm -m 4096M -v "$(Get-Location):c:\mnt" -e CI_COMMIT_BRANCH=${CI_COMMIT_BRANCH} -e OMNIBUS_TARGET=${OMNIBUS_TARGET} -e WINDOWS_BUILDER=true -e RELEASE_VERSION="$RELEASE_VERSION" -e MAJOR_VERSION="$AGENT_MAJOR_VERSION" -e INTEGRATIONS_CORE_VERSION="$INTEGRATIONS_CORE_VERSION" -e PY_RUNTIMES="$PYTHON_RUNTIMES" -e GOMODCACHE="c:\modcache" -e AWS_NETWORKING=true -e SIGN_WINDOWS=true -e BUCKET_BRANCH="$BUCKET_BRANCH" -e INTEGRATION_WHEELS_CACHE_BUCKET="$INTEGRATION_WHEELS_CACHE_BUCKET" -e S3_OMNIBUS_CACHE_BUCKET="$S3_OMNIBUS_CACHE_BUCKET" -e USE_S3_CACHING="$USE_S3_CACHING" -e VCPKG_BINARY_SOURCES="clear;x-azblob,${vcpkgBlobSaSUrl}" -e BUNDLE_MIRROR__RUBYGEMS__ORG=${BUNDLE_MIRROR__RUBYGEMS__ORG} 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-agent-buildimages/windows_1809_${ARCH}:${Env:DATADOG_AGENT_WINBUILDIMAGES} c:\mnt\tasks\winbuildscripts\buildwin.bat
- !reference [.setup_python_mirror_win]
- docker run --rm -m 4096M -v "$(Get-Location):c:\mnt" -e CI_COMMIT_BRANCH=${CI_COMMIT_BRANCH} -e OMNIBUS_TARGET=${OMNIBUS_TARGET} -e WINDOWS_BUILDER=true -e RELEASE_VERSION="$RELEASE_VERSION" -e MAJOR_VERSION="$AGENT_MAJOR_VERSION" -e INTEGRATIONS_CORE_VERSION="$INTEGRATIONS_CORE_VERSION" -e PY_RUNTIMES="$PYTHON_RUNTIMES" -e GOMODCACHE="c:\modcache" -e AWS_NETWORKING=true -e SIGN_WINDOWS=true -e BUCKET_BRANCH="$BUCKET_BRANCH" -e INTEGRATION_WHEELS_CACHE_BUCKET="$INTEGRATION_WHEELS_CACHE_BUCKET" -e S3_OMNIBUS_CACHE_BUCKET="$S3_OMNIBUS_CACHE_BUCKET" -e USE_S3_CACHING="$USE_S3_CACHING" -e VCPKG_BINARY_SOURCES="clear;x-azblob,${vcpkgBlobSaSUrl}" -e BUNDLE_MIRROR__RUBYGEMS__ORG=${BUNDLE_MIRROR__RUBYGEMS__ORG} -e PIP_INDEX_URL=${PIP_INDEX_URL} 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-agent-buildimages/windows_1809_${ARCH}:${Env:DATADOG_AGENT_WINBUILDIMAGES} c:\mnt\tasks\winbuildscripts\buildwin.bat
- If ($lastExitCode -ne "0") { throw "Previous command returned $lastExitCode" }
- get-childitem omnibus\pkg
- !reference [.upload_sbom_artifacts_windows]
Expand Down
10 changes: 10 additions & 0 deletions .gitlab/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@
.setup_ruby_mirror_win:
- *get_artifactory_token_win
- if ($Env:USE_CACHING_PROXY_RUBY -eq "true") { $BUNDLE_MIRROR__RUBYGEMS__ORG="https://${Env:ARTIFACTORY_USERNAME}:${ARTIFACTORY_TOKEN}@${Env:ARTIFACTORY_URL}/${Env:ARTIFACTORY_GEMS_PATH}" }

.setup_python_mirror_linux:
- set +x
- *get_artifactory_token_linux
- if [ "${USE_CACHING_PROXY_PYTHON}" = "true" ]; then export PIP_INDEX_URL=https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_TOKEN}@${ARTIFACTORY_URL}/${ARTIFACTORY_PYPI_PATH}; fi
- set -x

.setup_python_mirror_win:
- *get_artifactory_token_win
- if ($Env:USE_CACHING_PROXY_PYTHON -eq "true") { $PIP_INDEX_URL="https://${Env:ARTIFACTORY_USERNAME}:${ARTIFACTORY_TOKEN}@${Env:ARTIFACTORY_URL}/${Env:ARTIFACTORY_PYPI_PATH}" }
1 change: 1 addition & 0 deletions .gitlab/source_test/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tests_macos:
- export GITHUB_KEY_B64=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.macos_github_key_b64 --with-decryption --query "Parameter.Value" --out text)
- export GITHUB_APP_ID=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.macos_github_app_id --with-decryption --query "Parameter.Value" --out text)
- export GITHUB_INSTALLATION_ID=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.macos_github_installation_id --with-decryption --query "Parameter.Value" --out text)
- !reference [.setup_python_mirror_linux]
- python3 -m pip install -r tasks/libs/requirements-github.txt
- inv -e github.trigger-macos-test --datadog-agent-ref "$CI_COMMIT_SHA" --python-runtimes "$PYTHON_RUNTIMES"
artifacts:
Expand Down
19 changes: 14 additions & 5 deletions omnibus/config/software/datadog-agent-integrations-py2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@
python = "#{install_dir}/embedded/bin/python2"
end

# If a python_mirror was set, it's passed through a pip config file so that we're not leaking the API key in the CI Output
# Else the pip config file so pip will act casually
pip_config_file = ENV['PIP_CONFIG_FILE']
pre_build_env = {
"PIP_CONFIG_FILE" => "#{pip_config_file}"
}

# Install the checks along with their dependencies
block do
if windows?
Expand All @@ -133,14 +140,15 @@
# Prepare the build env, these dependencies are only needed to build and
# install the core integrations.
#
command "#{pip} download --dest #{build_deps_dir} hatchling==0.25.1"
command "#{pip} download --dest #{build_deps_dir} setuptools==40.9.0" # Version from ./setuptools2.rb
command "#{pip} install wheel==0.34.1"
command "#{pip} install setuptools-scm==5.0.2" # Pin to the last version that supports Python 2
command "#{pip} install pip-tools==5.4.0"
command "#{pip} download --dest #{build_deps_dir} hatchling==0.25.1", :env => pre_build_env
command "#{pip} download --dest #{build_deps_dir} setuptools==40.9.0", :env => pre_build_env # Version from ./setuptools2.rb
command "#{pip} install wheel==0.34.1", :env => pre_build_env
command "#{pip} install setuptools-scm==5.0.2", :env => pre_build_env # Pin to the last version that supports Python 2
command "#{pip} install pip-tools==5.4.0", :env => pre_build_env
uninstall_buildtime_deps = ['rtloader', 'click', 'first', 'pip-tools']
nix_build_env = {
"PIP_FIND_LINKS" => "#{build_deps_dir}",
"PIP_CONFIG_FILE" => "#{pip_config_file}",
"CFLAGS" => "-I#{install_dir}/embedded/include -I/opt/mqm/inc",
"CXXFLAGS" => "-I#{install_dir}/embedded/include -I/opt/mqm/inc",
"LDFLAGS" => "-L#{install_dir}/embedded/lib -L/opt/mqm/lib64 -L/opt/mqm/lib",
Expand All @@ -149,6 +157,7 @@
}
win_build_env = {
"PIP_FIND_LINKS" => "#{build_deps_dir}",
"PIP_CONFIG_FILE" => "#{pip_config_file}",
}
# Some libraries (looking at you, aerospike-client-python) need EXT_CFLAGS instead of CFLAGS.
specific_build_env = {
Expand Down
17 changes: 13 additions & 4 deletions omnibus/config/software/datadog-agent-integrations-py3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@
python = "#{install_dir}/embedded/bin/python3"
end

# If a python_mirror was set, it's passed through a pip config file so that we're not leaking the API key in the CI Output
# Else the pip config file so pip will act casually
pip_config_file = ENV['PIP_CONFIG_FILE']
pre_build_env = {
"PIP_CONFIG_FILE" => "#{pip_config_file}"
}

# Install the checks along with their dependencies
block do
if windows?
Expand All @@ -138,13 +145,14 @@
# Prepare the build env, these dependencies are only needed to build and
# install the core integrations.
#
command "#{pip} download --dest #{build_deps_dir} hatchling==0.25.1"
command "#{pip} download --dest #{build_deps_dir} setuptools==40.9.0" # Version from ./setuptools3.rb
command "#{pip} install wheel==0.34.1"
command "#{pip} install pip-tools==6.4.0"
command "#{pip} download --dest #{build_deps_dir} hatchling==0.25.1", :env => pre_build_env
command "#{pip} download --dest #{build_deps_dir} setuptools==40.9.0", :env => pre_build_env # Version from ./setuptools3.rb
command "#{pip} install wheel==0.34.1", :env => pre_build_env
command "#{pip} install pip-tools==6.4.0", :env => pre_build_env
uninstall_buildtime_deps = ['rtloader', 'click', 'first', 'pip-tools']
nix_build_env = {
"PIP_FIND_LINKS" => "#{build_deps_dir}",
"PIP_CONFIG_FILE" => "#{pip_config_file}",
# Specify C99 standard explicitly to avoid issues while building some
# wheels (eg. ddtrace)
"CFLAGS" => "-I#{install_dir}/embedded/include -I/opt/mqm/inc",
Expand All @@ -155,6 +163,7 @@
}
win_build_env = {
"PIP_FIND_LINKS" => "#{build_deps_dir}",
"PIP_CONFIG_FILE" => "#{pip_config_file}",
}
# Some libraries (looking at you, aerospike-client-python) need EXT_CFLAGS instead of CFLAGS.
specific_build_env = {
Expand Down
15 changes: 11 additions & 4 deletions omnibus/config/software/pylint2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@
python2 = "#{install_dir}/embedded/bin/python2"
end

# If a python_mirror was set, it's passed through a pip config file so that we're not leaking the API key in the CI Output
# Else the pip config file so pip will act casually
pip_config_file = ENV['PIP_CONFIG_FILE']
build_env = {
"PIP_CONFIG_FILE" => "#{pip_config_file}"
}

# pin 2 dependencies of pylint:
# - configparser: later versions (up to v3.7.1) are broken
# - lazy-object-proxy 1.7.0 broken on python 2 https://github.com/ionelmc/python-lazy-object-proxy/issues/61
if windows?
command "#{python2} -m pip install configparser==3.5.0 lazy-object-proxy==1.6.0"
command "#{python2} -m pip install pylint==#{version}"
command "#{python2} -m pip install configparser==3.5.0 lazy-object-proxy==1.6.0", :env => build_env
command "#{python2} -m pip install pylint==#{version}", :env => build_env
else
command "#{pip2} install configparser==3.5.0 lazy-object-proxy==1.6.0"
command "#{pip2} install pylint==#{version}"
command "#{pip2} install configparser==3.5.0 lazy-object-proxy==1.6.0", :env => build_env
command "#{pip2} install pylint==#{version}", :env => build_env
end
end
22 changes: 22 additions & 0 deletions tasks/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def get_omnibus_env(
nikos_path=None,
go_mod_cache=None,
flavor=AgentFlavor.base,
pip_config_file="pip.conf",
):
env = load_release_versions(ctx, release_version)

Expand Down Expand Up @@ -401,6 +402,11 @@ def get_omnibus_env(
)
env['MAJOR_VERSION'] = major_version
env['PY_RUNTIMES'] = python_runtimes

# Since omnibus and the invoke task won't run in the same folder
# we need to input the absolute path of the pip config file
env['PIP_CONFIG_FILE'] = os.path.abspath(pip_config_file)

if system_probe_bin:
env['SYSTEM_PROBE_BIN'] = system_probe_bin
if nikos_path:
Expand Down Expand Up @@ -480,6 +486,8 @@ def omnibus_build(
system_probe_bin=None,
nikos_path=None,
go_mod_cache=None,
python_mirror=None,
pip_config_file="pip.conf",
):
"""
Build the Agent packages with Omnibus Installer.
Expand Down Expand Up @@ -513,6 +521,7 @@ def omnibus_build(
nikos_path=nikos_path,
go_mod_cache=go_mod_cache,
flavor=flavor,
pip_config_file=pip_config_file,
)

target_project = "agent"
Expand All @@ -521,6 +530,16 @@ def omnibus_build(
elif agent_binaries:
target_project = "agent-binaries"

# Getting the python_mirror through the env variables if it wasn't pass through the args
python_mirror = python_mirror or os.environ.get("PIP_INDEX_URL")

# If a python_mirror is set then use it for pip by adding it in the pip.conf file
pip_index_url = f"[global]\nindex-url = {python_mirror}" if python_mirror else ""

# We're passing the --index-url arg through a pip.conf file so that omnibus doesn't leak the API key
with open(pip_config_file, 'w') as f:
f.write(pip_index_url)

bundle_start = datetime.datetime.now()
bundle_install_omnibus(ctx, gem_path, env)
bundle_done = datetime.datetime.now()
Expand All @@ -539,6 +558,9 @@ def omnibus_build(
omnibus_done = datetime.datetime.now()
omnibus_elapsed = omnibus_done - omnibus_start

# Now that the build is done we can delete the pip.conf file to hide the API key
os.remove(pip_config_file)

print("Build component timing:")
if not skip_deps:
print(f"Deps: {deps_elapsed}")
Expand Down