mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-21 08:06:30 +00:00
Support for Docker manifests base images add-on build (#3724)
* Support for Docker manifests base images add-on build * Set platform for build and tests * Remove empty test Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
This commit is contained in:
parent
96065ed704
commit
3f88236495
@ -15,6 +15,7 @@ from ..const import (
|
||||
META_ADDON,
|
||||
)
|
||||
from ..coresys import CoreSys, CoreSysAttributes
|
||||
from ..docker.interface import MAP_ARCH
|
||||
from ..exceptions import ConfigurationFileError
|
||||
from ..utils.common import FileConfiguration, find_one_filetype
|
||||
from .validate import SCHEMA_BUILD_CONFIG
|
||||
@ -50,6 +51,9 @@ class AddonBuild(FileConfiguration, CoreSysAttributes):
|
||||
if not self._data[ATTR_BUILD_FROM]:
|
||||
return f"ghcr.io/home-assistant/{self.sys_arch.default}-base:latest"
|
||||
|
||||
if isinstance(self._data[ATTR_BUILD_FROM], str):
|
||||
return self._data[ATTR_BUILD_FROM]
|
||||
|
||||
# Evaluate correct base image
|
||||
arch = self.sys_arch.match(list(self._data[ATTR_BUILD_FROM].keys()))
|
||||
return self._data[ATTR_BUILD_FROM][arch]
|
||||
@ -87,6 +91,7 @@ class AddonBuild(FileConfiguration, CoreSysAttributes):
|
||||
"pull": True,
|
||||
"forcerm": not self.sys_dev,
|
||||
"squash": self.squash,
|
||||
"platform": MAP_ARCH[self.sys_arch.match(self.addon.arch)],
|
||||
"labels": {
|
||||
"io.hass.version": version,
|
||||
"io.hass.arch": self.sys_arch.default,
|
||||
|
@ -351,8 +351,9 @@ SCHEMA_ADDON_CONFIG = vol.All(
|
||||
# pylint: disable=no-value-for-parameter
|
||||
SCHEMA_BUILD_CONFIG = vol.Schema(
|
||||
{
|
||||
vol.Optional(ATTR_BUILD_FROM, default=dict): vol.Schema(
|
||||
{vol.In(ARCH_ALL): vol.Match(RE_DOCKER_IMAGE_BUILD)}
|
||||
vol.Optional(ATTR_BUILD_FROM, default=dict): vol.Any(
|
||||
vol.Match(RE_DOCKER_IMAGE_BUILD),
|
||||
vol.Schema({vol.In(ARCH_ALL): vol.Match(RE_DOCKER_IMAGE_BUILD)}),
|
||||
),
|
||||
vol.Optional(ATTR_SQUASH, default=False): vol.Boolean(),
|
||||
vol.Optional(ATTR_ARGS, default=dict): vol.Schema({str: str}),
|
||||
|
21
tests/addons/test_build.py
Normal file
21
tests/addons/test_build.py
Normal file
@ -0,0 +1,21 @@
|
||||
"""Test addon build."""
|
||||
from unittest.mock import PropertyMock, patch
|
||||
|
||||
from awesomeversion import AwesomeVersion
|
||||
|
||||
from supervisor.addons.addon import Addon
|
||||
from supervisor.addons.build import AddonBuild
|
||||
from supervisor.coresys import CoreSys
|
||||
|
||||
|
||||
async def test_platform_set(coresys: CoreSys, install_addon_ssh: Addon):
|
||||
"""Test platform set in docker args."""
|
||||
build = AddonBuild(coresys, install_addon_ssh)
|
||||
with patch.object(
|
||||
type(coresys.arch), "supported", new=PropertyMock(return_value=["amd64"])
|
||||
), patch.object(
|
||||
type(coresys.arch), "default", new=PropertyMock(return_value="amd64")
|
||||
):
|
||||
args = build.get_docker_args(AwesomeVersion("latest"))
|
||||
|
||||
assert args["platform"] == "linux/amd64"
|
@ -146,6 +146,13 @@ def test_valid_basic_build():
|
||||
vd.SCHEMA_BUILD_CONFIG(config)
|
||||
|
||||
|
||||
async def test_valid_manifest_build():
|
||||
"""Validate build config with manifest build from."""
|
||||
config = load_json_fixture("build-config-manifest.json")
|
||||
|
||||
vd.SCHEMA_BUILD_CONFIG(config)
|
||||
|
||||
|
||||
def test_valid_machine():
|
||||
"""Validate valid machine config."""
|
||||
config = load_json_fixture("basic-addon-config.json")
|
||||
|
7
tests/fixtures/build-config-manifest.json
vendored
Normal file
7
tests/fixtures/build-config-manifest.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"build_from": "mycustom/base-image:latest",
|
||||
"squash": false,
|
||||
"args": {
|
||||
"my_build_arg": "xy"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user