Skip to content

Commit

Permalink
fix: unique name for release command
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdan-shulha committed Oct 15, 2024
1 parent 68a1e1a commit 1ed4a7c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions app/Models/DeploymentData/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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');

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 [
Expand All @@ -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,
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 1ed4a7c

Please sign in to comment.