Skip to content

Commit

Permalink
Make checking image updates configurable again (#14175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 authored Aug 9, 2024
1 parent 65639d2 commit 8aef5ec
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 15 additions & 7 deletions src/middlewared/middlewared/plugins/docker/update.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand All @@ -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),
Expand Down Expand Up @@ -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'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8aef5ec

Please sign in to comment.