|
4 | 4 | import hashlib |
5 | 5 | import os |
6 | 6 | import pathlib |
| 7 | +import platform |
7 | 8 | import re |
8 | 9 | import sys |
9 | 10 | import typing |
@@ -48,7 +49,7 @@ class ImageSpec: |
48 | 49 | cuda (Optional[str]): Version of cuda to install. |
49 | 50 | cudnn (Optional[str]): Version of cudnn to install. |
50 | 51 | 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). |
52 | 53 | pip_index (Optional[str]): Specify the custom pip index url. |
53 | 54 | pip_extra_index_url (Optional[List[str]]): Specify one or more pip index urls as a list. |
54 | 55 | 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: |
94 | 95 | cuda: Optional[str] = None |
95 | 96 | cudnn: Optional[str] = None |
96 | 97 | base_image: Optional[Union[str, "ImageSpec"]] = None |
97 | | - platform: str = "linux/amd64" |
| 98 | + platform: Optional[str] = None |
98 | 99 | pip_index: Optional[str] = None |
99 | 100 | pip_extra_index_url: Optional[List[str]] = None |
100 | 101 | pip_secret_mounts: Optional[List[Tuple[str, str]]] = None |
@@ -126,6 +127,17 @@ def __post_init__(self): |
126 | 127 | f"- 'docker.io/username' (for docker hub)\n" |
127 | 128 | ) |
128 | 129 |
|
| 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 | + |
129 | 141 | # If not set, help the user set this option as well, to support the older default behavior where existence |
130 | 142 | # of the source root implied that copying of files was needed. |
131 | 143 | if self.source_root is not None: |
|
0 commit comments