diff --git a/src/middlewared/middlewared/alembic/versions/24.10/2024-08-09_14-35_image_update.py b/src/middlewared/middlewared/alembic/versions/24.10/2024-08-09_14-35_image_update.py new file mode 100644 index 0000000000000..da39f1bd2998a --- /dev/null +++ b/src/middlewared/middlewared/alembic/versions/24.10/2024-08-09_14-35_image_update.py @@ -0,0 +1,25 @@ +""" +Add flag to see if image update is requried + +Revision ID: 4b0b7ba46e63 +Revises: 81b8bae8fb11 +Create Date: 2024-08-09 14:35:35.379137+00:00 + +""" +from alembic import op +import sqlalchemy as sa + + +revision = '4b0b7ba46e63' +down_revision = '81b8bae8fb11' +branch_labels = None +depends_on = None + + +def upgrade(): + with op.batch_alter_table('services_docker', schema=None) as batch_op: + batch_op.add_column(sa.Column('enable_image_updates', sa.Boolean(), nullable=False, server_default='1')) + + +def downgrade(): + pass diff --git a/src/middlewared/middlewared/plugins/docker/state_management.py b/src/middlewared/middlewared/plugins/docker/state_management.py index 4f01c194d0e37..7163eeea962d7 100644 --- a/src/middlewared/middlewared/plugins/docker/state_management.py +++ b/src/middlewared/middlewared/plugins/docker/state_management.py @@ -95,8 +95,10 @@ async def periodic_check(self): await (await self.middleware.call('catalog.sync')).wait() - await self.middleware.call('app.image.op.check_update') - # TODO: Add app upgrade alerts and account for update image check + docker_config = await self.middleware.call('docker.config') + if docker_config['enable_image_updates']: + self.middleware.create_task(self.middleware.call('app.image.op.check_update')) + # TODO: Add app upgrade alerts async def _event_system_ready(middleware, event_type, args): diff --git a/src/middlewared/middlewared/plugins/docker/update.py b/src/middlewared/middlewared/plugins/docker/update.py index a1bc882e372bd..c888b52dd8437 100644 --- a/src/middlewared/middlewared/plugins/docker/update.py +++ b/src/middlewared/middlewared/plugins/docker/update.py @@ -1,6 +1,6 @@ import middlewared.sqlalchemy as sa -from middlewared.schema import accepts, Dict, Int, Patch, Str +from middlewared.schema import accepts, Bool, Dict, Int, Patch, Str from middlewared.service import CallError, ConfigService, job, private, returns from .state_utils import Status @@ -12,6 +12,7 @@ class DockerModel(sa.Model): id = sa.Column(sa.Integer(), primary_key=True) pool = sa.Column(sa.String(255), default=None, nullable=True) + enable_image_updates = sa.Column(sa.Boolean(), default=True) class DockerService(ConfigService): @@ -24,6 +25,7 @@ class Config: ENTRY = Dict( 'docker_entry', + Bool('enable_image_updates', required=True), Int('id', required=True), Str('dataset', required=True), Str('pool', required=True, null=True), @@ -54,16 +56,22 @@ async def do_update(self, job, data): config.update(data) if old_config != config: - try: - await self.middleware.call('service.stop', 'docker') - except Exception as e: - raise CallError(f'Failed to stop docker service: {e}') + if config['pool'] != old_config['pool']: + job.set_progress(20, 'Stopping Docker service') + try: + await self.middleware.call('service.stop', 'docker') + except Exception as e: + raise CallError(f'Failed to stop docker service: {e}') - await self.middleware.call('docker.state.set_status', Status.UNCONFIGURED.value) + await self.middleware.call('docker.state.set_status', Status.UNCONFIGURED.value) await self.middleware.call('datastore.update', self._config.datastore, old_config['id'], config) - await self.middleware.call('docker.setup.status_change') + if config['pool'] != old_config['pool']: + job.set_progress(60, 'Applying requested configuration') + await self.middleware.call('docker.setup.status_change') + + job.set_progress(100, 'Requested configuration applied') return await self.config() @accepts(roles=['DOCKER_READ']) diff --git a/src/middlewared/middlewared/plugins/service_/services/docker.py b/src/middlewared/middlewared/plugins/service_/services/docker.py index 81052a7e1d5ea..3aa6ff23f18bb 100644 --- a/src/middlewared/middlewared/plugins/service_/services/docker.py +++ b/src/middlewared/middlewared/plugins/service_/services/docker.py @@ -62,6 +62,8 @@ async def after_start(self): await self.middleware.call('docker.state.set_status', Status.RUNNING.value) self.middleware.create_task(self.middleware.call('docker.events.setup')) await self.middleware.call('catalog.sync') + if (await self.middleware.call('docker.config'))['enable_image_updates']: + self.middleware.create_task(self.middleware.call('app.image.op.check_update')) async def before_stop(self): await self.middleware.call('docker.state.set_status', Status.STOPPING.value)