done fix
This commit is contained in:
@@ -9,6 +9,7 @@ from app.config import settings
|
||||
from app.core.checksum import sha256_file
|
||||
from app.core.command_runner import CommandRunner
|
||||
from app.core.downloader import Downloader
|
||||
from app.core.docker_installer import DockerInstaller, image_reference
|
||||
from app.core.installer import DebInstaller
|
||||
from app.core.manifest_client import ManifestClient
|
||||
from app.core.manifest_validator import ManifestValidator
|
||||
@@ -99,6 +100,12 @@ class TaskRunner:
|
||||
if component["type"] == "deb" and package_name:
|
||||
self.repository.add_log(task_id, "info", f"Removing package {package_name}")
|
||||
installer.remove_package(package_name, purge=request.purge)
|
||||
elif component["type"] == "docker":
|
||||
container_name = component.get("container_name") or component_id
|
||||
self.repository.add_log(task_id, "info", f"Removing Docker container {container_name}")
|
||||
docker_installer = DockerInstaller(command_runner)
|
||||
docker_installer.ensure_runtime(auto_install=settings.auto_install_docker)
|
||||
docker_installer.remove_container(container_name)
|
||||
else:
|
||||
raise ValueError(f"Unsupported installed component type: {component['type']}")
|
||||
|
||||
@@ -171,14 +178,16 @@ class TaskRunner:
|
||||
component_id,
|
||||
status="running",
|
||||
progress=5,
|
||||
current_step="downloading",
|
||||
current_step="preparing",
|
||||
started_at=utc_now(),
|
||||
)
|
||||
|
||||
if component["type"] != "deb":
|
||||
raise ValueError(f"Unsupported component type in MVP: {component['type']}")
|
||||
|
||||
self._install_deb_component(task_id, manifest["appId"], component)
|
||||
if component["type"] == "deb":
|
||||
self._install_deb_component(task_id, manifest["appId"], component)
|
||||
elif component["type"] == "docker":
|
||||
self._install_docker_component(task_id, manifest["appId"], component)
|
||||
else:
|
||||
raise ValueError(f"Unsupported component type: {component['type']}")
|
||||
|
||||
self.repository.update_task_component(
|
||||
task_id,
|
||||
@@ -196,6 +205,7 @@ class TaskRunner:
|
||||
installer = DebInstaller(command_runner)
|
||||
services = ServiceManager(command_runner)
|
||||
|
||||
self.repository.update_task_component(task_id, component_id, progress=10, current_step="downloading")
|
||||
package_path = downloader.download(component["downloadUrl"])
|
||||
self.repository.update_task_component(task_id, component_id, progress=35, current_step="verifying checksum")
|
||||
actual_sha256 = sha256_file(package_path)
|
||||
@@ -250,6 +260,32 @@ class TaskRunner:
|
||||
|
||||
self.repository.upsert_installed_component(app_id, component)
|
||||
|
||||
def _install_docker_component(self, task_id: str, app_id: str, component: dict[str, Any]) -> None:
|
||||
component_id = component["componentId"]
|
||||
container_name = component["containerName"]
|
||||
reference = image_reference(component)
|
||||
command_runner = CommandRunner(self.repository, task_id)
|
||||
installer = DockerInstaller(command_runner)
|
||||
|
||||
self.repository.update_task_component(task_id, component_id, progress=15, current_step="checking Docker runtime")
|
||||
installer.ensure_runtime(auto_install=settings.auto_install_docker)
|
||||
|
||||
self.repository.update_task_component(task_id, component_id, progress=35, current_step="pulling image")
|
||||
self.repository.add_log(task_id, "info", f"Pulling Docker image {reference}")
|
||||
installer.pull_image(reference)
|
||||
|
||||
self.repository.update_task_component(task_id, component_id, progress=70, current_step="recreating container")
|
||||
self.repository.add_log(task_id, "info", f"Recreating Docker container {container_name}")
|
||||
installer.recreate_container(app_id, component)
|
||||
|
||||
self.repository.update_task_component(task_id, component_id, progress=90, current_step="verifying container")
|
||||
installer.assert_container_running(container_name)
|
||||
self.repository.add_log(task_id, "info", f"Docker container {container_name} is running")
|
||||
|
||||
installed_component = dict(component)
|
||||
installed_component["image"] = reference
|
||||
self.repository.upsert_installed_component(app_id, installed_component)
|
||||
|
||||
def _mark_started(self, task_id: str, step: str) -> None:
|
||||
self.repository.update_task(
|
||||
task_id,
|
||||
@@ -261,12 +297,24 @@ class TaskRunner:
|
||||
self.repository.add_log(task_id, "info", step)
|
||||
|
||||
def _fail_task(self, task_id: str, error: Exception) -> None:
|
||||
task = self.repository.get_task(task_id)
|
||||
component_id = task.get("current_component_id") if task else None
|
||||
finished_at = utc_now()
|
||||
if component_id:
|
||||
self.repository.update_task_component(
|
||||
task_id,
|
||||
component_id,
|
||||
status="failed",
|
||||
current_step="failed",
|
||||
error_message=str(error),
|
||||
finished_at=finished_at,
|
||||
)
|
||||
self.repository.update_task(
|
||||
task_id,
|
||||
status="failed",
|
||||
current_step="failed",
|
||||
error_message=str(error),
|
||||
finished_at=utc_now(),
|
||||
finished_at=finished_at,
|
||||
)
|
||||
self.repository.add_log(task_id, "error", str(error))
|
||||
self.repository.add_log(task_id, "debug", traceback.format_exc())
|
||||
|
||||
Reference in New Issue
Block a user