diff --git a/supervisor/config.py b/supervisor/config.py index 47d65c799..400cd50ae 100644 --- a/supervisor/config.py +++ b/supervisor/config.py @@ -14,6 +14,7 @@ from .const import ( ATTR_DEBUG_BLOCK, ATTR_DIAGNOSTICS, ATTR_FORCE_SECURITY, + ATTR_IMAGE, ATTR_LAST_BOOT, ATTR_LOGGING, ATTR_TIMEZONE, @@ -69,14 +70,24 @@ class CoreConfig(FileConfiguration): @property def version(self) -> AwesomeVersion: - """Return config version.""" + """Return supervisor version.""" return self._data[ATTR_VERSION] @version.setter def version(self, value: AwesomeVersion) -> None: - """Set config version.""" + """Set supervisor version.""" self._data[ATTR_VERSION] = value + @property + def image(self) -> Optional[str]: + """Return supervisor image.""" + return self._data.get(ATTR_IMAGE) + + @image.setter + def image(self, value: str) -> None: + """Set supervisor image.""" + self._data[ATTR_IMAGE] = value + @property def wait_boot(self) -> int: """Return wait time for auto boot stages.""" diff --git a/supervisor/docker/interface.py b/supervisor/docker/interface.py index 767bec278..bbcea5a92 100644 --- a/supervisor/docker/interface.py +++ b/supervisor/docker/interface.py @@ -467,6 +467,9 @@ class DockerInterface(CoreSysAttributes): raise DockerError() from err for image in images_list: + if origin.id == image.id: + continue + with suppress(docker.errors.DockerException, requests.RequestException): _LOGGER.info("Cleanup images: %s", image.tags) self.sys_docker.images.remove(image.id, force=True) diff --git a/supervisor/docker/supervisor.py b/supervisor/docker/supervisor.py index 3316e44b3..bb5bb3cba 100644 --- a/supervisor/docker/supervisor.py +++ b/supervisor/docker/supervisor.py @@ -102,6 +102,7 @@ class DockerSupervisor(DockerInterface, CoreSysAttributes): if start_tag != "latest": continue docker_image.tag(start_image, start_tag) + docker_image.tag(start_image, version.string) except (docker.errors.DockerException, requests.RequestException) as err: _LOGGER.error("Can't fix start tag: %s", err) diff --git a/supervisor/supervisor.py b/supervisor/supervisor.py index e94a2d20b..244f0f31e 100644 --- a/supervisor/supervisor.py +++ b/supervisor/supervisor.py @@ -46,7 +46,7 @@ class Supervisor(CoreSysAttributes): _LOGGER.critical("Can't setup Supervisor Docker container!") with suppress(DockerError): - await self.instance.cleanup() + await self.instance.cleanup(old_image=self.sys_config.image) @property def connectivity(self) -> bool: @@ -161,6 +161,7 @@ class Supervisor(CoreSysAttributes): raise SupervisorUpdateError() from err else: self.sys_config.version = version + self.sys_config.image = self.sys_updater.image_supervisor self.sys_config.save_data() self.sys_create_task(self.sys_core.stop()) diff --git a/supervisor/validate.py b/supervisor/validate.py index 8481c051b..2868c671f 100644 --- a/supervisor/validate.py +++ b/supervisor/validate.py @@ -140,6 +140,7 @@ SCHEMA_SUPERVISOR_CONFIG = vol.Schema( vol.Optional( ATTR_VERSION, default=AwesomeVersion(SUPERVISOR_VERSION) ): version_tag, + vol.Optional(ATTR_IMAGE): docker_image, vol.Optional( ATTR_ADDONS_CUSTOM_LIST, default=["https://github.com/hassio-addons/repository"],