Skip to content

Commit c05e180

Browse files
committed
Lindt
1 parent fb87f4d commit c05e180

File tree

3 files changed

+57
-52
lines changed

3 files changed

+57
-52
lines changed

scripts/release/build_context.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def infer_scenario_from_environment(cls) -> "BuildScenario":
2929
scenario = BuildScenario.PATCH
3030
logger.info(f"Build scenario: {scenario} (patch_id: {patch_id})")
3131
elif is_evg:
32-
scenario = BuildScenario.MASTER # TODO: ultimately we won't have RELEASE variant and master will push to staging
32+
scenario = (
33+
BuildScenario.MASTER
34+
) # TODO: ultimately we won't have RELEASE variant and master will push to staging
3335
logger.info(f"Build scenario: {scenario} (patch_id: {patch_id})")
3436
else:
3537
scenario = BuildScenario.DEVELOPMENT
@@ -55,27 +57,26 @@ def from_scenario(cls, scenario: BuildScenario) -> "BuildContext":
5557
git_tag = os.getenv("triggered_by_git_tag")
5658
patch_id = os.getenv("version_id")
5759
signing_enabled = scenario == BuildScenario.RELEASE
58-
60+
5961
return cls(
6062
scenario=scenario,
6163
git_tag=git_tag,
6264
patch_id=patch_id,
6365
signing_enabled=signing_enabled,
64-
version=git_tag or patch_id, #TODO: update this
66+
version=git_tag or patch_id, # TODO: update this
6567
)
66-
68+
6769
def get_version(self) -> str:
6870
"""Gets the version that will be used to tag the images."""
6971
if self.scenario == BuildScenario.RELEASE:
7072
return self.git_tag
7173
if self.patch_id:
7274
return self.patch_id
7375
return "latest"
74-
76+
7577
def get_base_registry(self) -> str:
7678
"""Get the base registry URL for the current scenario."""
7779
if self.scenario == BuildScenario.RELEASE:
7880
return os.environ.get("STAGING_REPO_URL")
7981
else:
8082
return os.environ.get("BASE_REPO_URL")
81-

scripts/release/build_images.py

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from lib.sonar.sonar import create_ecr_repository
1616
from scripts.evergreen.release.images_signing import sign_image, verify_signature
1717

