diff --git a/deployment/core/tasks.py b/deployment/core/tasks.py index b54ef39..513bd32 100644 --- a/deployment/core/tasks.py +++ b/deployment/core/tasks.py @@ -21,8 +21,13 @@ lua = LuaRuntime(unpack_returned_tuples=True) config_path = self.get_arg("config") + self.print("Reading file: ", config_path) with open(config_path, "r") as f: - cfg = lua.execute(f.read()) + try: + lua_content = f.read() + cfg = lua.execute(lua_content) + except Exception as e: + self.fail("Failed to load deployment config: ", e) # 4. Hydrate self.env self.env.lua_cfg = cfg # Store the lua object for functional calls later @@ -46,6 +51,7 @@ """Verifies TOML existence and hydrates the environment with health check URI components""" _stage = Stage.BOOTSTRAP + _deps = [GetDeploymentConfig] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -118,6 +124,7 @@ """Bypasses the full build to update the current live deployment""" _stage = Stage.DEPLOY + _deps = [GetDeploymentConfig, LoadServerConfig] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -134,7 +141,7 @@ # 2. Pull changes try: self.sh( - "git pull origin " + self.env.deploy_branch, + "sudo -u {self.env.user} git pull origin " + self.env.deploy_branch, cwd=live_path, handle_exception=False, ) @@ -169,10 +176,12 @@ build_git_path = os.path.join(self.env.build_dir, ".git") + self.print("Build git path:", build_git_path) + if os.path.exists(build_git_path): try: self.sh( - f"git pull origin {self.env.deploy_branch}", + f"sudo -u {self.env.user} git pull origin {self.env.deploy_branch}", cwd=self.env.build_dir, handle_exception=False, ) @@ -196,34 +205,6 @@ self.sh("yarn combine:css", cwd=self.env.build_dir) return True -class YarnBuild(SuiteTask): - """Executes dependency installation and asset compilation""" - - _stage = Stage.BUILD - _deps = [GetDeploymentConfig, LoadServerConfig] - skip: bool = False - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.name = "Running Yarn build process" - - def _run(self): - timestamp = time.strftime(self.env.timestamp_format) - self.env.release_dir = f"{Path(self.env.testing.deploy_link)}-{timestamp}" - - self.sh( - f"git clone --branch {self.env.deploy_branch} {self.env.repo} {self.env.build_dir}" - ) - self.sh("git submodule update --init --recursive", cwd=self.env.build_dir) - self.sh("yarn config set enableGlobalCache true", cwd=self.env.build_dir) - self.sh( - f"yarn config set globalFolder {self.env.yarn_path}", cwd=self.env.build_dir - ) - self.sh("yarn config set nodeLinker pnp", cwd=self.env.build_dir) - self.sh("yarn install", cwd=self.env.build_dir) - self.sh("yarn combine:css", cwd=self.env.build_dir) - return True - class AtomicDeploy(SuiteTask): """Performs rsync to release directory and updates environment symlink""" diff --git a/deployment/core/tests.py b/deployment/core/tests.py index 41776f5..ea6feff 100644 --- a/deployment/core/tests.py +++ b/deployment/core/tests.py @@ -4,6 +4,7 @@ from lib.task_types import SuiteTask, SuiteSubTask from lib.types import Stage from core.tasks import YarnBuild +from core.task_runner import TaskRunner class StartTestApp(SuiteSubTask): @@ -23,7 +24,7 @@ self.print(f" [EXEC] Starting app in {self.env.build_dir}") - cmd = f"nohup yarn run prod --config {self.env.testing.config_file} >> '{self.env.test_log}' 2>&1 & echo $! > '{self.env.pidfile}'" + cmd = f"nohup sudo -u {self.env.user} yarn run prod --config {self.env.testing.config_file} >> '{self.env.test_log}' 2>&1 & echo $! > '{self.env.pidfile}'" # This doesn't work because systemd doesnt know where it is yet # cmd=f"sudo systemctl restart {self.env.testing.service_name}", self.sh( @@ -116,9 +117,14 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.name = "Integration Test Runner" - self._sub_tasks = [StartTestApp, WaitForReadiness, RunMochaTests, StopTestApp] + sub_tasks = [StartTestApp, WaitForReadiness, RunMochaTests, StopTestApp] + + runner = TaskRunner(self, owner=self._owner, base_class_name="TestRunner") + runner.queue_tasks(sub_tasks).run() def _run(self): + return + # 1. Check if we should even be here skip_param = self.args.get("skip_tests", False) enforced = self.get_arg("enforce_testing") @@ -142,9 +148,12 @@ self.print(f" [FAIL] Test suite halted at: {task.name}") break + except AttributeError as e: + success = False + self.fail(f" [ERROR] failure during test execution: {e}") except Exception as e: success = False - self.print(f" [ERROR] Critical failure during test execution: {e}") + self.fail(f" [ERROR] Critical failure during test execution: {e}") finally: if self.do_dry_run():