Allow every repository to make a local build (#47)

* Allow every repository to make a local build

* store version of build

* cleanup code

* fix lint
This commit is contained in:
Pascal Vizeli 2017-05-14 23:32:54 +02:00 committed by GitHub
parent eed41d30ec
commit 86180ddc34
4 changed files with 13 additions and 21 deletions

View File

@ -13,8 +13,8 @@ from .validate import (
from ..const import (
FILE_HASSIO_ADDONS, ATTR_NAME, ATTR_VERSION, ATTR_SLUG, ATTR_DESCRIPTON,
ATTR_STARTUP, ATTR_BOOT, ATTR_MAP, ATTR_OPTIONS, ATTR_PORTS, BOOT_AUTO,
DOCKER_REPO, ATTR_SCHEMA, ATTR_IMAGE, MAP_CONFIG, MAP_SSL, MAP_ADDONS,
MAP_BACKUP, ATTR_REPOSITORY, ATTR_URL, ATTR_ARCH, ATTR_LOCATON)
ATTR_SCHEMA, ATTR_IMAGE, MAP_CONFIG, MAP_SSL, MAP_ADDONS, MAP_BACKUP,
ATTR_REPOSITORY, ATTR_URL, ATTR_ARCH, ATTR_LOCATON)
from ..config import Config
from ..tools import read_json_file, write_json_file
@ -308,28 +308,20 @@ class AddonsData(Config):
addon, self._addons_cache.get(addon)
)
# core repository
if addon_data[ATTR_REPOSITORY] == REPOSITORY_CORE:
return "{}/{}-addon-{}".format(
DOCKER_REPO, self.arch, addon_data[ATTR_SLUG])
# Repository with dockerhub images
if ATTR_IMAGE in addon_data:
return addon_data[ATTR_IMAGE].format(arch=self.arch)
# Local build addon
if addon_data[ATTR_REPOSITORY] == REPOSITORY_LOCAL:
return "local/{}-addon-{}".format(self.arch, addon_data[ATTR_SLUG])
_LOGGER.error("No image for %s", addon)
# local build
return "{}/{}-addon-{}".format(
addon_data[ATTR_REPOSITORY], self.arch, addon_data[ATTR_SLUG])
def need_build(self, addon):
"""Return True if this addon need a local build."""
"""Return True if this addon need a local build."""
addon_data = self._system_data.get(
addon, self._addons_cache.get(addon)
)
return addon_data[ATTR_REPOSITORY] == REPOSITORY_LOCAL \
and not addon_data.get(ATTR_IMAGE)
return ATTR_IMAGE not in addon_data
def map_config(self, addon):
"""Return True if config map is needed."""

View File

@ -10,8 +10,6 @@ URL_HASSIO_VERSION_BETA = ('https://raw.githubusercontent.com/home-assistant/'
URL_HASSIO_ADDONS = 'https://github.com/home-assistant/hassio-addons'
DOCKER_REPO = "homeassistant"
HASSIO_SHARE = Path("/data")
RUN_UPDATE_INFO_TASKS = 28800

View File

@ -51,13 +51,13 @@ class DockerBase(object):
_LOGGER.info("Pull image %s tag %s.", self.image, tag)
image = self.dock.images.pull("{}:{}".format(self.image, tag))
self.version = tag
image.tag(self.image, tag='latest')
self.version = get_version_from_env(image.attrs['Config']['Env'])
_LOGGER.info("Tag image %s with version %s as latest",
self.image, self.version)
except docker.errors.APIError as err:
_LOGGER.error("Can't install %s:%s -> %s.", self.image, tag, err)
return False
_LOGGER.info("Tag image %s with version %s as latest", self.image, tag)
return True
def exists(self):

View File

@ -159,12 +159,14 @@ class DockerAddon(DockerBase):
image = self.dock.images.build(
path=str(build_dir), tag=build_tag, pull=True)
_LOGGER.info("Build %s done", build_tag)
self.version = tag
image.tag(self.image, tag='latest')
except (docker.errors.DockerException, TypeError) as err:
_LOGGER.error("Can't build %s -> %s", build_tag, err)
return False
_LOGGER.info("Build %s done", build_tag)
return True
finally: