Skip to content

Commit 1badff0

Browse files
committed
Ensure builder in main to fix race conditions
1 parent 2ec7587 commit 1badff0

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

scripts/release/build_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def get_base_registry(self) -> str:
8383
# TODO CLOUDP-335471: STAGING scenario should also push to STAGING_REPO_URL with version_id tag,
8484
# in addition to the current ECR dev latest push (for backward compatibility)
8585
# This will enable proper staging environment testing before production releases
86-
86+
8787
# For now, always use BASE_REPO_URL to preserve legacy behavior
8888
# (STAGING pushes to ECR dev with "latest" tag)
8989
return os.environ.get("BASE_REPO_URL")

scripts/release/build_images.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import docker
1111
from lib.base_logger import logger
1212

13+
DEFAULT_BUILDER_NAME = "multiarch" # Default buildx builder name
14+
1315

1416
def ecr_login_boto3(region: str, account_id: str):
1517
"""
@@ -38,7 +40,7 @@ def ecr_login_boto3(region: str, account_id: str):
3840
logger.debug(f"ECR login succeeded: {status}")
3941

4042

41-
def ensure_buildx_builder(builder_name: str = "multiarch") -> str:
43+
def ensure_buildx_builder(builder_name: str = DEFAULT_BUILDER_NAME) -> str:
4244
"""
4345
Ensures a Docker Buildx builder exists for multi-platform builds.
4446
@@ -70,7 +72,13 @@ def ensure_buildx_builder(builder_name: str = "multiarch") -> str:
7072

7173

7274
def execute_docker_build(
73-
tag: str, dockerfile: str, path: str, args: Dict[str, str] = {}, push: bool = True, platforms: list[str] = None
75+
tag: str,
76+
dockerfile: str,
77+
path: str,
78+
args: Dict[str, str] = {},
79+
push: bool = True,
80+
platforms: list[str] = None,
81+
builder_name: str = DEFAULT_BUILDER_NAME,
7482
):
7583
"""
7684
Build a Docker image using python_on_whales and Docker Buildx for multi-architecture support.
@@ -105,10 +113,7 @@ def execute_docker_build(
105113
if len(platforms) > 1:
106114
logger.info(f"Multi-platform build for {len(platforms)} architectures")
107115

108-
# We need a special driver to handle multi-platform builds
109-
builder_name = ensure_buildx_builder("multiarch")
110-
111-
# Build the image using buildx
116+
# Build the image using buildx, builder must be already initialized
112117
docker.buildx.build(
113118
context_path=path,
114119
file=dockerfile,

scripts/release/pipeline_main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
BuildContext,
3535
BuildScenario,
3636
)
37+
from scripts.release.build_images import DEFAULT_BUILDER_NAME, ensure_buildx_builder
3738

3839
"""
3940
The goal of main.py, build_configuration.py and build_context.py is to provide a single source of truth for the build
@@ -145,6 +146,10 @@ def main():
145146
logger.info(f"Building image: {args.image}")
146147
logger.info(f"Build configuration: {build_config}")
147148

149+
# Create buildx builder
150+
# It must be initialized here as opposed to in build_images.py so that parallel calls (such as agent builds) can access it
151+
# and not face race conditions
152+
ensure_buildx_builder(DEFAULT_BUILDER_NAME)
148153
build_image(args.image, build_config)
149154

150155

0 commit comments

Comments
 (0)