18+
1819
# TODO: self review the PR
1920
def ecr_login_boto3(region: str, account_id: str):
2021
"""
@@ -45,36 +46,38 @@ def ecr_login_boto3(region: str, account_id: str):
4546

4647
# TODO: don't do it every time ? Check for existence without relying on Exception
4748
def ensure_buildx_builder(builder_name: str = "multiarch") -> str:
48-
"""
49-
Ensures a Docker Buildx builder exists for multi-platform builds.
50-
51-
:param builder_name: Name for the buildx builder
52-
:return: The builder name that was created or reused
53-
"""
54-
docker = python_on_whales.docker
55-
56-
try:
57-
docker.buildx.create(
58-
name=builder_name,
59-
driver="docker-container",
60-
use=True,
61-
bootstrap=True,
62-
)
63-
logger.info(f"Created new buildx builder: {builder_name}")
64-
except DockerException as e:
65-
if f'existing instance for "{builder_name}"' in str(e):
66-
logger.info(f"Builder '{builder_name}' already exists – reusing it.")
67-
# Make sure it's the current one:
68-
docker.buildx.use(builder_name)
69-
else:
70-
# Some other failure happened
71-
logger.error(f"Failed to create buildx builder: {e}")
72-
raise
73-
74-
return builder_name
75-
76-
77-
def build_image(tag: str, dockerfile: str, path: str, args: Dict[str, str] = {}, push: bool = True, platforms: list[str] = None):
49+
"""
50+
Ensures a Docker Buildx builder exists for multi-platform builds.
51+
52+
:param builder_name: Name for the buildx builder
53+
:return: The builder name that was created or reused
54+
"""
55+
docker = python_on_whales.docker
56+
57+
try:
58+
docker.buildx.create(
59+
name=builder_name,
60+
driver="docker-container",
61+
use=True,
62+
bootstrap=True,
63+
)
64+
logger.info(f"Created new buildx builder: {builder_name}")
65+
except DockerException as e:
66+
if f'existing instance for "{builder_name}"' in str(e):
67+
logger.info(f"Builder '{builder_name}' already exists – reusing it.")
68+
# Make sure it's the current one:
69+
docker.buildx.use(builder_name)
70+
else:
71+
# Some other failure happened
72+
logger.error(f"Failed to create buildx builder: {e}")
73+
raise
74+
75+
return builder_name
76+
77+
78+
def build_image(
79+
tag: str, dockerfile: str, path: str, args: Dict[str, str] = {}, push: bool = True, platforms: list[str] = None
80+
):
7881
"""
7982
Build a Docker image using python_on_whales and Docker Buildx for multi-architecture support.
8083
@@ -86,25 +89,25 @@ def build_image(tag: str, dockerfile: str, path: str, args: Dict[str, str] = {},
8689
:param platforms: List of target platforms (e.g., ["linux/amd64", "linux/arm64"])
8790
"""
8891
docker = python_on_whales.docker
89-
92+
9093
try:
9194
# Convert build args to the format expected by python_on_whales
9295
build_args = {k: str(v) for k, v in args.items()} if args else {}
93-
96+
9497
# Set default platforms if not specified
9598
if platforms is None:
9699
platforms = ["linux/amd64"]
97-
100+
98101
logger.info(f"Building image: {tag}")
99102
logger.info(f"Platforms: {platforms}")
100103
logger.info(f"Dockerfile: {dockerfile}")
101104
logger.info(f"Build context: {path}")
102105
logger.debug(f"Build args: {build_args}")
103-
106+
104107
# Use buildx for multi-platform builds
105108
if len(platforms) > 1:
106109
logger.info(f"Multi-platform build for {len(platforms)} architectures")
107-
110+
108111
# We need a special driver to handle multi platform builds
109112
builder_name = ensure_buildx_builder("multiarch")
110113

@@ -117,18 +120,17 @@ def build_image(tag: str, dockerfile: str, path: str, args: Dict[str, str] = {},
117120
builder=builder_name,
118121
build_args=build_args,
119122
push=push,
120-
provenance=False, # To not get an untagged image for single platform builds
123+
provenance=False, # To not get an untagged image for single platform builds
121124
pull=False, # Don't always pull base images
122125
)
123-
126+
124127
logger.info(f"Successfully built {'and pushed' if push else ''} {tag}")
125-
128+
126129
except Exception as e:
127130
logger.error(f"Failed to build image {tag}: {e}")
128131
raise RuntimeError(f"Failed to build image {tag}: {str(e)}")
129132

130133

131-
132134
def process_image(
133135
image_name: str,
134136
image_tag: str,
@@ -141,7 +143,7 @@ def process_image(
141143
push: bool = True,
142144
):
143145
# Login to ECR using boto3
144-
ecr_login_boto3(region="us-east-1", account_id="268558157000") # TODO: use environment variables
146+
ecr_login_boto3(region="us-east-1", account_id="268558157000") # TODO: use environment variables
145147

146148
# Helper to automatically create registry with correct name
147149
should_create_repo = False
@@ -157,15 +159,15 @@ def process_image(
157159

158160
docker_registry = f"{base_registry}/{image_name}"
159161
image_full_uri = f"{docker_registry}:{image_tag}"
160-
162+
161163
# Build image with docker buildx
162164
build_image(
163165
tag=image_full_uri,
164166
dockerfile=dockerfile_path,
165167
path=build_path,
166168
args=dockerfile_args,
167169
push=push,
168-
platforms=platforms
170+
platforms=platforms,
169171
)
170172

171173
if sign:

scripts/release/main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def main():
115115

116116
_setup_tracing()
117117
parser = argparse.ArgumentParser(description="Build container images.")
118-
parser.add_argument("image", help="Image to build.") # Required
118+
parser.add_argument("image", help="Image to build.") # Required
119119
parser.add_argument("--parallel", action="store_true", help="Build images in parallel.")
120120
parser.add_argument("--debug", action="store_true", help="Enable debug logging.")
121121
parser.add_argument("--sign", action="store_true", help="Sign images.")
@@ -138,7 +138,7 @@ def main():
138138
"--registry",
139139
help="Override the base registry instead of resolving from build scenario",
140140
)
141-
141+
142142
# Agent specific arguments
143143
parser.add_argument(
144144
"--all-agents",
@@ -172,7 +172,9 @@ def build_config_from_args(args):
172172
platforms = [p.strip() for p in args.platform.split(",")]
173173
SUPPORTED_PLATFORMS = ["linux/amd64", "linux/arm64"]
174174
if any(p not in SUPPORTED_PLATFORMS for p in platforms):
175-
logger.error(f"Unsupported platform in '{args.platform}'. Supported platforms: {', '.join(SUPPORTED_PLATFORMS)}")
175+
logger.error(
176+
f"Unsupported platform in '{args.platform}'. Supported platforms: {', '.join(SUPPORTED_PLATFORMS)}"
177+
)
176178
sys.exit(1)
177179

178180
# Centralized configuration management with overrides
@@ -191,7 +193,7 @@ def build_config_from_args(args):
191193
version=version,
192194
base_registry=registry,
193195
parallel=args.parallel,
194-
debug=args.debug, # TODO: is debug used ?
196+
debug=args.debug, # TODO: is debug used ?
195197
platforms=platforms,
196198
sign=sign,
197199
all_agents=all_agents,

0 commit comments

Comments
 (0)