adamant-magazine-16751
03/14/2023, 12:58 PMdocker_image
target? An example would be building a linux/amd64 image on an m1 mac. I managed to build a pex using platform=linux_x86_64
but I suppose that a docker_image built on an arm will target arm64
. Do I understand correctly that this example workflow from the docs considers the case with an x86 mac - the same architecture?https://www.pantsbuild.org/docs/environments#use-a-docker_environment-to-build-the-inputs-to-a-docker_image
I'm not even sure if this is something I should expect to be available. This is a very specific case of quick-prototyping - building a dev version of an image locally, publishing and running it in the test environment that is based on x86worried-painter-31382
03/14/2023, 1:15 PMimport platform
from typing import Iterable
from pants.backend.docker.target_types import DockerBuildOptionFieldMixin
from pants.backend.docker.target_types import DockerImageTarget
from pants.backend.docker.target_types import OptionValueFormatter
from pants.engine.rules import Rule
from pants.engine.target import StringField
from pants.util.strutil import softwrap
X86_64 = "linux/amd64"
ARM_64 = "linux/arm64"
class DockerImagePlatformField(DockerBuildOptionFieldMixin, StringField):
alias = "platform"
help = softwrap(
"""
Target platform of the built image (e.g., "linux/amd64")
"""
)
docker_build_option = "--platform"
default = X86_64
_python_to_docker_platforms = {
"x86_64": X86_64,
"aarch64": ARM_64,
}
def option_values(self, *, value_formatter: OptionValueFormatter) -> Iterable[str]:
if self.value:
machine = platform.machine()
if self._python_to_docker_platforms.get(machine) != self.value:
yield value_formatter(self.value)
def rules() -> Iterable[Rule]:
return [
DockerImageTarget.register_plugin_field(DockerImagePlatformField),
]
but I suppose that a docker_image built on an arm will targetYep.arm64
This is a very specific case of quick-prototyping - building a dev version of an image locally, publishing and running it in the test environment that is based on x86This can be a lot of pain. I have found that
qemu
for silicon is not particularly reliable yetadamant-magazine-16751
03/14/2023, 3:03 PM