Fix server execution method parameter name

This commit is contained in:
Andras Bacsai 2023-11-22 20:56:25 +01:00
parent 9012f6b953
commit 7fb9e672cf
2 changed files with 29 additions and 29 deletions

View File

@ -33,17 +33,18 @@ public function handle()
ray('Deploying Docker Image'); ray('Deploying Docker Image');
try { try {
$applicationDeploymentQueue = ApplicationDeploymentQueue::find($this->applicationDeploymentQueueId); $applicationDeploymentQueue = ApplicationDeploymentQueue::find($this->applicationDeploymentQueueId);
$application = Application::find($applicationDeploymentQueue->application_id);
$deploymentUuid = data_get($applicationDeploymentQueue, 'deployment_uuid'); $deploymentUuid = data_get($applicationDeploymentQueue, 'deployment_uuid');
$dockerImage = data_get($application, 'docker_registry_image_name');
$dockerImageTag = data_get($application, 'docker_registry_image_tag');
$productionImageName = str("{$dockerImage}:{$dockerImageTag}");
$destination = $application->destination->getMorphClass()::where('id', $application->destination->id)->first();
$pullRequestId = data_get($applicationDeploymentQueue, 'pull_request_id'); $pullRequestId = data_get($applicationDeploymentQueue, 'pull_request_id');
$server = data_get($destination, 'server'); $application = Application::find($applicationDeploymentQueue->application_id)->firstOrFail();
$network = data_get($destination, 'network'); $server = data_get($application->destination, 'server');
$network = data_get($application->destination, 'network');
$dockerImage = data_get($application, 'docker_registry_image_name');
$dockerImageTag = data_get($application, 'docker_registry_image_tag');
$productionImageName = str("{$dockerImage}:{$dockerImageTag}");
$containerName = generateApplicationContainerName($application, $pullRequestId); $containerName = generateApplicationContainerName($application, $pullRequestId);
savePrivateKeyToFs($server); savePrivateKeyToFs($server);
@ -53,15 +54,11 @@ public function handle()
$applicationDeploymentQueue->update([ $applicationDeploymentQueue->update([
'status' => ApplicationDeploymentStatus::IN_PROGRESS->value, 'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,
]); ]);
$this->executeRemoteCommand( $server->executeRemoteCommand(
server: $server, commands: prepareHelperContainer($server, $network, $deploymentUuid),
logModel: $applicationDeploymentQueue, loggingModel: $applicationDeploymentQueue
commands: prepareHelperContainer($server, $network, $deploymentUuid)
); );
$server->executeRemoteCommand(
$this->executeRemoteCommand(
server: $server,
logModel: $applicationDeploymentQueue,
commands: generateComposeFile( commands: generateComposeFile(
deploymentUuid: $deploymentUuid, deploymentUuid: $deploymentUuid,
server: $server, server: $server,
@ -70,13 +67,16 @@ public function handle()
containerName: $containerName, containerName: $containerName,
imageName: $productionImageName, imageName: $productionImageName,
pullRequestId: $pullRequestId pullRequestId: $pullRequestId
) ),
loggingModel: $applicationDeploymentQueue
); );
$this->executeRemoteCommand( $server->executeRemoteCommand(
server: $server, commands: rollingUpdate(application: $application, deploymentUuid: $deploymentUuid),
logModel: $applicationDeploymentQueue, loggingModel: $applicationDeploymentQueue
commands: rollingUpdate(application: $application, deploymentUuid: $deploymentUuid)
); );
$applicationDeploymentQueue->update([
'status' => ApplicationDeploymentStatus::FINISHED->value,
]);
} catch (Throwable $e) { } catch (Throwable $e) {
$this->executeRemoteCommand( $this->executeRemoteCommand(
server: $server, server: $server,

View File

@ -392,7 +392,7 @@ public function validateCoolifyNetwork()
{ {
return instant_remote_process(["docker network create coolify --attachable >/dev/null 2>&1 || true"], $this, false); return instant_remote_process(["docker network create coolify --attachable >/dev/null 2>&1 || true"], $this, false);
} }
public function executeRemoteCommand(Collection $commands, ApplicationDeploymentQueue $logModel) public function executeRemoteCommand(Collection $commands, ApplicationDeploymentQueue $loggingModel)
{ {
static::$batch_counter++; static::$batch_counter++;
foreach ($commands as $command) { foreach ($commands as $command) {
@ -406,7 +406,7 @@ public function executeRemoteCommand(Collection $commands, ApplicationDeployment
$saveOutput = data_get($command, 'saveOutput'); $saveOutput = data_get($command, 'saveOutput');
$remoteCommand = generateSshCommand($this, $command); $remoteCommand = generateSshCommand($this, $command);
$process = Process::timeout(3600)->idleTimeout(3600)->start($remoteCommand, function (string $type, string $output) use ($command, $hidden, $customOutputType, $logModel, $saveOutput) { $process = Process::timeout(3600)->idleTimeout(3600)->start($remoteCommand, function (string $type, string $output) use ($command, $hidden, $customOutputType, $loggingModel, $saveOutput) {
$output = str($output)->trim(); $output = str($output)->trim();
if ($output->startsWith('╔')) { if ($output->startsWith('╔')) {
$output = "\n" . $output; $output = "\n" . $output;
@ -419,22 +419,22 @@ public function executeRemoteCommand(Collection $commands, ApplicationDeployment
'hidden' => $hidden, 'hidden' => $hidden,
'batch' => static::$batch_counter, 'batch' => static::$batch_counter,
]; ];
if (!$logModel->logs) { if (!$loggingModel->logs) {
$new_log_entry['order'] = 1; $new_log_entry['order'] = 1;
} else { } else {
$previous_logs = json_decode($this->log_model->logs, associative: true, flags: JSON_THROW_ON_ERROR); $previous_logs = json_decode($this->log_model->logs, associative: true, flags: JSON_THROW_ON_ERROR);
$new_log_entry['order'] = count($previous_logs) + 1; $new_log_entry['order'] = count($previous_logs) + 1;
} }
$previousLogs = json_decode($logModel->logs, associative: true, flags: JSON_THROW_ON_ERROR); $previousLogs = json_decode($loggingModel->logs, associative: true, flags: JSON_THROW_ON_ERROR);
$newLogEntry['order'] = count($previousLogs) + 1; $newLogEntry['order'] = count($previousLogs) + 1;
$previousLogs[] = $newLogEntry; $previousLogs[] = $newLogEntry;
$logModel->logs = json_encode($previousLogs, flags: JSON_THROW_ON_ERROR); $loggingModel->logs = json_encode($previousLogs, flags: JSON_THROW_ON_ERROR);
$logModel->save(); $loggingModel->save();
if ($saveOutput) { if ($saveOutput) {
$this->remoteCommandOutputs[$saveOutput] = str($output)->trim(); $this->remoteCommandOutputs[$saveOutput] = str($output)->trim();
} }
}); });
$logModel->update([ $loggingModel->update([
'current_process_id' => $process->id(), 'current_process_id' => $process->id(),
]); ]);
@ -442,8 +442,8 @@ public function executeRemoteCommand(Collection $commands, ApplicationDeployment
if ($processResult->exitCode() !== 0) { if ($processResult->exitCode() !== 0) {
if (!$ignoreErrors) { if (!$ignoreErrors) {
$status = ApplicationDeploymentStatus::FAILED->value; $status = ApplicationDeploymentStatus::FAILED->value;
$logModel->status = $status; $loggingModel->status = $status;
$logModel->save(); $loggingModel->save();
throw new \RuntimeException($processResult->errorOutput()); throw new \RuntimeException($processResult->errorOutput());
} }
} }