Skip to content

Commit 2b4a42f

Browse files
committed
Use version_id instead of datetime
1 parent 16de7c4 commit 2b4a42f

File tree

5 files changed

+25
-64
lines changed

5 files changed

+25
-64
lines changed

.evergreen-functions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ variables:
99
- PKCS11_URI
1010
- branch_name
1111
- build_id
12+
- build_tag_type
1213
- build_variant
1314
- distro
1415
- e2e_cloud_qa_apikey_owner_ubi_cloudqa
@@ -29,7 +30,6 @@ variables:
2930
- otel_collector_endpoint
3031
- otel_parent_id
3132
- otel_trace_id
32-
- build_tag_type
3333
- registry
3434
- requester
3535
- skip_tags

.evergreen-periodic-builds.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ include:
33
- filename: .evergreen-tasks.yml
44

55
parameters:
6-
# Deprecated: do not use pin_tag_at parameter, this was used to pin the image tag to a specific time,
7-
# but resulted in overwritten image tags which causes quay to garbage collect
8-
# untagged images. This caused a release image to be missing.
9-
- key: pin_tag_at
10-
value: 00:00
11-
description: Pin tags at this time of the day. Midnight by default.
12-
136
- key: build_tag_type
147
value: periodic
158
description: The build type, this is added to the image tag. Used for periodic and release builds.

.evergreen.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,6 @@ parameters:
167167
value: "true"
168168
description: set this to false to suppress retries on failure
169169

170-
# Deprecated: do not use pin_tag_at parameter, this was used to pin the image tag to a specific time,
171-
# but resulted in overwritten image tags which causes quay to garbage collect
172-
# untagged images. This caused a release image to be missing.
173-
- key: pin_tag_at
174-
value: 10:00
175-
description: Pin tags at this time of the day. Midnight by default for periodic and 10 for releases.
176-
177170
- key: build_tag_type
178171
value: release
179172
description: The build type, this is added to the image tag. Used for periodic and release builds.

pipeline.py

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -199,72 +199,32 @@ def is_running_in_evg_pipeline():
199199
class MissingEnvironmentVariable(Exception):
200200
pass
201201

202-
203-
# Deprecated: do not use pin_tag_at parameter, this was used to pin the image tag to a specific time,
204-
# but resulted in overwritten image tags which causes quay to garbage collect
205-
# untagged images. This caused a release image to be missing.
206-
def should_pin_at() -> Optional[Tuple[str, str]]:
207-
"""Gets the value of the pin_tag_at to tag the images with.
208-
209-
Returns its value split on :.
210-
"""
211-
# We need to return something so `partition` does not raise
212-
# AttributeError
213-
is_patch = is_running_in_patch()
214-
215-
try:
216-
pinned = os.environ["pin_tag_at"]
217-
except KeyError:
218-
raise MissingEnvironmentVariable(f"pin_tag_at environment variable does not exist, but is required")
219-
if is_patch:
220-
if pinned == "00:00":
221-
raise Exception("Pinning to midnight during a patch is not supported. Please pin to another date!")
222-
223-
hour, _, minute = pinned.partition(":")
224-
return hour, minute
225-
226-
227202
def is_running_in_patch():
228203
is_patch = os.environ.get("is_patch")
229204
return is_patch is not None and is_patch.lower() == "true"
230205

231206

232207
def build_id() -> str:
233-
"""Returns the current UTC time in ISO8601 date format.
234-
235-
If running in Evergreen and `created_at` expansion is defined, use the
236-
datetime defined in that variable instead.
237-
238-
It is possible to pin this time at midnight (00:00) for periodic builds. If
239-
running a manual build, then the Evergreen `pin_tag_at` variable needs to be
240-
set to the empty string, in which case, the image tag suffix will correspond
241-
to the current timestamp.
242-
208+
"""Returns the build id used for the image tag.
209+
The build id is configurable `build_tag_type` and `version_id` in evergreen.
243210
"""
244211

212+
build_tag_type = ""
245213
try:
246214
build_tag_type = os.environ["build_tag_type"]
247215
except KeyError:
248216
pass
249217

250-
date = datetime.now(timezone.utc)
218+
version_id = ""
251219
try:
252-
created_at = os.environ["created_at"]
253-
date = datetime.strptime(created_at, "%y_%m_%d_%H_%M_%S")
220+
version_id = os.environ["version_id"]
254221
except KeyError:
255-
pass
222+
raise MissingEnvironmentVariable("Missing environment variable `version_id`")
256223

257-
# Deprecated: do not use should_pin_at(). Use the suffix instead.
258-
hour, minute = should_pin_at()
259-
if hour and minute:
260-
logger.info(f"we are pinning to, hour: {hour}, minute: {minute}")
261-
date = date.replace(hour=int(hour), minute=int(minute), second=0)
224+
if build_tag_type == "":
225+
return version_id
262226
else:
263-
logger.warning(f"hour and minute cannot be extracted from provided pin_tag_at env, pinning to now")
264-
265-
string_time = date.strftime("%Y%m%dT%H%M%SZ")
266-
267-
return f"{string_time}-{build_tag_type}"
227+
return f"{version_id}-{build_tag_type}"
268228

269229

270230
def get_release() -> Dict:

pipeline_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,18 @@ def test_create_and_push_manifest_push_error(mock_run):
324324

325325
assert "Error pushing manifest" in str(exc_info.value)
326326
assert mock_run.call_count == 2 # Both create and push calls
327+
328+
def test_build_id():
329+
from pipeline import build_id
330+
331+
os.environ["version_id"] = "abcdefg"
332+
os.environ["build_tag_type"] = "release"
333+
id = build_id()
334+
335+
assert id == "abcdefg-release"
336+
337+
os.environ["version_id"] = "abcdefg"
338+
os.environ["build_tag_type"] = ""
339+
id = build_id()
340+
341+
assert id == "abcdefg"

0 commit comments

Comments
 (0)