Skip to content

Commit

Permalink
refactor(datadog-agent-nvml): use melange variables and remove env vars
Browse files Browse the repository at this point in the history
Signed-off-by: Massimiliano Giovagnoli <[email protected]>
  • Loading branch information
maxgio92 committed Oct 25, 2024
1 parent 19b4e22 commit 1fd3ace
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions datadog-agent-nvml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ environment:
- datadog-agent
- datadog-agent-core-integrations
- rsync
environment:
DD_HOME: / # agent being run by root expects /.
DD_SHARED: /usr/share/datadog-agent
DD_CONF: /etc/datadog-agent/conf.d

vars:
DD_HOME: / # agent being run by root expects /.
DD_SHARED: /usr/share/datadog-agent
DD_CONF: /etc/datadog-agent/conf.d

pipeline:
# This integration wheel comes from the integrations-extras repository
Expand All @@ -46,26 +47,26 @@ pipeline:
. .venv/bin/activate
# Use embedded Python in virtual environment.
sed -i "s|$(pwd)/.venv|${DD_SHARED}|g" .venv/pyvenv.cfg
sed -i "s|$(pwd)/.venv|${DD_SHARED}|g" .venv/bin/*
sed -i "s|$(pwd)/.venv|${{vars.DD_SHARED}}|g" .venv/pyvenv.cfg
sed -i "s|$(pwd)/.venv|${{vars.DD_SHARED}}|g" .venv/bin/*
# Dump plugin requirements. It's required by the `agent integration install` command.
pip freeze > "${DD_HOME}/final_constraints-py3.txt"
pip freeze > "${{vars.DD_HOME}}/final_constraints-py3.txt"
# TODO: we probably need to ship this too with the integrations-core subpackage.
cp /home/integrations-core/requirements-agent-release.txt $DD_HOME
cp /home/integrations-core/requirements-agent-release.txt ${{vars.DD_HOME}}
# It seems that the agent integration install command doesnt look for dependencies
# at PYTHONPATH, instead it does it at $DD_HOME/embedded directory in an hardcoded fashion.
ln -s $DD_SHARED $DD_HOME/embedded
# at PYTHONPATH, instead it does it at ${{vars.DD_HOME}}/embedded directory in an hardcoded fashion.
ln -s ${{vars.DD_SHARED}} ${{vars.DD_HOME}}/embedded
# Dump the packages.
mkdir site-packages
rsync -az $DD_HOME/embedded/lib/python3.11/site-packages/ ./site-packages/
rsync -az ${{vars.DD_HOME}}/embedded/lib/python3.11/site-packages/ ./site-packages/
# Dump the configurations.
mkdir conf.d
rsync -az $DD_CONF/ ./conf.d/
rsync -az ${{vars.DD_CONF}}/ ./conf.d/
# This is needed to work around the error "ValueError: ZIP does not support timestamps before 1980"
SOURCE_DATE_EPOCH=315532800
Expand All @@ -76,25 +77,25 @@ pipeline:
agent integration install datadog-nvml==1.0.9 --third-party --allow-root
# Cleanup before preparing the package content.
find $DD_SHARED -name "*.pyc" -delete
find $DD_SHARED -name "__pycache__" -exec rm -rf {} +
find ${{vars.DD_SHARED}} -name "*.pyc" -delete
find ${{vars.DD_SHARED}} -name "__pycache__" -exec rm -rf {} +
# Prepare the package content.
diff_packages=$(rsync --include='*/' --exclude='*' --ignore-existing -rv --dry-run $DD_SHARED/lib/python3.11/site-packages/ ./site-packages/ | grep -v "sending incremental file list" | grep -v -E "^\./$|^sent .+ bytes|total size|^$")
diff_conf=$(rsync --include='*/' --exclude='*' --ignore-existing -rv --dry-run $DD_CONF/ ./conf.d/ | grep -v "sending incremental file list" | grep -v -E "^\./$|^sent .+ bytes|total size|^$")
diff_packages=$(rsync --include='*/' --exclude='*' --ignore-existing -rv --dry-run ${{vars.DD_SHARED}}/lib/python3.11/site-packages/ ./site-packages/ | grep -v "sending incremental file list" | grep -v -E "^\./$|^sent .+ bytes|total size|^$")
diff_conf=$(rsync --include='*/' --exclude='*' --ignore-existing -rv --dry-run ${{vars.DD_CONF}}/ ./conf.d/ | grep -v "sending incremental file list" | grep -v -E "^\./$|^sent .+ bytes|total size|^$")
# Include the new packages.
packages_dir="${{targets.contextdir}}${DD_SHARED}/lib/python3.11/site-packages/"
packages_dir="${{targets.contextdir}}${{vars.DD_SHARED}}/lib/python3.11/site-packages/"
mkdir -p "${packages_dir}/datadog_checks"
for package in $diff_packages; do
cp -vr "${DD_SHARED}/lib/python3.11/site-packages/${package}" $packages_dir;
cp -vr "${{vars.DD_SHARED}}/lib/python3.11/site-packages/${package}" $packages_dir;
done
# Include the new configurations.
conf_dir="${{targets.destdir}}${DD_CONF}/"
conf_dir="${{targets.destdir}}${{vars.DD_CONF}}/"
mkdir -p $conf_dir
for conf in $diff_conf; do
cp -vr "${DD_CONF}/${conf}" $conf_dir;
cp -vr "${{vars.DD_CONF}}/${conf}" $conf_dir;
done
deactivate
Expand Down

0 comments on commit 1fd3ace

Please sign in to comment.