mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 16:52:45 -04:00
The legacy configuration hash encoded serialized environment variable rows, so hashes from older versions never matched after an upgrade, and the fallback compared the configuration with an empty one. Apps without a deployment snapshot now report no pending changes, and their next deployment rebuilds the image. Closes #11101 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.1 KiB
PHP
85 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\DeploymentConfiguration;
|
|
|
|
class ConfigurationDiff
|
|
{
|
|
/**
|
|
* @param array<int, array<string, mixed>> $changes
|
|
*/
|
|
public function __construct(
|
|
protected array $changes = [],
|
|
protected bool $legacyFallback = false,
|
|
) {}
|
|
|
|
public static function unchanged(): self
|
|
{
|
|
return new self;
|
|
}
|
|
|
|
/**
|
|
* The last deployment stored no configuration snapshot (it ran before v4.1), so the
|
|
* deployed configuration is unknown. Report no changes, but build on the next deployment.
|
|
*/
|
|
public static function legacy(): self
|
|
{
|
|
return new self(legacyFallback: true);
|
|
}
|
|
|
|
/**
|
|
* @param array<int, array<string, mixed>> $changes
|
|
*/
|
|
public static function fromChanges(array $changes): self
|
|
{
|
|
return new self(array_values($changes));
|
|
}
|
|
|
|
public function isChanged(): bool
|
|
{
|
|
return $this->changes !== [];
|
|
}
|
|
|
|
public function isLegacyFallback(): bool
|
|
{
|
|
return $this->legacyFallback;
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return count($this->changes);
|
|
}
|
|
|
|
public function requiresBuild(): bool
|
|
{
|
|
return $this->legacyFallback || collect($this->changes)->contains(fn (array $change): bool => $change['impact'] === 'build');
|
|
}
|
|
|
|
public function requiresRedeploy(): bool
|
|
{
|
|
return $this->isChanged();
|
|
}
|
|
|
|
/**
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
public function changes(): array
|
|
{
|
|
return $this->changes;
|
|
}
|
|
|
|
/**
|
|
* @return array{changed: bool, count: int, requires_build: bool, requires_redeploy: bool, legacy_fallback: bool, changes: array<int, array<string, mixed>>}
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'changed' => $this->isChanged(),
|
|
'count' => $this->count(),
|
|
'requires_build' => $this->requiresBuild(),
|
|
'requires_redeploy' => $this->requiresRedeploy(),
|
|
'legacy_fallback' => $this->isLegacyFallback(),
|
|
'changes' => $this->changes(),
|
|
];
|
|
}
|
|
}
|