feat: labels by proxy type

This commit is contained in:
Lorenzo Migliorero
2024-07-17 21:06:56 +02:00
parent c37398af72
commit 3be06ced92
2 changed files with 108 additions and 79 deletions

View File

@@ -1,5 +1,6 @@
<?php <?php
use App\Enums\ProxyTypes;
use App\Models\Application; use App\Models\Application;
use App\Models\ApplicationPreview; use App\Models\ApplicationPreview;
use App\Models\Server; use App\Models\Server;
@@ -535,26 +536,31 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview
if ($pull_request_id === 0) { if ($pull_request_id === 0) {
if ($application->fqdn) { if ($application->fqdn) {
$domains = str(data_get($application, 'fqdn'))->explode(','); $domains = str(data_get($application, 'fqdn'))->explode(',');
$labels = $labels->merge(fqdnLabelsForTraefik( switch($application->destination->server->proxyType()) {
uuid: $appUuid, case ProxyTypes::TRAEFIK_V2->value:
domains: $domains, $labels = $labels->merge(fqdnLabelsForTraefik(
onlyPort: $onlyPort, uuid: $appUuid,
is_force_https_enabled: $application->isForceHttpsEnabled(), domains: $domains,
is_gzip_enabled: $application->isGzipEnabled(), onlyPort: $onlyPort,
is_stripprefix_enabled: $application->isStripprefixEnabled(), is_force_https_enabled: $application->isForceHttpsEnabled(),
redirect_direction: $application->redirect is_gzip_enabled: $application->isGzipEnabled(),
)); is_stripprefix_enabled: $application->isStripprefixEnabled(),
// Add Caddy labels redirect_direction: $application->redirect
$labels = $labels->merge(fqdnLabelsForCaddy( ));
network: $application->destination->network, break;
uuid: $appUuid, case ProxyTypes::CADDY->value:
domains: $domains, $labels = $labels->merge(fqdnLabelsForCaddy(
onlyPort: $onlyPort, network: $application->destination->network,
is_force_https_enabled: $application->isForceHttpsEnabled(), uuid: $appUuid,
is_gzip_enabled: $application->isGzipEnabled(), domains: $domains,
is_stripprefix_enabled: $application->isStripprefixEnabled(), onlyPort: $onlyPort,
redirect_direction: $application->redirect is_force_https_enabled: $application->isForceHttpsEnabled(),
)); is_gzip_enabled: $application->isGzipEnabled(),
is_stripprefix_enabled: $application->isStripprefixEnabled(),
redirect_direction: $application->redirect
));
break;
}
} }
} else { } else {
if (data_get($preview, 'fqdn')) { if (data_get($preview, 'fqdn')) {
@@ -562,24 +568,30 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview
} else { } else {
$domains = collect([]); $domains = collect([]);
} }
$labels = $labels->merge(fqdnLabelsForTraefik(
uuid: $appUuid, switch($application->destination->server->proxyType()) {
domains: $domains, case ProxyTypes::TRAEFIK_V2->value:
onlyPort: $onlyPort, $labels = $labels->merge(fqdnLabelsForTraefik(
is_force_https_enabled: $application->isForceHttpsEnabled(), uuid: $appUuid,
is_gzip_enabled: $application->isGzipEnabled(), domains: $domains,
is_stripprefix_enabled: $application->isStripprefixEnabled() onlyPort: $onlyPort,
)); is_force_https_enabled: $application->isForceHttpsEnabled(),
// Add Caddy labels is_gzip_enabled: $application->isGzipEnabled(),
$labels = $labels->merge(fqdnLabelsForCaddy( is_stripprefix_enabled: $application->isStripprefixEnabled()
network: $application->destination->network, ));
uuid: $appUuid, break;
domains: $domains, case ProxyTypes::CADDY->value:
onlyPort: $onlyPort, $labels = $labels->merge(fqdnLabelsForCaddy(
is_force_https_enabled: $application->isForceHttpsEnabled(), network: $application->destination->network,
is_gzip_enabled: $application->isGzipEnabled(), uuid: $appUuid,
is_stripprefix_enabled: $application->isStripprefixEnabled() domains: $domains,
)); onlyPort: $onlyPort,
is_force_https_enabled: $application->isForceHttpsEnabled(),
is_gzip_enabled: $application->isGzipEnabled(),
is_stripprefix_enabled: $application->isStripprefixEnabled()
));
break;
}
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
use App\Enums\ApplicationDeploymentStatus; use App\Enums\ApplicationDeploymentStatus;
use App\Enums\ProxyTypes;
use App\Jobs\ServerFilesFromServerJob; use App\Jobs\ServerFilesFromServerJob;
use App\Models\Application; use App\Models\Application;
use App\Models\ApplicationDeploymentQueue; use App\Models\ApplicationDeploymentQueue;
@@ -1305,27 +1306,33 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
$serviceLabels = $serviceLabels->merge($defaultLabels); $serviceLabels = $serviceLabels->merge($defaultLabels);
if (! $isDatabase && $fqdns->count() > 0) { if (! $isDatabase && $fqdns->count() > 0) {
if ($fqdns) { if ($fqdns) {
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik( switch($resource->destination->server->proxyType()) {
uuid: $resource->uuid, case ProxyTypes::TRAEFIK_V2->value:
domains: $fqdns, $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(
is_force_https_enabled: true, uuid: $resource->uuid,
serviceLabels: $serviceLabels, domains: $fqdns,
is_gzip_enabled: $savedService->isGzipEnabled(), is_force_https_enabled: true,
is_stripprefix_enabled: $savedService->isStripprefixEnabled(), serviceLabels: $serviceLabels,
service_name: $serviceName, is_gzip_enabled: $savedService->isGzipEnabled(),
image: data_get($service, 'image') is_stripprefix_enabled: $savedService->isStripprefixEnabled(),
)); service_name: $serviceName,
$serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy( image: data_get($service, 'image')
network: $resource->destination->network, ));
uuid: $resource->uuid, break;
domains: $fqdns, case ProxyTypes::CADDY->value:
is_force_https_enabled: true, $serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(
serviceLabels: $serviceLabels, network: $resource->destination->network,
is_gzip_enabled: $savedService->isGzipEnabled(), uuid: $resource->uuid,
is_stripprefix_enabled: $savedService->isStripprefixEnabled(), domains: $fqdns,
service_name: $serviceName, is_force_https_enabled: true,
image: data_get($service, 'image') serviceLabels: $serviceLabels,
)); is_gzip_enabled: $savedService->isGzipEnabled(),
is_stripprefix_enabled: $savedService->isStripprefixEnabled(),
service_name: $serviceName,
image: data_get($service, 'image')
));
break;
}
} }
} }
if ($resource->server->isLogDrainEnabled() && $savedService->isLogDrainEnabled()) { if ($resource->server->isLogDrainEnabled() && $savedService->isLogDrainEnabled()) {
@@ -2023,26 +2030,36 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
}); });
} }
} }
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik( switch ($server->proxyType()) {
uuid: $resource->uuid, case ProxyTypes::TRAEFIK_V2->value:
domains: $fqdns, $serviceLabels = $serviceLabels->merge(
serviceLabels: $serviceLabels, fqdnLabelsForTraefik(
generate_unique_uuid: $resource->build_pack === 'dockercompose', uuid: $resource->uuid,
image: data_get($service, 'image'), domains: $fqdns,
is_force_https_enabled: $resource->isForceHttpsEnabled(), serviceLabels: $serviceLabels,
is_gzip_enabled: $resource->isGzipEnabled(), generate_unique_uuid: $resource->build_pack === 'dockercompose',
is_stripprefix_enabled: $resource->isStripprefixEnabled(), image: data_get($service, 'image'),
)); is_force_https_enabled: $resource->isForceHttpsEnabled(),
$serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy( is_gzip_enabled: $resource->isGzipEnabled(),
network: $resource->destination->network, is_stripprefix_enabled: $resource->isStripprefixEnabled(),
uuid: $resource->uuid, )
domains: $fqdns, );
serviceLabels: $serviceLabels, break;
image: data_get($service, 'image'), case ProxyTypes::CADDY->value:
is_force_https_enabled: $resource->isForceHttpsEnabled(), $serviceLabels = $serviceLabels->merge(
is_gzip_enabled: $resource->isGzipEnabled(), fqdnLabelsForCaddy(
is_stripprefix_enabled: $resource->isStripprefixEnabled(), network: $resource->destination->network,
)); uuid: $resource->uuid,
domains: $fqdns,
serviceLabels: $serviceLabels,
image: data_get($service, 'image'),
is_force_https_enabled: $resource->isForceHttpsEnabled(),
is_gzip_enabled: $resource->isGzipEnabled(),
is_stripprefix_enabled: $resource->isStripprefixEnabled(),
)
);
break;
}
} }
} }
} }