Skip to content

Commit 84d649b

Browse files
feat: Always build for both AMD64 and ARM64 architectures
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent 9510f2d commit 84d649b

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

airbyte_cdk/cli/build/_run.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ def parse_args(args: List[str]) -> argparse.Namespace:
4343
parser.add_argument(
4444
"--tag", type=str, default="dev", help="Tag to apply to the built image (default: dev)"
4545
)
46-
parser.add_argument(
47-
"--platform",
48-
type=str,
49-
choices=["linux/amd64", "linux/arm64"],
50-
default="linux/amd64",
51-
help="Platform to build for (default: linux/amd64)",
52-
)
5346
parser.add_argument(
5447
"--no-verify", action="store_true", help="Skip verification of the built image"
5548
)
@@ -178,15 +171,15 @@ def build_from_dockerfile(
178171
connector_dir: Path,
179172
metadata: ConnectorMetadata,
180173
tag: str,
181-
platform: str,
174+
platforms: str = "linux/amd64,linux/arm64",
182175
) -> str:
183176
"""Build a Docker image for the connector using its Dockerfile.
184177
185178
Args:
186179
connector_dir: Path to the connector directory.
187180
metadata: The connector metadata.
188181
tag: The tag to apply to the built image.
189-
platform: The platform to build for (e.g., linux/amd64).
182+
platforms: The platforms to build for (default: "linux/amd64,linux/arm64").
190183
191184
Returns:
192185
The full image name with tag.
@@ -202,22 +195,24 @@ def build_from_dockerfile(
202195
image_name = metadata.dockerRepository
203196
full_image_name = f"{image_name}:{tag}"
204197

205-
logger.info(f"Building Docker image from Dockerfile: {full_image_name} for platform {platform}")
198+
logger.info(f"Building Docker image from Dockerfile: {full_image_name} for platforms {platforms}")
206199
logger.warning(
207200
"Building from Dockerfile is deprecated. Consider using a base image in metadata.yaml."
208201
)
209202

210203
build_cmd = [
211204
"docker",
205+
"buildx",
212206
"build",
213207
"--platform",
214-
platform,
208+
platforms,
215209
"-t",
216210
full_image_name,
217211
"--label",
218212
f"io.airbyte.version={metadata.dockerImageTag}",
219213
"--label",
220214
f"io.airbyte.name={metadata.dockerRepository}",
215+
"--load", # Load the image into the local Docker daemon
221216
str(connector_dir),
222217
]
223218

@@ -234,15 +229,15 @@ def build_from_base_image(
234229
connector_dir: Path,
235230
metadata: ConnectorMetadata,
236231
tag: str,
237-
platform: str,
232+
platforms: str = "linux/amd64,linux/arm64",
238233
) -> str:
239234
"""Build a Docker image for the connector using a base image.
240235
241236
Args:
242237
connector_dir: Path to the connector directory.
243238
metadata: The connector metadata.
244239
tag: The tag to apply to the built image.
245-
platform: The platform to build for (e.g., linux/amd64).
240+
platforms: The platforms to build for (default: "linux/amd64,linux/arm64").
246241
247242
Returns:
248243
The full image name with tag.
@@ -259,7 +254,7 @@ def build_from_base_image(
259254
full_image_name = f"{image_name}:{tag}"
260255

261256
logger.info(
262-
f"Building Docker image from base image {base_image}: {full_image_name} for platform {platform}"
257+
f"Building Docker image from base image {base_image}: {full_image_name} for platforms {platforms}"
263258
)
264259

265260
with tempfile.TemporaryDirectory() as temp_dir:
@@ -272,6 +267,8 @@ def build_from_base_image(
272267
273268
COPY . .
274269
270+
RUN pip install .
271+
275272
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/{get_main_file_name(connector_dir)}"
276273
ENTRYPOINT ["python", "/airbyte/integration_code/{get_main_file_name(connector_dir)}"]
277274
"""
@@ -287,15 +284,17 @@ def build_from_base_image(
287284

288285
build_cmd = [
289286
"docker",
287+
"buildx",
290288
"build",
291289
"--platform",
292-
platform,
290+
platforms,
293291
"-t",
294292
full_image_name,
295293
"--label",
296294
f"io.airbyte.version={metadata.dockerImageTag}",
297295
"--label",
298296
f"io.airbyte.name={metadata.dockerRepository}",
297+
"--load", # Load the image into the local Docker daemon
299298
str(temp_dir_path),
300299
]
301300

@@ -377,13 +376,16 @@ def run_command(args: List[str]) -> int:
377376
logger.info(f"Detected connector language: {language}")
378377

379378
try:
379+
platforms = "linux/amd64,linux/arm64"
380+
logger.info(f"Building for platforms: {platforms}")
381+
380382
if metadata.connectorBuildOptions and metadata.connectorBuildOptions.baseImage:
381383
image_name = build_from_base_image(
382-
connector_dir, metadata, parsed_args.tag, parsed_args.platform
384+
connector_dir, metadata, parsed_args.tag, platforms
383385
)
384386
else:
385387
image_name = build_from_dockerfile(
386-
connector_dir, metadata, parsed_args.tag, parsed_args.platform
388+
connector_dir, metadata, parsed_args.tag, platforms
387389
)
388390

389391
if not parsed_args.no_verify:

airbyte_cdk/cli/commands/image.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,14 @@ def image() -> None:
2727
"connector_dir", type=click.Path(exists=True, file_okay=False, dir_okay=True, path_type=Path)
2828
)
2929
@click.option("--tag", default="dev", help="Tag to apply to the built image (default: dev)")
30-
@click.option(
31-
"--platform",
32-
type=click.Choice(["linux/amd64", "linux/arm64"]),
33-
default="linux/amd64",
34-
help="Platform to build for (default: linux/amd64)",
35-
)
3630
@click.option("--no-verify", is_flag=True, help="Skip verification of the built image")
3731
@click.option("--verbose", "-v", is_flag=True, help="Enable verbose logging")
38-
def build(connector_dir: Path, tag: str, platform: str, no_verify: bool, verbose: bool) -> None:
32+
def build(connector_dir: Path, tag: str, no_verify: bool, verbose: bool) -> None:
3933
"""Build a connector Docker image.
4034
4135
This command builds a Docker image for a connector, using either
4236
the connector's Dockerfile or a base image specified in the metadata.
37+
The image is built for both AMD64 and ARM64 architectures.
4338
"""
4439
set_up_logging(verbose)
4540

@@ -56,11 +51,14 @@ def build(connector_dir: Path, tag: str, platform: str, no_verify: bool, verbose
5651

5752
language = infer_connector_language(metadata, connector_dir)
5853
click.echo(f"Detected connector language: {language}")
54+
55+
platforms = "linux/amd64,linux/arm64"
56+
click.echo(f"Building for platforms: {platforms}")
5957

6058
if metadata.connectorBuildOptions and metadata.connectorBuildOptions.baseImage:
61-
image_name = build_from_base_image(connector_dir, metadata, tag, platform)
59+
image_name = build_from_base_image(connector_dir, metadata, tag, platforms)
6260
else:
63-
image_name = build_from_dockerfile(connector_dir, metadata, tag, platform)
61+
image_name = build_from_dockerfile(connector_dir, metadata, tag, platforms)
6462

6563
if not no_verify:
6664
if verify_image(image_name):

docs/cli/build.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ airbyte-cdk image build /path/to/connector
2424
# With custom tag
2525
airbyte-cdk image build /path/to/connector --tag custom_tag
2626

27-
# Build for a specific platform
28-
airbyte-cdk image build /path/to/connector --platform linux/arm64
29-
3027
# Skip verification
3128
airbyte-cdk image build /path/to/connector --no-verify
3229

@@ -38,7 +35,7 @@ airbyte-cdk image build /path/to/connector --verbose
3835

3936
- `connector_dir`: Path to the connector directory (required)
4037
- `--tag`: Tag to apply to the built image (default: "dev")
41-
- `--platform`: Platform to build for (choices: "linux/amd64", "linux/arm64", default: "linux/amd64")
38+
4239
- `--no-verify`: Skip verification of the built image
4340
- `--verbose`, `-v`: Enable verbose logging
4441

0 commit comments

Comments
 (0)