Add managed registry provisioning, pruning, and readiness tracking
This commit is contained in:
54
app/Services/Registries/ImageReference.php
Normal file
54
app/Services/Registries/ImageReference.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Registries;
|
||||
|
||||
use App\Enums\RegistryType;
|
||||
use App\Models\Environment;
|
||||
use App\Models\Registry;
|
||||
|
||||
class ImageReference
|
||||
{
|
||||
public function tagFor(Environment $environment, string $commitSha, ?Registry $registry = null): string
|
||||
{
|
||||
$tag = substr($commitSha, 0, 12);
|
||||
|
||||
if ($this->registryType($registry) === RegistryType::MANAGED) {
|
||||
$namespace = trim((string) config('keystone.managed_registry.namespace', 'keystone'), '/');
|
||||
$applicationId = $environment->application->uuid ?: 'app-'.$environment->application_id;
|
||||
$environmentId = $environment->uuid ?: 'env-'.$environment->id;
|
||||
$path = $namespace.'/'.$applicationId.'/'.$environmentId;
|
||||
|
||||
return $path.':'.$tag;
|
||||
}
|
||||
|
||||
return str($environment->application->name)
|
||||
->slug()
|
||||
->append(':'.$tag)
|
||||
->value();
|
||||
}
|
||||
|
||||
public function registryReference(Registry $registry, string $imageTag): string
|
||||
{
|
||||
return rtrim($this->registryHost((string) $registry->url), '/').'/'.ltrim($imageTag, '/');
|
||||
}
|
||||
|
||||
private function registryHost(string $url): string
|
||||
{
|
||||
$host = preg_replace('#^https?://#', '', trim($url));
|
||||
|
||||
return $host === null ? trim($url) : $host;
|
||||
}
|
||||
|
||||
private function registryType(?Registry $registry): ?RegistryType
|
||||
{
|
||||
if (! $registry instanceof Registry) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($registry->type instanceof RegistryType) {
|
||||
return $registry->type;
|
||||
}
|
||||
|
||||
return RegistryType::tryFrom((string) $registry->type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user