feature: integrated update service to CE

This commit is contained in:
ievgenii vdovenko 2026-01-25 13:57:44 +01:00
parent ad3ae1737e
commit bb1bac5a77
5 changed files with 89 additions and 17 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,20 @@ 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 RcStack"))
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 +136,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 +224,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):