Allow moving registry for supervisor (#1667)

* Allow moving registry for supervisor

* fix

* Filter number
This commit is contained in:
Pascal Vizeli 2020-04-21 16:59:28 +02:00 committed by GitHub
parent 0f4810d41f
commit c2cfc0d3d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -77,3 +77,30 @@ class DockerSupervisor(DockerInterface, CoreSysAttributes):
except docker.errors.DockerException as err:
_LOGGER.error("Can't retag supervisor version: %s", err)
raise DockerAPIError() from None
def update_start_tag(self, image: str, version: str) -> Awaitable[None]:
"""Update start tag to new version."""
return self.sys_run_in_executor(self._update_start_tag, image, version)
def _update_start_tag(self, image: str, version: str) -> None:
"""Update start tag to new version.
Need run inside executor.
"""
try:
docker_container = self.sys_docker.containers.get(self.name)
docker_image = self.sys_docker.images.get(f"{image}:{version}")
# Find start tag
for tag in docker_container.image.tags:
start_image = tag.partition(":")[0]
start_tag = tag.partition(":")[2] or "latest"
# If version tag
if start_tag.isdigit():
continue
docker_image.tag(start_image, start_tag)
except docker.errors.DockerException as err:
_LOGGER.error("Can't fix start tag: %s", err)
raise DockerAPIError() from None

View File

@ -116,7 +116,10 @@ class Supervisor(CoreSysAttributes):
_LOGGER.info("Update Supervisor to version %s", version)
try:
await self.instance.install(
version, image=self.sys_updater.image_supervisor, latest=True
version, image=self.sys_updater.image_supervisor
)
await self.instance.update_start_tag(
self.sys_updater.image_supervisor, version
)
except DockerAPIError:
_LOGGER.error("Update of Supervisor fails!")