diff --git a/.evergreen-functions.yml b/.evergreen-functions.yml index 98a898321..7d54521db 100644 --- a/.evergreen-functions.yml +++ b/.evergreen-functions.yml @@ -9,6 +9,7 @@ variables: - PKCS11_URI - branch_name - build_id + - build_tag_type - build_variant - distro - e2e_cloud_qa_apikey_owner_ubi_cloudqa @@ -29,7 +30,6 @@ variables: - otel_collector_endpoint - otel_parent_id - otel_trace_id - - pin_tag_at - registry - requester - skip_tags diff --git a/.evergreen-periodic-builds.yaml b/.evergreen-periodic-builds.yaml index 1c50a283b..9fa46be77 100644 --- a/.evergreen-periodic-builds.yaml +++ b/.evergreen-periodic-builds.yaml @@ -3,9 +3,9 @@ include: - filename: .evergreen-tasks.yml parameters: - - key: pin_tag_at - value: 00:00 - description: Pin tags at this time of the day. Midnight by default. + - key: build_tag_type + value: periodic + description: The build type, this is added to the image tag. Used for periodic and release builds. variables: - &setup_group diff --git a/.evergreen.yml b/.evergreen.yml index 78e2fbf80..a141e401a 100644 --- a/.evergreen.yml +++ b/.evergreen.yml @@ -180,9 +180,9 @@ parameters: value: "true" description: set this to false to suppress retries on failure - - key: pin_tag_at - value: 10:00 - description: Pin tags at this time of the day. Midnight by default for periodic and 10 for releases. + - key: build_tag_type + value: release + description: The build type, this is added to the image tag. Used for periodic and release builds. - key: OVERRIDE_VERSION_ID value: "" diff --git a/pipeline.py b/pipeline.py index e9603c37a..be31748fa 100755 --- a/pipeline.py +++ b/pipeline.py @@ -200,62 +200,31 @@ class MissingEnvironmentVariable(Exception): pass -def should_pin_at() -> Optional[Tuple[str, str]]: - """Gets the value of the pin_tag_at to tag the images with. - - Returns its value split on :. - """ - # We need to return something so `partition` does not raise - # AttributeError - is_patch = is_running_in_patch() - - try: - pinned = os.environ["pin_tag_at"] - except KeyError: - raise MissingEnvironmentVariable(f"pin_tag_at environment variable does not exist, but is required") - if is_patch: - if pinned == "00:00": - raise Exception("Pinning to midnight during a patch is not supported. Please pin to another date!") - - hour, _, minute = pinned.partition(":") - return hour, minute - - def is_running_in_patch(): is_patch = os.environ.get("is_patch") return is_patch is not None and is_patch.lower() == "true" def build_id() -> str: - """Returns the current UTC time in ISO8601 date format. - - If running in Evergreen and `created_at` expansion is defined, use the - datetime defined in that variable instead. - - It is possible to pin this time at midnight (00:00) for periodic builds. If - running a manual build, then the Evergreen `pin_tag_at` variable needs to be - set to the empty string, in which case, the image tag suffix will correspond - to the current timestamp. - + """Returns the build id used for the image tag. + The build id is configurable `build_tag_type` and `version_id` in evergreen. """ - date = datetime.now(timezone.utc) + build_tag_type = "" try: - created_at = os.environ["created_at"] - date = datetime.strptime(created_at, "%y_%m_%d_%H_%M_%S") + build_tag_type = os.environ["build_tag_type"] except KeyError: pass - hour, minute = should_pin_at() - if hour and minute: - logger.info(f"we are pinning to, hour: {hour}, minute: {minute}") - date = date.replace(hour=int(hour), minute=int(minute), second=0) - else: - logger.warning(f"hour and minute cannot be extracted from provided pin_tag_at env, pinning to now") - - string_time = date.strftime("%Y%m%dT%H%M%SZ") + try: + version_id = os.environ["version_id"] + except KeyError: + raise MissingEnvironmentVariable("Missing environment variable `version_id`") - return string_time + if build_tag_type == "": + return version_id + else: + return f"{version_id}-{build_tag_type}" def get_release() -> Dict: @@ -744,7 +713,8 @@ def should_skip_arm64(): """ return is_running_in_evg_pipeline() and is_running_in_patch() - +# build_image_daily is always called, it is not only used for daily builds. build_image_generic calls +# build_image_daily for the release and PR builds too. def build_image_daily( image_name: str, # corresponds to the image_name in the release.json min_version: str = None, @@ -805,6 +775,7 @@ def inner(build_configuration: BuildConfiguration): args = args_for_daily_image(image_name) args["build_id"] = build_id() + # TODO: add span for build_id completed_versions = set() diff --git a/pipeline_test.py b/pipeline_test.py index 671ad105e..53cf9a540 100644 --- a/pipeline_test.py +++ b/pipeline_test.py @@ -324,3 +324,19 @@ def test_create_and_push_manifest_push_error(mock_run): assert "Error pushing manifest" in str(exc_info.value) assert mock_run.call_count == 2 # Both create and push calls + + +def test_build_id(): + from pipeline import build_id + + os.environ["version_id"] = "abcdefg" + os.environ["build_tag_type"] = "release" + id = build_id() + + assert id == "abcdefg-release" + + os.environ["version_id"] = "abcdefg" + os.environ["build_tag_type"] = "" + id = build_id() + + assert id == "abcdefg"