Skip to content

Commit

Permalink
Get updates to work for custom apps
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed Aug 8, 2024
1 parent 72007ef commit d26ca06
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
44 changes: 27 additions & 17 deletions src/middlewared/middlewared/plugins/apps/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from middlewared.validators import Match, Range

from .compose_utils import compose_action
from .custom_app_utils import validate_payload
from .ix_apps.lifecycle import add_context_to_values, get_current_app_config, update_app_config
from .ix_apps.metadata import update_app_metadata, update_app_metadata_for_portals
from .ix_apps.path import get_installed_app_path, get_installed_app_version_path
Expand Down Expand Up @@ -157,8 +158,7 @@ def do_create(self, job, data):
raise CallError(f'Application with name {data["app_name"]} already exists', errno=errno.EEXIST)

if data['custom_app']:
self.middleware.call_sync('app.custom.create', data, job)
return
return self.middleware.call_sync('app.custom.create', data, job)

verrors = ValidationErrors()
if not data.get('catalog_app'):
Expand Down Expand Up @@ -232,6 +232,8 @@ def create_internal(
Dict(
'app_update',
Dict('values', additional_attrs=True, private=True),
Dict('custom_compose_config', additional_attrs=True, private=True),
Str('custom_compose_config_string', private=True),
)
)
@job(lock=lambda args: f'app_update_{args[0]}')
Expand All @@ -246,25 +248,33 @@ def do_update(self, job, app_name, data):
@private
def update_internal(self, job, app, data, progress_keyword='Update'):
app_name = app['id']
config = get_current_app_config(app_name, app['version'])
config.update(data['values'])
# We use update=False because we want defaults to be populated again if they are not present in the payload
# Why this is not dangerous is because the defaults will be added only if they are not present/configured for
# the app in question
app_version_details = self.middleware.call_sync(
'catalog.app_version_details', get_installed_app_version_path(app_name, app['version'])
)
if app['custom_app']:
if progress_keyword == 'Update':
new_values = validate_payload(data, 'app_update')
else:
new_values = get_current_app_config(app_name, app['version'])
else:
config = get_current_app_config(app_name, app['version'])
config.update(data['values'])
# We use update=False because we want defaults to be populated again if they are not present in the payload
# Why this is not dangerous is because the defaults will be added only if they are not present/configured
# for the app in question
app_version_details = self.middleware.call_sync(
'catalog.app_version_details', get_installed_app_version_path(app_name, app['version'])
)

new_values = self.middleware.call_sync(
'app.schema.normalize_and_validate_values', app_version_details, config, True,
get_installed_app_path(app_name), app
)
new_values = self.middleware.call_sync(
'app.schema.normalize_and_validate_values', app_version_details, config, True,
get_installed_app_path(app_name), app
)
new_values = add_context_to_values(app_name, new_values, app['metadata'], update=True)

job.set_progress(25, 'Initial Validation completed')

new_values = add_context_to_values(app_name, new_values, app['metadata'], update=True)
update_app_config(app_name, app['version'], new_values)
update_app_metadata_for_portals(app_name, app['version'])
update_app_config(app_name, app['version'], new_values, custom_app=app['custom_app'])
if app['custom_app'] is False:
# TODO: Eventually we would want this to be executed for custom apps as well
update_app_metadata_for_portals(app_name, app['version'])
job.set_progress(60, 'Configuration updated, updating docker resources')
compose_action(app_name, app['version'], 'up', force_recreate=True, remove_orphans=True)

Expand Down
3 changes: 1 addition & 2 deletions src/middlewared/middlewared/plugins/apps/custom_app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import contextlib
import shutil
import yaml

from catalog_reader.custom_app import get_version_details

from middlewared.service import Service, ValidationErrors
from middlewared.service import Service

from .compose_utils import compose_action
from .custom_app_utils import validate_payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def update_app_metadata(
'custom_app': custom_app,
**{k: app_version_details[k] for k in ('version', 'human_version')},
**get_portals_and_app_notes(app_name, app_version_details['version']),
# TODO: We should not try to get portals for custom apps for now
}))


Expand Down

0 comments on commit d26ca06

Please sign in to comment.