Skip to content

Commit c51b8ba

Browse files
authored
Fix master builds (#331)
# Summary Master patches are broken because they build with `latest` tag only, while the patch still need the `patch_id` tagged images. This PR fixes this issue to get master green again, but remove builds to `latest`. They will be added again in #317, using build_info. Not pushing to latest only impacts local testing for dev, as we use them to have the most recently built versions from master. It won't break local development, but it means the image used will be slightly outdated. ## Proof of Work I tested it by forcing to return the patch ID and dumping the relevant variables in this patch: https://spruce.mongodb.com/version/6899d033f94ad4000694cf89/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC But the relevant environment variable (`is_patch` being false, as described in the added documentation) will be set to the right value only when merging to master.
1 parent 64ded08 commit c51b8ba

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

scripts/release/build_context.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,36 @@ class BuildScenario(str, Enum):
1717
@classmethod
1818
def infer_scenario_from_environment(cls) -> "BuildScenario":
1919
"""Infer the build scenario from environment variables."""
20+
# triggered_by_git_tag is the name of the tag that triggered this version, if applicable. It will be None for
21+
# all patches except when tagging a commit on GitHub
2022
git_tag = os.getenv("triggered_by_git_tag")
23+
# is_patch is passed automatically by Evergreen.
24+
# It is "true" if the running task is in a patch build and undefined if it is not.
25+
# A patch build is a version not triggered by a commit to a repository.
26+
# It either runs tasks on a base commit plus some diff if submitted by the CLI or on a git branch if created by
27+
# a GitHub pull request.
2128
is_patch = os.getenv("is_patch", "false").lower() == "true"
29+
# RUNNING_IN_EVG is set by us in evg-private-context
2230
is_evg = os.getenv("RUNNING_IN_EVG", "false").lower() == "true"
31+
# version_id is the id of the task's version. It is generated automatically for each task run.
32+
# For example: `6899b7e35bfaee00077db986` for a manual/PR patch,
33+
# or `mongodb_kubernetes_5c5a3accb47bb411682b8c67f225b61f7ad5a619` for a master merge
2334
patch_id = os.getenv("version_id")
2435

36+
logger.debug(
37+
f"Collected environment variables: git tag {git_tag}, is_patch {is_patch}, is_evg {is_evg}, patch_id {patch_id}"
38+
)
39+
2540
if git_tag:
2641
# Release scenario and the git tag will be used for promotion process only
2742
scenario = BuildScenario.RELEASE
28-
logger.info(f"Build scenario: {scenario} (git_tag: {git_tag})")
43+
logger.info(f"Build scenario: {scenario}, git_tag: {git_tag}")
2944
elif is_patch:
3045
scenario = BuildScenario.PATCH
31-
logger.info(f"Build scenario: {scenario} (patch_id: {patch_id})")
46+
logger.info(f"Build scenario: {scenario}, patch_id: {patch_id}")
3247
elif is_evg:
3348
scenario = BuildScenario.STAGING
34-
logger.info(f"Build scenario: {scenario} (patch_id: {patch_id})")
49+
logger.info(f"Build scenario: {scenario}, patch_id: {patch_id}")
3550
else:
3651
scenario = BuildScenario.DEVELOPMENT
3752
logger.info(f"Build scenario: {scenario}")
@@ -70,11 +85,15 @@ def get_version(self) -> str:
7085
if self.scenario == BuildScenario.RELEASE:
7186
return self.git_tag
7287
if self.scenario == BuildScenario.STAGING:
73-
# On master merges, always use "latest" (preserving legacy behavior)
74-
return "latest"
88+
# On master merges, we need to build images with the patch_id as they are expected by tests. Later on,
89+
# we will use commit SHA. Optionally, we may want to continue pushing to ECR registry with "latest", for
90+
# local dev purposes.
91+
return self.patch_id
7592
if self.patch_id:
7693
return self.patch_id
7794
# Alternatively, we can fail here if no ID is explicitly defined
95+
# When working locally, "version_id" env variable is defined in the generated context file. It is "latest" by
96+
# default, and can be overridden with OVERRIDE_VERSION_ID
7897
return "latest"
7998

8099
def get_base_registry(self) -> str:

0 commit comments

Comments
 (0)