Merge pull request !2954 from rhodecode-enterprise-ce feature/update_via_ui

Changes from branch: Feature/update via ui
This commit is contained in:
Andrii Verbytskyi 2026-01-27 15:55:39 +00:00
commit 144e4a8ab1
5 changed files with 228 additions and 0 deletions

View file

@ -209,6 +209,15 @@ def admin_routes(config):
renderer="rhodecode:templates/admin/settings/settings_system_update.mako",
)
config.add_route(name="settings_system_info_rcstack_update", pattern="/settings/system/rcstack/update")
config.add_view(
AdminSystemInfoSettingsView,
attr="settings_system_info_rcstack_update",
route_name="settings_system_info_rcstack_update",
request_method="GET",
renderer="rhodecode:templates/admin/settings/settings_system_update.mako",
)
config.add_route(name="admin_settings_exception_tracker", pattern="/settings/exceptions")
config.add_view(
ExceptionsTrackerView,

View file

@ -0,0 +1,38 @@
import logging
import os
import requests
from rhodecode.lib.type_utils import str2bool
class RcStackUpdateService:
class State:
READY = "ready"
PROCESSING = "processing"
def __init__(self, server_host: str, server_port: int):
self.host = server_host
self.port = server_port
self.log = logging.getLogger(__name__)
def feature_available(self):
if str2bool(os.environ.get("DISABLE_RC_UPDATE_SERVICE", "false")) or self.host is None:
return False
try:
self.get_state()
return True
except Exception as e:
self.log.error(f"Server on host machine not available, error: {e}")
return False
def get_state(self):
url_base = f"http://{self.host}:{self.port}"
url = f"{url_base}/state"
return requests.get(url).json().get("state", None)
def rcstack_update(self):
url_base = f"http://{self.host}:{self.port}"
url = f"{url_base}/rcstack/update"
return requests.get(url).json()

View file

@ -22,9 +22,12 @@ import urllib.error
import urllib.parse
import os
from pyramid.httpexceptions import HTTPFound
import rhodecode
from rhodecode.apps._base import BaseAppView
from rhodecode.apps._base.navigation import navigation_list
from rhodecode.apps.admin.update_service import RcStackUpdateService
from rhodecode.lib import helpers as h
from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
from rhodecode.lib.utils2 import str2bool
@ -112,6 +115,22 @@ class AdminSystemInfoSettingsView(BaseAppView):
update_state = (
{"type": "warning", "message": "New version available: {}".format(version)} if is_outdated else {}
)
update_service = self._get_rc_update_service()
update_feature_available = update_service.feature_available()
update_literal = ""
if update_feature_available:
update_service_state = update_service.get_state()
if update_service_state == RcStackUpdateService.State.READY:
update_literal = '<br/> <span class="link" id="rcstack_update" >%s.</span>' % (
_("Update Rhodecode to latest version")
)
else:
update_literal = "<br/> <span>%s.</span>" % (
_("Update in progress, please wait. You can check logs on the host machine")
)
c.data_items = [
# update info
(
@ -119,6 +138,7 @@ class AdminSystemInfoSettingsView(BaseAppView):
h.literal(
'<span class="link" id="check_for_update" >%s.</span>' % (_("Check for updates"))
+ "<br/> <span >%s.</span>" % (update_info_msg)
+ update_literal
),
"",
),
@ -206,6 +226,22 @@ class AdminSystemInfoSettingsView(BaseAppView):
h.flash("You are not allowed to do this", category="warning")
return self._get_template_context(c)
@LoginRequired()
@HasPermissionAllDecorator("hg.admin")
def settings_system_info_rcstack_update(self):
update_service = self._get_rc_update_service()
update_feature_available = update_service.feature_available()
if update_feature_available:
response = update_service.rcstack_update()
log.debug(f"update server response: {response}")
return HTTPFound(h.route_path("admin_settings_system"))
def _get_rc_update_service(self) -> RcStackUpdateService:
host = os.environ.get("RC_UPDATE_HOST", None)
port = os.environ.get("RC_UPDATE_PORT", 10025)
return RcStackUpdateService(server_host=host, server_port=port)
@LoginRequired()
@HasPermissionAllDecorator("hg.admin")
def settings_system_info_check_update(self):

View file

@ -100,4 +100,7 @@
$('#update_notice').show();
$('#update_notice').load("${h.route_path('admin_settings_system_update', _query={'ver': request.GET.get('ver')})}");
})
$('#rcstack_update').on('click', function(e){
window.location.href = "${h.route_path('settings_system_info_rcstack_update')}";
})
</script>