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');
try {
$applicationDeploymentQueue = ApplicationDeploymentQueue::find($this->applicationDeploymentQueueId);
$application = Application::find($applicationDeploymentQueue->application_id);
$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');
$server = data_get($destination, 'server');
$network = data_get($destination, 'network');
$application = Application::find($applicationDeploymentQueue->application_id)->firstOrFail();
$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);
savePrivateKeyToFs($server);
@ -53,15 +54,11 @@ public function handle()
$applicationDeploymentQueue->update([
'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,
]);
$this->executeRemoteCommand(
server: $server,
logModel: $applicationDeploymentQueue,
commands: prepareHelperContainer($server, $network, $deploymentUuid)
$server->executeRemoteCommand(
commands: prepareHelperContainer($server, $network, $deploymentUuid),
loggingModel: $applicationDeploymentQueue
);
$this->executeRemoteCommand(
server: $server,
logModel: $applicationDeploymentQueue,
$server->executeRemoteCommand(
commands: generateComposeFile(
deploymentUuid: $deploymentUuid,
server: $server,
@ -70,13 +67,16 @@ public function handle()
containerName: $containerName,
imageName: $productionImageName,
pullRequestId: $pullRequestId
)
),
loggingModel: $applicationDeploymentQueue
);
$this->executeRemoteCommand(
server: $server,
logModel: $applicationDeploymentQueue,
commands: rollingUpdate(application: $application, deploymentUuid: $deploymentUuid)
$server->executeRemoteCommand(
commands: rollingUpdate(application: $application, deploymentUuid: $deploymentUuid),
loggingModel: $applicationDeploymentQueue
);
$applicationDeploymentQueue->update([
'status' => ApplicationDeploymentStatus::FINISHED->value,
]);
} catch (Throwable $e) {
$this->executeRemoteCommand(
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);
}
public function executeRemoteCommand(Collection $commands, ApplicationDeploymentQueue $logModel)
public function executeRemoteCommand(Collection $commands, ApplicationDeploymentQueue $loggingModel)
{
static::$batch_counter++;
foreach ($commands as $command) {
@ -406,7 +406,7 @@ public function executeRemoteCommand(Collection $commands, ApplicationDeployment
$saveOutput = data_get($command, 'saveOutput');
$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();
if ($output->startsWith('╔')) {
$output = "\n" . $output;
@ -419,22 +419,22 @@ public function executeRemoteCommand(Collection $commands, ApplicationDeployment
'hidden' => $hidden,
'batch' => static::$batch_counter,
];
if (!$logModel->logs) {
if (!$loggingModel->logs) {
$new_log_entry['order'] = 1;
} else {
$previous_logs = json_decode($this->log_model->logs, associative: true, flags: JSON_THROW_ON_ERROR);
$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;
$previousLogs[] = $newLogEntry;
$logModel->logs = json_encode($previousLogs, flags: JSON_THROW_ON_ERROR);
$logModel->save();
$loggingModel->logs = json_encode($previousLogs, flags: JSON_THROW_ON_ERROR);
$loggingModel->save();
if ($saveOutput) {
$this->remoteCommandOutputs[$saveOutput] = str($output)->trim();
}
});
$logModel->update([
$loggingModel->update([
'current_process_id' => $process->id(),
]);
@ -442,8 +442,8 @@ public function executeRemoteCommand(Collection $commands, ApplicationDeployment
if ($processResult->exitCode() !== 0) {
if (!$ignoreErrors) {
$status = ApplicationDeploymentStatus::FAILED->value;
$logModel->status = $status;
$logModel->save();
$loggingModel->status = $status;
$loggingModel->save();
throw new \RuntimeException($processResult->errorOutput());
}
}