Skip to content

WIP: CLOUDP-318525: Add build_tag_id_prefix and deprecate pin_tag_at #104

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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .evergreen-functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ variables:
- PKCS11_URI
- branch_name
- build_id
- build_tag_type
- build_variant
- distro
- e2e_cloud_qa_apikey_owner_ubi_cloudqa
Expand All @@ -29,7 +30,6 @@ variables:
- otel_collector_endpoint
- otel_parent_id
- otel_trace_id
- pin_tag_at
- registry
- requester
- skip_tags
Expand Down
6 changes: 3 additions & 3 deletions .evergreen-periodic-builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
59 changes: 15 additions & 44 deletions pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down
16 changes: 16 additions & 0 deletions pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"