77import os
88import subprocess
99import sys
10+ from enum import Enum
1011from pathlib import Path
1112
1213import click
2021
2122logger = logging .getLogger (__name__ )
2223
24+ class ArchEnum (str , Enum ):
25+ """Enum for supported architectures."""
26+
27+ ARM64 = "arm64"
28+ AMD64 = "amd64"
29+
2330
2431def _build_image (
2532 context_dir : Path ,
2633 dockerfile : Path ,
2734 metadata : MetadataFile ,
2835 tag : str ,
29- arch : str ,
36+ arch : ArchEnum ,
3037 build_args : dict [str , str | None ] | None = None ,
3138) -> str :
3239 """Build a Docker image for the specified architecture.
@@ -37,7 +44,7 @@ def _build_image(
3744 "docker" ,
3845 "build" ,
3946 "--platform" ,
40- arch ,
47+ f"linux/ { arch . value } " ,
4148 "--file" ,
4249 str (dockerfile ),
4350 "--label" ,
@@ -98,9 +105,25 @@ def build_connector_image(
98105 connector_directory : Path ,
99106 metadata : MetadataFile ,
100107 tag : str ,
101- arch : str | None = None ,
108+ primary_arch : ArchEnum = ArchEnum . ARM64 , # Assume MacBook M series by default
102109 no_verify : bool = False ,
103110) -> None :
111+ """Build a connector Docker image.
112+
113+ This command builds a Docker image for a connector, using either
114+ the connector's Dockerfile or a base image specified in the metadata.
115+ The image is built for both AMD64 and ARM64 architectures.
116+
117+ Args:
118+ connector_name: The name of the connector.
119+ connector_directory: The directory containing the connector code.
120+ metadata: The metadata of the connector.
121+ tag: The tag to apply to the built image.
122+ primary_arch: The primary architecture for the build (default: arm64). This
123+ architecture will be used for the same-named tag. Both AMD64 and ARM64
124+ images will be built, with the suffixes '-amd64' and '-arm64'.
125+ no_verify: If True, skip verification of the built image.
126+ """
104127 connector_kebab_name = connector_name
105128 connector_snake_name = connector_kebab_name .replace ("-" , "_" )
106129
@@ -133,9 +156,8 @@ def build_connector_image(
133156
134157 base_tag = f"{ metadata .data .dockerRepository } :{ tag } "
135158 arch_images : list [str ] = []
136- default_arch = "linux/arm64" # Assume MacBook M series by default
137- for arch in ["linux/amd64" , "linux/arm64" ]:
138- docker_tag = f"{ base_tag } -{ arch .replace ('/' , '-' )} "
159+ for arch in [ArchEnum .AMD64 , ArchEnum .ARM64 ]:
160+ docker_tag = f"{ base_tag } -{ arch .value } "
139161 docker_tag_parts = docker_tag .split ("/" )
140162 if len (docker_tag_parts ) > 2 :
141163 docker_tag = "/" .join (docker_tag_parts [- 1 :])
@@ -151,7 +173,7 @@ def build_connector_image(
151173 )
152174
153175 _tag_image (
154- tag = f"{ base_tag } -{ default_arch . replace ( '/' , '-' ) } " ,
176+ tag = f"{ base_tag } -{ primary_arch . value } " ,
155177 new_tags = [base_tag ],
156178 )
157179 if not no_verify :
0 commit comments