Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions auto_inject.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.57.1-1
39 changes: 39 additions & 0 deletions tests/test_the_test/test_installer_versions.py
Original file line number Diff line number Diff line change
@@ -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]
8 changes: 7 additions & 1 deletion utils/_context/_scenarios/docker_ssi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = (
Expand Down
11 changes: 11 additions & 0 deletions utils/installer_versions.py
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 3 additions & 0 deletions utils/scripts/ci_orchestrators/external_gitlab_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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}

Expand Down
2 changes: 2 additions & 0 deletions utils/scripts/ci_orchestrators/gitlab_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"] = []
Expand Down
2 changes: 2 additions & 0 deletions utils/virtual_machine/virtual_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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")
Expand Down
Loading