From 1ed4a7cc9b4de188c2e6feb512bb2ed6e715ca53 Mon Sep 17 00:00:00 2001 From: Bohdan Shulha Date: Tue, 15 Oct 2024 23:09:08 +0200 Subject: [PATCH] fix: unique name for release command --- app/Models/DeploymentData/Worker.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/Models/DeploymentData/Worker.php b/app/Models/DeploymentData/Worker.php index dc8681c..3fcd4d7 100644 --- a/app/Models/DeploymentData/Worker.php +++ b/app/Models/DeploymentData/Worker.php @@ -56,6 +56,10 @@ public function __construct( public function asNodeTasks(Deployment $deployment, Process $process, bool $pullImage = true, ?int $desiredReplicas = null, ?Backup $backup = null): array { + if (! $this->dockerName) { + $this->dockerName = $process->makeResourceName('wkr_'.$this->name); + } + $launchNow = is_null($desiredReplicas) ? $this->replicas > 0 : $desiredReplicas > 0; if ($launchNow) { @@ -76,10 +80,6 @@ public function asNodeTasks(Deployment $deployment, Process $process, bool $pull $tasks = []; - if (! $this->dockerName) { - $this->dockerName = $process->makeResourceName('wkr_'.$this->name); - } - if ($this->launchMode->value === LaunchMode::BackupCreate->value && ! $this->backupCreate->backupVolume) { $dockerName = dockerize_name($this->dockerName.'_vol_ptah_backup'); @@ -136,7 +136,7 @@ public function asNodeTasks(Deployment $deployment, Process $process, bool $pull 'workerName' => $this->name, ]), 'payload' => [ - 'ReleaseCommand' => $this->getReleaseCommandPayload($process, $labels), + 'ReleaseCommand' => $this->getReleaseCommandPayload($deployment, $labels), 'SecretVars' => $this->getSecretVars($process), 'SwarmServiceSpec' => [ 'Name' => $this->dockerName, @@ -283,7 +283,7 @@ private function getCommandAndArgs(): array return [['sh'], ['-c', $this->command]]; } - private function getReleaseCommandPayload(Process $process, array $labels): array + private function getReleaseCommandPayload(Deployment $deployment, array $labels): array { if (! $this->releaseCommand->command) { return [ @@ -294,7 +294,7 @@ private function getReleaseCommandPayload(Process $process, array $labels): arra } // Always create a new config, as the command may be the same, but the image/entrypoint may be different. - $this->releaseCommand->dockerName = $process->makeResourceName('rel_cmd'); + $this->releaseCommand->dockerName = $this->makeResourceName('dpl_'.$deployment->id.'_rel_cmd'); return [ 'ConfigName' => $this->releaseCommand->dockerName, @@ -468,6 +468,11 @@ private function getBackupRestoreTask(Backup $backup, array $labels): array ]; } + private function makeResourceName(string $name): string + { + return dockerize_name($this->dockerName.'_'.$name); + } + public static function make(array $attributes): static { $defaults = [