Skip to content

Commit 12ce1b9

Browse files
authored
Dynamic platform detection for ImageSpec to support cross-platform development (#3315)
Signed-off-by: Barry Wu <a0987818905@gmail.com>
1 parent a28f70d commit 12ce1b9

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

flytekit/image_spec/image_spec.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import hashlib
55
import os
66
import pathlib
7+
import platform
78
import re
89
import sys
910
import typing
@@ -48,7 +49,7 @@ class ImageSpec:
4849
cuda (Optional[str]): Version of cuda to install.
4950
cudnn (Optional[str]): Version of cudnn to install.
5051
base_image (Optional[Union[str, 'ImageSpec']]): Base image of the image.
51-
platform (str): Specify the target platforms for the build output (for example, windows/amd64 or linux/amd64,darwin/arm64).
52+
platform (Optional[str]): Specify the target platforms for the build output (for example, windows/amd64 or linux/amd64,darwin/arm64).
5253
pip_index (Optional[str]): Specify the custom pip index url.
5354
pip_extra_index_url (Optional[List[str]]): Specify one or more pip index urls as a list.
5455
pip_secret_mounts (Optional[List[Tuple[str, str]]]): Specify a list of tuples to mount secret for pip install. Each tuple should contain the path to
@@ -94,7 +95,7 @@ class ImageSpec:
9495
cuda: Optional[str] = None
9596
cudnn: Optional[str] = None
9697
base_image: Optional[Union[str, "ImageSpec"]] = None
97-
platform: str = "linux/amd64"
98+
platform: Optional[str] = None
9899
pip_index: Optional[str] = None
99100
pip_extra_index_url: Optional[List[str]] = None
100101
pip_secret_mounts: Optional[List[Tuple[str, str]]] = None
@@ -126,6 +127,17 @@ def __post_init__(self):
126127
f"- 'docker.io/username' (for docker hub)\n"
127128
)
128129

130+
if self.platform is None:
131+
if (
132+
self.registry
133+
and self.registry.lower().startswith("localhost:")
134+
and platform.machine().lower() in ("arm64", "aarch64")
135+
):
136+
# Only change platform to ARM64 if platform is not set and pushing to local registry on ARM64 machine
137+
self.platform = "linux/arm64"
138+
else:
139+
self.platform = "linux/amd64"
140+
129141
# If not set, help the user set this option as well, to support the older default behavior where existence
130142
# of the source root implied that copying of files was needed.
131143
if self.source_root is not None:

0 commit comments

Comments
 (0)