diff --git a/auto_inject.lock b/auto_inject.lock new file mode 100644 index 00000000000..b06f285d822 --- /dev/null +++ b/auto_inject.lock @@ -0,0 +1 @@ +0.57.1-1 diff --git a/tests/test_the_test/test_installer_versions.py b/tests/test_the_test/test_installer_versions.py new file mode 100644 index 00000000000..49675cd9248 --- /dev/null +++ b/tests/test_the_test/test_installer_versions.py @@ -0,0 +1,39 @@ +import os +from pathlib import Path + +import pytest + +from utils import installer_versions +from utils import scenarios + + +@scenarios.test_the_test +class Test_InstallerVersions: + def test_custom_library_pins_injector_from_lock(self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: + lock = tmp_path / "auto_inject.lock" + lock.write_text("pinned-version\n", encoding="utf-8") + monkeypatch.setattr(installer_versions, "AUTO_INJECT_LOCK", lock) + monkeypatch.setenv("DD_INSTALLER_LIBRARY_VERSION", "custom-library") + monkeypatch.setenv("DD_INSTALLER_INJECTOR_VERSION", "custom-injector") + + installer_versions.set_injector_version_from_lock() + + assert os.environ["DD_INSTALLER_INJECTOR_VERSION"] == "pinned-version" + + def test_default_library_does_not_set_injector(self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: + lock = tmp_path / "auto_inject.lock" + lock.write_text("pinned-version\n", encoding="utf-8") + monkeypatch.setattr(installer_versions, "AUTO_INJECT_LOCK", lock) + monkeypatch.delenv("DD_INSTALLER_LIBRARY_VERSION", raising=False) + monkeypatch.delenv("DD_INSTALLER_INJECTOR_VERSION", raising=False) + + installer_versions.set_injector_version_from_lock() + + assert "DD_INSTALLER_INJECTOR_VERSION" not in os.environ + + def test_auto_inject_lock_format(self) -> None: + contents = installer_versions.AUTO_INJECT_LOCK.read_text(encoding="utf-8") + + assert contents.endswith("\n") + assert contents.count("\n") == 1 + assert contents.strip() == contents[:-1] diff --git a/utils/_context/_scenarios/docker_ssi.py b/utils/_context/_scenarios/docker_ssi.py index fdbd539ec27..0b17185a16b 100644 --- a/utils/_context/_scenarios/docker_ssi.py +++ b/utils/_context/_scenarios/docker_ssi.py @@ -18,6 +18,7 @@ ) from utils._context.docker import get_docker_client from utils.docker_ssi.docker_ssi_matrix_utils import resolve_runtime_version +from utils.installer_versions import set_injector_version_from_lock from utils._logger import logger from utils.virtual_machine.vm_logger import vm_logger @@ -72,7 +73,12 @@ def configure(self, config: pytest.Config): self._env = "prod" if config.option.ssi_env is None or config.option.ssi_env == "prod" else "dev" self.configuration["env"] = self._env self._custom_library_version = config.option.ssi_library_version - self._custom_injector_version = config.option.ssi_injector_version + set_injector_version_from_lock() + self._custom_injector_version = ( + os.getenv("DD_INSTALLER_INJECTOR_VERSION") + if os.getenv("DD_INSTALLER_LIBRARY_VERSION") + else config.option.ssi_injector_version + ) # The runtime that we want to install on the base image. it could be empty if we don't need to install a runtime self._installable_runtime = ( diff --git a/utils/installer_versions.py b/utils/installer_versions.py new file mode 100644 index 00000000000..854982771ba --- /dev/null +++ b/utils/installer_versions.py @@ -0,0 +1,11 @@ +import os +from pathlib import Path + + +AUTO_INJECT_LOCK = Path(__file__).resolve().parents[1] / "auto_inject.lock" + + +def set_injector_version_from_lock() -> None: + """Pin the injector when testing a custom library package.""" + if os.getenv("DD_INSTALLER_LIBRARY_VERSION"): + os.environ["DD_INSTALLER_INJECTOR_VERSION"] = AUTO_INJECT_LOCK.read_text(encoding="utf-8").strip() diff --git a/utils/scripts/ci_orchestrators/external_gitlab_pipeline.py b/utils/scripts/ci_orchestrators/external_gitlab_pipeline.py index 7bfc4c11af3..29fa061990b 100644 --- a/utils/scripts/ci_orchestrators/external_gitlab_pipeline.py +++ b/utils/scripts/ci_orchestrators/external_gitlab_pipeline.py @@ -2,6 +2,7 @@ import os from utils.const import COMPONENT_GROUPS +from utils.installer_versions import set_injector_version_from_lock # List of allowed variables ALLOWED_VARIABLES = [ @@ -56,6 +57,8 @@ def main(language: str | None = None) -> None: language (str): The language to filter the pipeline for. if it's None or not a language, the pipeline will be generated for all languages """ + set_injector_version_from_lock() + # Filter environment variables new_variables = {var: os.getenv(var) for var in ALLOWED_VARIABLES if os.getenv(var) is not None} diff --git a/utils/scripts/ci_orchestrators/gitlab_exporter.py b/utils/scripts/ci_orchestrators/gitlab_exporter.py index de0810b8621..630084137c0 100644 --- a/utils/scripts/ci_orchestrators/gitlab_exporter.py +++ b/utils/scripts/ci_orchestrators/gitlab_exporter.py @@ -4,6 +4,7 @@ import json from utils._context._scenarios import get_all_scenarios from utils._context._scenarios.core import Scenario +from utils.installer_versions import set_injector_version_from_lock from utils.k8s.k8s_components_parser import K8sComponentsParser @@ -68,6 +69,7 @@ def print_gitlab_pipeline(language: str, matrix_data: dict[str, dict], ci_enviro def print_ssi_gitlab_pipeline(language: str, matrix_data: dict[str, dict], ci_environment: str) -> None: + set_injector_version_from_lock() result_pipeline = {} # type: dict result_pipeline["workflow"] = {"name": f"{language} SSI"} result_pipeline["include"] = [] diff --git a/utils/virtual_machine/virtual_machines.py b/utils/virtual_machine/virtual_machines.py index 99e89ab769c..8d3d87bcf24 100644 --- a/utils/virtual_machine/virtual_machines.py +++ b/utils/virtual_machine/virtual_machines.py @@ -5,6 +5,7 @@ import paramiko +from utils.installer_versions import set_injector_version_from_lock from utils.virtual_machine.virtual_machine_provisioner import Provision, _DeployedWeblog # The AWS AMI name is limited to 128 characters (119 usable + 9 added by AWS). @@ -21,6 +22,7 @@ def __init__(self) -> None: class DataDogConfig: def __init__(self) -> None: + set_injector_version_from_lock() self.dd_api_key = os.getenv("DD_API_KEY_ONBOARDING") self.dd_app_key = os.getenv("DD_APP_KEY_ONBOARDING") self.docker_login = os.getenv("DOCKER_LOGIN")