mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-10 02:36:29 +00:00
Add cleanup
This commit is contained in:
parent
454d82d985
commit
c9876988da
@ -14,6 +14,7 @@ HOMEASSISTANT_CURRENT = 'homeassistant_current'
|
|||||||
|
|
||||||
HASSIO_SSL = "{}/ssl"
|
HASSIO_SSL = "{}/ssl"
|
||||||
HASSIO_CURRENT = 'hassio_current'
|
HASSIO_CURRENT = 'hassio_current'
|
||||||
|
HASSIO_CLEANUP = 'hassio_cleanup'
|
||||||
|
|
||||||
ADDONS_REPO = "{}/addons"
|
ADDONS_REPO = "{}/addons"
|
||||||
ADDONS_DATA = "{}/addons_data"
|
ADDONS_DATA = "{}/addons_data"
|
||||||
@ -87,6 +88,20 @@ class CoreConfig(Config):
|
|||||||
"""Set beta upstream mode."""
|
"""Set beta upstream mode."""
|
||||||
self._data[UPSTREAM_BETA] = bool(value)
|
self._data[UPSTREAM_BETA] = bool(value)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cleanup_hassio(self):
|
||||||
|
"""Return Version they need to cleanup."""
|
||||||
|
return self._data.get(HASSIO_CLEANUP)
|
||||||
|
|
||||||
|
@cleanup_hassio.setter
|
||||||
|
def cleanup_hassio(self, version):
|
||||||
|
"""Set or remove cleanup flag."""
|
||||||
|
if version is None:
|
||||||
|
self._data.pop(HASSIO_CLEANUP, None)
|
||||||
|
else:
|
||||||
|
self._data[HASSIO_CLEANUP] = version
|
||||||
|
self.save()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def homeassistant_image(self):
|
def homeassistant_image(self):
|
||||||
"""Return docker homeassistant repository."""
|
"""Return docker homeassistant repository."""
|
||||||
|
@ -50,6 +50,7 @@ class HassIO(object):
|
|||||||
"""Setup HassIO orchestration."""
|
"""Setup HassIO orchestration."""
|
||||||
# supervisor
|
# supervisor
|
||||||
await self.supervisor.attach()
|
await self.supervisor.attach()
|
||||||
|
await self.supervisor.cleanup()
|
||||||
|
|
||||||
# hostcontroll
|
# hostcontroll
|
||||||
host_info = await self.host_controll.info()
|
host_info = await self.host_controll.info()
|
||||||
|
@ -209,10 +209,7 @@ class DockerBase(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
async def update(self, tag):
|
async def update(self, tag):
|
||||||
"""Update a docker image.
|
"""Update a docker image."""
|
||||||
|
|
||||||
Return a Future.
|
|
||||||
"""
|
|
||||||
if self._lock.locked():
|
if self._lock.locked():
|
||||||
_LOGGER.error("Can't excute update while a task is in progress")
|
_LOGGER.error("Can't excute update while a task is in progress")
|
||||||
return False
|
return False
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Init file for HassIO docker object."""
|
"""Init file for HassIO docker object."""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import docker
|
||||||
|
|
||||||
from . import DockerBase
|
from . import DockerBase
|
||||||
|
|
||||||
|
|
||||||
@ -19,27 +21,43 @@ class DockerSupervisor(DockerBase):
|
|||||||
return os.environ['SUPERVISOR_NAME']
|
return os.environ['SUPERVISOR_NAME']
|
||||||
|
|
||||||
async def update(self, tag):
|
async def update(self, tag):
|
||||||
"""Update a supervisor docker image.
|
"""Update a supervisor docker image."""
|
||||||
|
|
||||||
Return a Future.
|
|
||||||
"""
|
|
||||||
if self._lock.locked():
|
if self._lock.locked():
|
||||||
_LOGGER.error("Can't excute update while a task is in progress")
|
_LOGGER.error("Can't excute update while a task is in progress")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
_LOGGER.info("Update supervisor docker to %s:%s", self.image, tag)
|
||||||
|
old_version = self.version
|
||||||
|
|
||||||
async with self._lock:
|
async with self._lock:
|
||||||
if await self.loop.run_in_executor(None, self._update, tag):
|
if await self.loop.run_in_executor(None, self._install, tag):
|
||||||
|
self.config.hassio_cleanup = old_version
|
||||||
self.loop.create_task(self.hassio.stop(RESTART_EXIT_CODE))
|
self.loop.create_task(self.hassio.stop(RESTART_EXIT_CODE))
|
||||||
|
|
||||||
def _update(self, tag):
|
async def cleanup(self):
|
||||||
"""Update a docker image.
|
"""Check if old supervisor version exists and cleanup."""
|
||||||
|
if not self.config.hassio_cleanup:
|
||||||
|
return
|
||||||
|
|
||||||
|
async with self._lock:
|
||||||
|
if await self.loop.run_in_executor(None, self._cleanup):
|
||||||
|
self.config.hassio_cleanup = None
|
||||||
|
|
||||||
|
def _cleanup(self):
|
||||||
|
"""Remove old image.
|
||||||
|
|
||||||
Need run inside executor.
|
Need run inside executor.
|
||||||
"""
|
"""
|
||||||
_LOGGER.info("Update supervisor docker to %s:%s", self.image, tag)
|
old_image = "{}:{}".format(self.image, self.config.hassio_cleanup)
|
||||||
|
|
||||||
# update docker image
|
_LOGGER.info("Old supervisor docker found %s", old_image)
|
||||||
return self._install(tag)
|
try:
|
||||||
|
self.dock.images.remove(image=old_image, force=True)
|
||||||
|
except docker.errors.DockerException as err:
|
||||||
|
_LOGGER.warning("Can't remove old image %s -> %s", old_image, err)
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
"""Run docker image."""
|
"""Run docker image."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user