Build Debian packages and apply upgrades through APT
This commit is contained in:
1 parent
e240cbc64f
commit
2d6ac5ac43
13 files changed
+290
-10
No files matched your search
@@ -17,7 +17,9 @@
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endif %}
|
||||
{% if not updater_enabled %}
|
||||
{% if apt_managed %}
|
||||
<section class="surface"><p class="empty">This panel is managed by APT. Apply Coulobre package updates from the server console.</p></section>
|
||||
{% elif not updater_enabled %}
|
||||
<section class="surface"><p class="empty">Enable the local updater socket on an installer-managed panel to use web updates.</p></section>
|
||||
{% elif catalog_problem %}
|
||||
<section class="surface"><p class="empty">{{ catalog_problem }}</p></section>
|
||||
|
||||
@@ -89,6 +89,9 @@ class UpdateView(UserPassesTestMixin, FormView):
|
||||
context["update_status"] = topology.get("status", {})
|
||||
context["linked_nodes"] = nodes
|
||||
context["preflight_problem"] = topology.get("problem")
|
||||
context["apt_managed"] = topology.get("apt_managed", False)
|
||||
if context["apt_managed"]:
|
||||
return context
|
||||
try:
|
||||
context["releases"] = cache.get_or_set(
|
||||
f"coulobre-updates:{installed}",
|
||||
|
||||
@@ -18,6 +18,7 @@ from tempfile import TemporaryDirectory
|
||||
from .linked_updates import linked_roles, receiver_status, staged_for_release
|
||||
from .release_updates import (
|
||||
SHA256,
|
||||
Release,
|
||||
UpdateError,
|
||||
download_wheel,
|
||||
selected_release,
|
||||
@@ -57,6 +58,7 @@ MANAGED_UNITS = frozenset(
|
||||
"coulobre-offsite-worker.service",
|
||||
"coulobre-operator-apply.socket",
|
||||
"coulobre-operator-worker.service",
|
||||
"coulobre-remote-deploy.socket",
|
||||
"coulobre-folder-sftp.socket",
|
||||
"coulobre-provisioner.service",
|
||||
"coulobre-service-credentials.socket",
|
||||
@@ -73,6 +75,7 @@ VENV = Path("/opt/coulobre")
|
||||
PYTHON = VENV / "bin/python"
|
||||
CONFIG = Path("/etc/coulobre/panel.env")
|
||||
INSTALLATION = Path("/var/lib/coulobre-installer/installation.json")
|
||||
DEB_WHEEL = Path("/usr/share/coulobre-panel/wheel")
|
||||
ROOT_COMMAND_ENV = {
|
||||
"PATH": "/usr/sbin:/usr/bin:/sbin:/bin",
|
||||
"LC_ALL": "C.UTF-8",
|
||||
@@ -319,7 +322,7 @@ def check_dependencies(wheel, log):
|
||||
) from None
|
||||
|
||||
|
||||
def apply_update(status, request, hostname):
|
||||
def apply_update(status, request, hostname, *, package_wheel=None):
|
||||
backup = STATE / datetime.now(UTC).strftime("recovery-%Y%m%dT%H%M%S%fZ")
|
||||
backup.mkdir(mode=0o700)
|
||||
status["recovery"] = backup.name
|
||||
@@ -330,13 +333,17 @@ def apply_update(status, request, hostname):
|
||||
TemporaryDirectory(dir=STATE) as download,
|
||||
):
|
||||
try:
|
||||
release = selected_release(
|
||||
request["version"],
|
||||
status["installed_version"],
|
||||
request["sha256"],
|
||||
)
|
||||
publish_status(status, "running", "Verifying the release package.")
|
||||
wheel = download_wheel(release, download)
|
||||
if package_wheel is None:
|
||||
release = selected_release(
|
||||
request["version"],
|
||||
status["installed_version"],
|
||||
request["sha256"],
|
||||
)
|
||||
wheel = download_wheel(release, download)
|
||||
else:
|
||||
release = Release(request["version"], "", False, "")
|
||||
wheel = package_wheel
|
||||
check_dependencies(wheel, log)
|
||||
check_installation(release.version)
|
||||
active = active_units(log)
|
||||
@@ -496,8 +503,16 @@ def handle_request(peer):
|
||||
problem=str(error),
|
||||
)
|
||||
else:
|
||||
reply(peer, accepted=True, status=display_status(), nodes=nodes)
|
||||
reply(
|
||||
peer,
|
||||
accepted=True,
|
||||
status=display_status(),
|
||||
nodes=nodes,
|
||||
apt_managed=DEB_WHEEL.is_dir(),
|
||||
)
|
||||
return
|
||||
if DEB_WHEEL.is_dir():
|
||||
raise UpdateError("Upgrade this APT-managed panel from the host.")
|
||||
with LOCK.open("a") as lock:
|
||||
try:
|
||||
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
|
||||
@@ -132,6 +132,14 @@ def packages(request):
|
||||
raise ValueError(
|
||||
"Review this package update from the server console."
|
||||
)
|
||||
if any(
|
||||
line.split()[1:2] == ["coulobre-panel"]
|
||||
or line.startswith("Inst coulobre-panel:")
|
||||
for line in plan["packages"]
|
||||
):
|
||||
raise ValueError(
|
||||
"Apply Coulobre package updates from the server console."
|
||||
)
|
||||
if plan["count"]:
|
||||
command(
|
||||
APT,
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
"""Apply the packaged wheel using the panel recovery workflow."""
|
||||
|
||||
import fcntl
|
||||
import os
|
||||
from importlib.metadata import version
|
||||
|
||||
from . import local_update
|
||||
from .release_updates import UpdateError, version_key, wheel_name
|
||||
|
||||
PREFIX = "coulobre_panel-"
|
||||
SUFFIX = "-py3-none-any.whl"
|
||||
|
||||
|
||||
def upgrade_package():
|
||||
if os.geteuid() != 0:
|
||||
raise UpdateError("Run the package upgrade as root.")
|
||||
directory = local_update.DEB_WHEEL
|
||||
wheels = list(directory.glob(f"{PREFIX}*{SUFFIX}"))
|
||||
if len(wheels) != 1 or not all(
|
||||
local_update.root_controlled(path)
|
||||
for path in (directory.parent, directory, *wheels)
|
||||
):
|
||||
raise UpdateError("The packaged release wheel is unavailable.")
|
||||
wheel = wheels[0]
|
||||
target = wheel.name.removeprefix(PREFIX).removesuffix(SUFFIX)
|
||||
if wheel_name(target) != wheel.name or not wheel.is_file():
|
||||
raise UpdateError("The packaged release wheel is invalid.")
|
||||
state = local_update.STATE
|
||||
state.mkdir(mode=0o700, exist_ok=True)
|
||||
if not local_update.root_controlled(state):
|
||||
raise UpdateError("The upgrade state directory is not protected.")
|
||||
with local_update.LOCK.open("a") as lock:
|
||||
os.fchmod(lock.fileno(), 0o600)
|
||||
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
if local_update.read_status().get("state") in {
|
||||
"running",
|
||||
"recovery_required",
|
||||
}:
|
||||
raise UpdateError("Resolve the previous update before retrying.")
|
||||
installed = version("coulobre-panel")
|
||||
if installed == target:
|
||||
return
|
||||
if version_key(installed) >= version_key(target):
|
||||
raise UpdateError("Use the recovery procedure to downgrade.")
|
||||
hostname = local_update.check_installation(target)
|
||||
status = {
|
||||
"installed_version": installed,
|
||||
"target_version": target,
|
||||
"actor": "APT",
|
||||
}
|
||||
local_update.apply_update(
|
||||
status, {"version": target}, hostname, package_wheel=wheel
|
||||
)
|
||||
if status.get("state") != "succeeded":
|
||||
raise UpdateError(
|
||||
status.get("message", "The package upgrade failed.")
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
upgrade_package()
|
||||
except (OSError, UpdateError) as error:
|
||||
raise SystemExit(str(error)) from None
|
||||
Reference in new issue
Block a user