wowowowowo
This commit is contained in:
@@ -18,6 +18,7 @@ use App\Models\Operation;
|
||||
use App\Models\Service;
|
||||
use App\Models\ServiceReplica;
|
||||
use App\Services\Compose\ComposeRenderer;
|
||||
use App\Support\CaddyRouteRenderer;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use InvalidArgumentException;
|
||||
@@ -29,6 +30,7 @@ class DeployEnvironment implements ShouldQueue
|
||||
|
||||
public function __construct(
|
||||
public Environment $environment,
|
||||
public ?string $targetCommit = null,
|
||||
) {
|
||||
//
|
||||
}
|
||||
@@ -51,7 +53,7 @@ class DeployEnvironment implements ShouldQueue
|
||||
'started_at' => now(),
|
||||
]);
|
||||
|
||||
$commitSha = app(ResolveEnvironmentCommit::class)->execute($this->environment);
|
||||
$commitSha = $this->targetCommit ?? app(ResolveEnvironmentCommit::class)->execute($this->environment);
|
||||
$services = $this->servicesNeedingDeployment($plan->services, $commitSha);
|
||||
|
||||
if ($services === []) {
|
||||
@@ -378,15 +380,25 @@ class DeployEnvironment implements ShouldQueue
|
||||
private function gatewayCutoverSteps(EnvironmentAttachment $attachment): array
|
||||
{
|
||||
$containerName = $attachment->service->replicas()->first()?->container_name;
|
||||
$config = $attachment->serviceSlice?->config ?? [];
|
||||
$domain = $config['domain'] ?? null;
|
||||
$tlsEnabled = $config['tls_enabled'] ?? true;
|
||||
$reloadCommand = $containerName
|
||||
? 'docker exec '.escapeshellarg($containerName).' caddy reload --config /etc/caddy/Caddyfile'
|
||||
: "docker compose -f /home/keystone/services/{$attachment->service_id}/compose.yml exec -T {$this->serviceKey($attachment->service)} caddy reload --config /etc/caddy/Caddyfile";
|
||||
$certificateCheck = $tlsEnabled && $domain
|
||||
? 'curl --fail --silent --show-error --head https://'.escapeshellarg($domain).' >/dev/null'
|
||||
: 'true # TLS disabled or no domain configured for this route';
|
||||
|
||||
return [
|
||||
[
|
||||
'name' => 'Validate Caddy route configuration',
|
||||
'script' => 'test -s /home/keystone/gateway/Caddyfile',
|
||||
],
|
||||
[
|
||||
'name' => 'Check TLS certificate status',
|
||||
'script' => $certificateCheck,
|
||||
],
|
||||
[
|
||||
'name' => 'Reload Caddy',
|
||||
'script' => $reloadCommand,
|
||||
@@ -406,15 +418,13 @@ class DeployEnvironment implements ShouldQueue
|
||||
|
||||
private function configureCaddyRouteScript(EnvironmentAttachment $attachment): string
|
||||
{
|
||||
$route = $attachment->serviceSlice?->name ?? $this->environment->name;
|
||||
$upstreams = $this->gatewayUpstreams($attachment);
|
||||
$caddyfile = app(CaddyRouteRenderer::class)->render($attachment, $upstreams);
|
||||
|
||||
return implode("\n", [
|
||||
'mkdir -p /home/keystone/gateway/Caddyfile.d',
|
||||
"cat > /home/keystone/gateway/Caddyfile.d/{$attachment->id}.caddy <<'KEYSTONE_CADDY_ROUTE'",
|
||||
"{$route} {",
|
||||
' reverse_proxy '.implode(' ', $upstreams),
|
||||
'}',
|
||||
$caddyfile,
|
||||
'KEYSTONE_CADDY_ROUTE',
|
||||
'cat /home/keystone/gateway/Caddyfile.d/*.caddy > /home/keystone/gateway/Caddyfile',
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user