From b9f820cef4b92794899ede4c2ae4c51fb46777ba Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 11 Jan 2024 12:33:28 +0100 Subject: [PATCH 1/2] fix: save cmd output propely (merge) --- app/Traits/ExecuteRemoteCommand.php | 2 +- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Traits/ExecuteRemoteCommand.php b/app/Traits/ExecuteRemoteCommand.php index 6c0dc5d03..10f50e251 100644 --- a/app/Traits/ExecuteRemoteCommand.php +++ b/app/Traits/ExecuteRemoteCommand.php @@ -59,7 +59,7 @@ public function execute_remote_command(...$commands) $this->application_deployment_queue->save(); if ($this->save) { - $this->saved_outputs[$this->save] = Str::of($output)->trim(); + $this->saved_outputs[$this->save] .= Str::of($output)->trim(); } }); $this->application_deployment_queue->update([ diff --git a/config/sentry.php b/config/sentry.php index 4df15f841..c586dba82 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.186', + 'release' => '4.0.0-beta.187', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index be52135e7..8dc7a5d2f 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Thu, 11 Jan 2024 12:56:02 +0100 Subject: [PATCH 2/2] fix: nixpacks envs fix: append logs --- app/Jobs/ApplicationDeploymentJob.php | 34 +++++++++++++++++---------- app/Traits/ExecuteRemoteCommand.php | 13 ++++++++-- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 3999a7fcd..b7534952c 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -72,6 +72,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted private bool $is_debug_enabled; private $build_args; private $env_args; + private $env_nixpacks_args; private $docker_compose; private $docker_compose_base64; private ?string $nixpacks_plan = null; @@ -692,7 +693,8 @@ private function health_check() [ "docker inspect --format='{{json .State.Health.Status}}' {$this->container_name}", "hidden" => true, - "save" => "health_check" + "save" => "health_check", + "append" => false ], ); @@ -854,7 +856,6 @@ private function check_git_if_build_needed() ], ); } - if ($this->saved_outputs->get('git_commit_sha')) { $this->commit = $this->saved_outputs->get('git_commit_sha')->before("\t"); } @@ -910,9 +911,10 @@ private function generate_nixpacks_confs() if ($this->nixpacks_plan) { $parsed = Toml::Parse($this->nixpacks_plan); // Do any modifications here - $cmds = collect(data_get($parsed, 'phases.setup.cmds', [])); + // $cmds = collect(data_get($parsed, 'phases.setup.cmds', [])); $this->generate_env_variables(); - data_set($parsed, 'phases.setup.cmds', $cmds); + // data_set($parsed, 'phases.setup.cmds', $cmds); + ray($this->env_args->toArray()); $merged_envs = $this->env_args->merge(collect(data_get($parsed, 'variables', []))); data_set($parsed, 'variables', $merged_envs->toArray()); $this->nixpacks_plan = json_encode($parsed, JSON_PRETTY_PRINT); @@ -922,7 +924,8 @@ private function generate_nixpacks_confs() private function nixpacks_build_cmd() { - $nixpacks_command = "nixpacks plan -f toml"; + $this->generate_nixpacks_env_variables(); + $nixpacks_command = "nixpacks plan -f toml {$this->env_nixpacks_args}"; if ($this->application->build_command) { $nixpacks_command .= " --build-cmd \"{$this->application->build_command}\""; } @@ -935,26 +938,33 @@ private function nixpacks_build_cmd() $nixpacks_command .= " {$this->workdir}"; return $nixpacks_command; } + private function generate_nixpacks_env_variables() + { + $this->env_nixpacks_args = collect([]); + if ($this->pull_request_id === 0) { + foreach ($this->application->nixpacks_environment_variables as $env) { + $this->env_nixpacks_args->push("--env {$env->key}={$env->value}"); + } + } else { + foreach ($this->application->nixpacks_environment_variables_preview as $env) { + $this->env_nixpacks_args->push("--env {$env->key}={$env->value}"); + } + } + $this->env_nixpacks_args = $this->env_nixpacks_args->implode(' '); + } private function generate_env_variables() { $this->env_args = collect([]); if ($this->pull_request_id === 0) { - foreach ($this->application->nixpacks_environment_variables as $env) { - $this->env_args->put($env->key, $env->value); - } foreach ($this->application->build_environment_variables as $env) { $this->env_args->put($env->key, $env->value); } } else { - foreach ($this->application->nixpacks_environment_variables_preview as $env) { - $this->env_args->put($env->key, $env->value); - } foreach ($this->application->build_environment_variables_preview as $env) { $this->env_args->put($env->key, $env->value); } } - // $this->env_args = $this->env_args->implode(' '); } private function generate_compose_file() diff --git a/app/Traits/ExecuteRemoteCommand.php b/app/Traits/ExecuteRemoteCommand.php index 10f50e251..529dacd7a 100644 --- a/app/Traits/ExecuteRemoteCommand.php +++ b/app/Traits/ExecuteRemoteCommand.php @@ -32,10 +32,11 @@ public function execute_remote_command(...$commands) $hidden = data_get($single_command, 'hidden', false); $customType = data_get($single_command, 'type'); $ignore_errors = data_get($single_command, 'ignore_errors', false); + $append = data_get($single_command, 'append', true); $this->save = data_get($single_command, 'save'); $remote_command = generateSshCommand($this->server, $command); - $process = Process::timeout(3600)->idleTimeout(3600)->start($remote_command, function (string $type, string $output) use ($command, $hidden, $customType) { + $process = Process::timeout(3600)->idleTimeout(3600)->start($remote_command, function (string $type, string $output) use ($command, $hidden, $customType, $append) { $output = Str::of($output)->trim(); if ($output->startsWith('╔')) { $output = "\n" . $output; @@ -59,7 +60,15 @@ public function execute_remote_command(...$commands) $this->application_deployment_queue->save(); if ($this->save) { - $this->saved_outputs[$this->save] .= Str::of($output)->trim(); + if (data_get($this->saved_outputs, $this->save, null) === null) { + data_set($this->saved_outputs, $this->save, str()); + } + if ($append) { + $this->saved_outputs[$this->save] .= str($output)->trim(); + $this->saved_outputs[$this->save] = str($this->saved_outputs[$this->save]); + } else { + $this->saved_outputs[$this->save] = str($output)->trim(); + } } }); $this->application_deployment_queue->update([