1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-04-02 00:07:16 +01:00

Fix apps build using wrong architecture for non-native arch apps (#6610)

* Fix add-on build using wrong architecture for non-native arch add-ons

When building a locally-built add-on (no image tag), the architecture
was always set to sys_arch.default (e.g. amd64 on x86_64) instead of
matching against the add-on's declared architectures. This caused an
i386-only add-on to incorrectly build as amd64.

Use sys_arch.match() against the add-on's declared arch list in all
code paths: the arch property, image name generation, BUILD_ARCH build
arg, and default base image selection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Use CpuArch enums to fix tests

* Explicitly set _supported_arch as new list to fix tests

* Fix pytests

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Stefan Agner
2026-03-03 15:36:30 +01:00
committed by GitHub
parent 2627d55873
commit 96fb26462b
4 changed files with 16 additions and 15 deletions

View File

@@ -84,7 +84,7 @@ class AddonBuild(FileConfiguration, CoreSysAttributes):
def base_image(self) -> str:
"""Return base image for this add-on."""
if not self._data[ATTR_BUILD_FROM]:
return f"ghcr.io/home-assistant/{self.sys_arch.default!s}-base:latest"
return f"ghcr.io/home-assistant/{self.arch!s}-base:latest"
if isinstance(self._data[ATTR_BUILD_FROM], str):
return self._data[ATTR_BUILD_FROM]
@@ -220,7 +220,7 @@ class AddonBuild(FileConfiguration, CoreSysAttributes):
build_args = {
"BUILD_FROM": self.base_image,
"BUILD_VERSION": version,
"BUILD_ARCH": self.sys_arch.default,
"BUILD_ARCH": self.arch,
**self.additional_args,
}

View File

@@ -550,10 +550,7 @@ class AddonModel(JobGroup, ABC):
@property
def arch(self) -> CpuArch:
"""Return architecture to use for the addon's image."""
if ATTR_IMAGE in self.data:
return self.sys_arch.match(self.data[ATTR_ARCH])
return self.sys_arch.default
return self.sys_arch.match(self.data[ATTR_ARCH])
@property
def image(self) -> str | None:
@@ -725,4 +722,5 @@ class AddonModel(JobGroup, ABC):
return config[ATTR_IMAGE].format(arch=arch)
# local build
return f"{config[ATTR_REPOSITORY]}/{self.sys_arch.default!s}-addon-{config[ATTR_SLUG]}"
arch = self.sys_arch.match(config[ATTR_ARCH])
return f"{config[ATTR_REPOSITORY]}/{arch!s}-addon-{config[ATTR_SLUG]}"

View File

@@ -64,11 +64,12 @@ class CpuArchManager(CoreSysAttributes):
if not self.sys_machine or self.sys_machine not in arch_data:
_LOGGER.warning("Can't detect the machine type!")
self._default_arch = native_support
self._supported_arch.append(self.default)
self._supported_arch = [self.default]
self._supported_set = {self.default}
return
# Use configs from arch.json
self._supported_arch.extend(CpuArch(a) for a in arch_data[self.sys_machine])
self._supported_arch = [CpuArch(a) for a in arch_data[self.sys_machine]]
self._default_arch = self.supported[0]
# Make sure native support is in supported list

View File

@@ -48,6 +48,7 @@ from supervisor.const import (
ATTR_VERSION,
REQUEST_FROM,
CoreState,
CpuArch,
)
from supervisor.coresys import CoreSys
from supervisor.dbus.network import NetworkManager
@@ -506,8 +507,9 @@ async def coresys(
"Config": {"Labels": {"io.hass.arch": "amd64"}},
"HostConfig": {"Privileged": True},
}
coresys_obj.arch._default_arch = "amd64"
coresys_obj.arch._supported_set = {"amd64"}
coresys_obj.arch._default_arch = CpuArch.AMD64
coresys_obj.arch._supported_arch = [CpuArch.AMD64]
coresys_obj.arch._supported_set = {CpuArch.AMD64}
coresys_obj._machine = "qemux86-64"
coresys_obj._machine_id = uuid4()
@@ -984,15 +986,15 @@ async def mount_propagation(container: DockerContainer, coresys: CoreSys) -> Non
@pytest.fixture
def mock_amd64_arch_supported(coresys: CoreSys) -> None:
"""Mock amd64 arch as supported."""
coresys.arch._supported_arch = ["amd64"]
coresys.arch._supported_set = {"amd64"}
coresys.arch._supported_arch = [CpuArch.AMD64]
coresys.arch._supported_set = {CpuArch.AMD64}
@pytest.fixture
def mock_aarch64_arch_supported(coresys: CoreSys) -> None:
"""Mock aarch64 arch as supported."""
coresys.arch._supported_arch = ["amd64"]
coresys.arch._supported_set = {"amd64"}
coresys.arch._supported_arch = [CpuArch.AMD64]
coresys.arch._supported_set = {CpuArch.AMD64}
@pytest.fixture