Skip to content

Commit 86e0a60

Browse files
committed
clean up arch implementation
1 parent c12242d commit 86e0a60

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

airbyte_cdk/cli/airbyte_cdk/_image.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def build(
7272
connector_name=connector_name,
7373
metadata=metadata,
7474
tag=tag,
75-
arch="linux/amd64",
7675
no_verify=no_verify,
7776
)
7877

airbyte_cdk/utils/docker.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import subprocess
99
import sys
10+
from enum import Enum
1011
from pathlib import Path
1112

1213
import click
@@ -20,13 +21,19 @@
2021

2122
logger = logging.getLogger(__name__)
2223

24+
class ArchEnum(str, Enum):
25+
"""Enum for supported architectures."""
26+
27+
ARM64 = "arm64"
28+
AMD64 = "amd64"
29+
2330

2431
def _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

Comments
 (0)