An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
Merge branch 'v4.x' of https://github.com/ahmadw13/coolify into v4.x
Ahmed A5eacb01bebd4
diff --cc app/Traits/ExecuteRemoteCommand.phpindex 2890842665,3b88c3f16c..40edd65dd6--- a/app/Traits/ExecuteRemoteCommand.php+++ b/app/Traits/ExecuteRemoteCommand.php@@@ -45,111 -43,74 +45,61 @@@ trait ExecuteRemoteComman$command = parseLineForSudo($command, $this->server);}}-- $maxRetries = config('constants.ssh.max_retries');- $attempt = 0;- $lastError = null;- $commandExecuted = false;-- while ($attempt < $maxRetries && ! $commandExecuted) {- try {- $this->executeCommandWithProcess($command, $hidden, $customType, $append, $ignore_errors);- $commandExecuted = true;- } catch (\RuntimeException $e) {- $lastError = $e;- $errorMessage = $e->getMessage();- // Only retry if it's an SSH connection error and we haven't exhausted retries- if ($this->isRetryableSshError($errorMessage) && $attempt < $maxRetries - 1) {- $attempt++;- $delay = $this->calculateRetryDelay($attempt - 1);-- // Track SSH retry event in Sentry- $this->trackSshRetryEvent($attempt, $maxRetries, $delay, $errorMessage, [- 'server' => $this->server->name ?? $this->server->ip ?? 'unknown',- 'command' => remove_iip($command),- 'trait' => 'ExecuteRemoteCommand',- ]);-- // Add log entry for the retry- if (isset($this->application_deployment_queue)) {- $this->addRetryLogEntry($attempt, $maxRetries, $delay, $errorMessage);- }-- sleep($delay);- } else {- // Not retryable or max retries reached- throw $e;- }+ $remote_command = SshMultiplexingHelper::generateSshCommand($this->server, $command);+ $process = Process::timeout(config('constants.ssh.command_timeout'))->idleTimeout(3600)->start($remote_command, function (string $type, string $output) use ($command, $hidden, $customType, $append) {+ $output = str($output)->trim();+ if ($output->startsWith('╔')) {+ $output = "\n".$output;}- }-- // If we exhausted all retries and still failed- if (! $commandExecuted && $lastError) {- throw $lastError;- }- });- }-- /**- * Execute the actual command with process handling- */- private function executeCommandWithProcess($command, $hidden, $customType, $append, $ignore_errors)- {- $remote_command = SshMultiplexingHelper::generateSshCommand($this->server, $command);- $process = Process::timeout(config('constants.ssh.command_timeout'))->idleTimeout(3600)->start($remote_command, function (string $type, string $output) use ($command, $hidden, $customType, $append) {- $output = str($output)->trim();- if ($output->startsWith('╔')) {- $output = "\n".$output;- }- // Sanitize output to ensure valid UTF-8 encoding before JSON encoding- $sanitized_output = sanitize_utf8_text($output);-- $new_log_entry = [- 'command' => remove_iip($command),- 'output' => remove_iip($sanitized_output),- 'type' => $customType ?? $type === 'err' ? 'stderr' : 'stdout',- 'timestamp' => Carbon::now('UTC'),- 'hidden' => $hidden,- 'batch' => static::$batch_counter,- ];- if (! $this->application_deployment_queue->logs) {- $new_log_entry['order'] = 1;- } else {- try {- $previous_logs = json_decode($this->application_deployment_queue->logs, associative: true, flags: JSON_THROW_ON_ERROR);- } catch (\JsonException $e) {- // If existing logs are corrupted, start fresh- $previous_logs = [];- $new_log_entry['order'] = 1;- }- if (is_array($previous_logs)) {- $new_log_entry['order'] = count($previous_logs) + 1;- } else {- $previous_logs = [];- $new_log_entry['order'] = 1;- }- }- $previous_logs[] = $new_log_entry;+ // Sanitize output to ensure valid UTF-8 encoding before JSON encoding+ $sanitized_output = sanitize_utf8_text($output);+ $new_log_entry = [+ 'command' => remove_iip($command),+ 'output' => remove_iip($sanitized_output),+ 'type' => $customType ?? $type === 'err' ? 'stderr' : 'stdout',+ 'timestamp' => Carbon::now('UTC'),+ 'hidden' => $hidden,+ 'batch' => static::$batch_counter,+ ];+ if (! $this->application_deployment_queue->logs) {+ $new_log_entry['order'] = 1;+ } else {try {- $this->application_deployment_queue->logs = json_encode($previous_logs, flags: JSON_THROW_ON_ERROR);+ $previous_logs = json_decode($this->application_deployment_queue->logs, associative: true, flags: JSON_THROW_ON_ERROR);} catch (\JsonException $e) {- // If JSON encoding still fails, use fallback with invalid sequences replacement- $this->application_deployment_queue->logs = json_encode($previous_logs, flags: JSON_INVALID_UTF8_SUBSTITUTE);+ // If existing logs are corrupted, start fresh+ $previous_logs = [];+ $new_log_entry['order'] = 1;+ }+ if (is_array($previous_logs)) {+ $new_log_entry['order'] = count($previous_logs) + 1;+ } else {+ $previous_logs = [];+ $new_log_entry['order'] = 1;}+ }+ $previous_logs[] = $new_log_entry;- $this->application_deployment_queue->save();+ try {+ $this->application_deployment_queue->logs = json_encode($previous_logs, flags: JSON_THROW_ON_ERROR);+ } catch (\JsonException $e) {+ // If JSON encoding still fails, use fallback with invalid sequences replacement+ $this->application_deployment_queue->logs = json_encode($previous_logs, flags: JSON_INVALID_UTF8_SUBSTITUTE);+ }++ $this->application_deployment_queue->save();- if ($this->save) {- 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($sanitized_output)->trim();- $this->saved_outputs[$this->save] = str($this->saved_outputs[$this->save]);- } else {- $this->saved_outputs[$this->save] = str($sanitized_output)->trim();- }+ if ($this->save) {+ if (data_get($this->saved_outputs, $this->save, null) === null) {+ data_set($this->saved_outputs, $this->save, str());}- });- $this->application_deployment_queue->update([- 'current_process_id' => $process->id(),- ]);-- $process_result = $process->wait();- if ($process_result->exitCode() !== 0) {- if (! $ignore_errors) {- $this->application_deployment_queue->status = ApplicationDeploymentStatus::FAILED->value;- $this->application_deployment_queue->save();- throw new \RuntimeException($process_result->errorOutput());+ if ($append) {+ $this->saved_outputs[$this->save] .= str($sanitized_output)->trim();+ $this->saved_outputs[$this->save] = str($this->saved_outputs[$this->save]);+ } else {+ $this->saved_outputs[$this->save] = str($sanitized_output)->trim();}}});