From 3be06ced92ea4fc01f542643f48ff43d63e36e16 Mon Sep 17 00:00:00 2001 From: Lorenzo Migliorero Date: Wed, 17 Jul 2024 21:06:56 +0200 Subject: [PATCH 1/2] feat: labels by proxy type --- bootstrap/helpers/docker.php | 88 ++++++++++++++++++-------------- bootstrap/helpers/shared.php | 99 +++++++++++++++++++++--------------- 2 files changed, 108 insertions(+), 79 deletions(-) diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index 21e946a9a..fa2a19c2a 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -1,5 +1,6 @@ fqdn) { $domains = str(data_get($application, 'fqdn'))->explode(','); - $labels = $labels->merge(fqdnLabelsForTraefik( - uuid: $appUuid, - domains: $domains, - onlyPort: $onlyPort, - is_force_https_enabled: $application->isForceHttpsEnabled(), - is_gzip_enabled: $application->isGzipEnabled(), - is_stripprefix_enabled: $application->isStripprefixEnabled(), - redirect_direction: $application->redirect - )); - // Add Caddy labels - $labels = $labels->merge(fqdnLabelsForCaddy( - network: $application->destination->network, - uuid: $appUuid, - domains: $domains, - onlyPort: $onlyPort, - is_force_https_enabled: $application->isForceHttpsEnabled(), - is_gzip_enabled: $application->isGzipEnabled(), - is_stripprefix_enabled: $application->isStripprefixEnabled(), - redirect_direction: $application->redirect - )); + switch($application->destination->server->proxyType()) { + case ProxyTypes::TRAEFIK_V2->value: + $labels = $labels->merge(fqdnLabelsForTraefik( + uuid: $appUuid, + domains: $domains, + onlyPort: $onlyPort, + is_force_https_enabled: $application->isForceHttpsEnabled(), + is_gzip_enabled: $application->isGzipEnabled(), + is_stripprefix_enabled: $application->isStripprefixEnabled(), + redirect_direction: $application->redirect + )); + break; + case ProxyTypes::CADDY->value: + $labels = $labels->merge(fqdnLabelsForCaddy( + network: $application->destination->network, + uuid: $appUuid, + domains: $domains, + onlyPort: $onlyPort, + is_force_https_enabled: $application->isForceHttpsEnabled(), + is_gzip_enabled: $application->isGzipEnabled(), + is_stripprefix_enabled: $application->isStripprefixEnabled(), + redirect_direction: $application->redirect + )); + break; + } } } else { if (data_get($preview, 'fqdn')) { @@ -562,24 +568,30 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview } else { $domains = collect([]); } - $labels = $labels->merge(fqdnLabelsForTraefik( - uuid: $appUuid, - domains: $domains, - onlyPort: $onlyPort, - is_force_https_enabled: $application->isForceHttpsEnabled(), - is_gzip_enabled: $application->isGzipEnabled(), - is_stripprefix_enabled: $application->isStripprefixEnabled() - )); - // Add Caddy labels - $labels = $labels->merge(fqdnLabelsForCaddy( - network: $application->destination->network, - uuid: $appUuid, - domains: $domains, - onlyPort: $onlyPort, - is_force_https_enabled: $application->isForceHttpsEnabled(), - is_gzip_enabled: $application->isGzipEnabled(), - is_stripprefix_enabled: $application->isStripprefixEnabled() - )); + + switch($application->destination->server->proxyType()) { + case ProxyTypes::TRAEFIK_V2->value: + $labels = $labels->merge(fqdnLabelsForTraefik( + uuid: $appUuid, + domains: $domains, + onlyPort: $onlyPort, + is_force_https_enabled: $application->isForceHttpsEnabled(), + is_gzip_enabled: $application->isGzipEnabled(), + is_stripprefix_enabled: $application->isStripprefixEnabled() + )); + break; + case ProxyTypes::CADDY->value: + $labels = $labels->merge(fqdnLabelsForCaddy( + network: $application->destination->network, + uuid: $appUuid, + domains: $domains, + onlyPort: $onlyPort, + is_force_https_enabled: $application->isForceHttpsEnabled(), + is_gzip_enabled: $application->isGzipEnabled(), + is_stripprefix_enabled: $application->isStripprefixEnabled() + )); + break; + } } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index e3c8d5218..9600b13d2 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -1,6 +1,7 @@ merge($defaultLabels); if (! $isDatabase && $fqdns->count() > 0) { if ($fqdns) { - $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik( - uuid: $resource->uuid, - domains: $fqdns, - is_force_https_enabled: true, - serviceLabels: $serviceLabels, - is_gzip_enabled: $savedService->isGzipEnabled(), - is_stripprefix_enabled: $savedService->isStripprefixEnabled(), - service_name: $serviceName, - image: data_get($service, 'image') - )); - $serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy( - network: $resource->destination->network, - uuid: $resource->uuid, - domains: $fqdns, - is_force_https_enabled: true, - serviceLabels: $serviceLabels, - is_gzip_enabled: $savedService->isGzipEnabled(), - is_stripprefix_enabled: $savedService->isStripprefixEnabled(), - service_name: $serviceName, - image: data_get($service, 'image') - )); + switch($resource->destination->server->proxyType()) { + case ProxyTypes::TRAEFIK_V2->value: + $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik( + uuid: $resource->uuid, + domains: $fqdns, + is_force_https_enabled: true, + serviceLabels: $serviceLabels, + is_gzip_enabled: $savedService->isGzipEnabled(), + is_stripprefix_enabled: $savedService->isStripprefixEnabled(), + service_name: $serviceName, + image: data_get($service, 'image') + )); + break; + case ProxyTypes::CADDY->value: + $serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy( + network: $resource->destination->network, + uuid: $resource->uuid, + domains: $fqdns, + is_force_https_enabled: true, + 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()) { @@ -2023,26 +2030,36 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal }); } } - $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik( - uuid: $resource->uuid, - domains: $fqdns, - serviceLabels: $serviceLabels, - generate_unique_uuid: $resource->build_pack === 'dockercompose', - image: data_get($service, 'image'), - is_force_https_enabled: $resource->isForceHttpsEnabled(), - is_gzip_enabled: $resource->isGzipEnabled(), - is_stripprefix_enabled: $resource->isStripprefixEnabled(), - )); - $serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy( - 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(), - )); + switch ($server->proxyType()) { + case ProxyTypes::TRAEFIK_V2->value: + $serviceLabels = $serviceLabels->merge( + fqdnLabelsForTraefik( + uuid: $resource->uuid, + domains: $fqdns, + serviceLabels: $serviceLabels, + generate_unique_uuid: $resource->build_pack === 'dockercompose', + image: data_get($service, 'image'), + is_force_https_enabled: $resource->isForceHttpsEnabled(), + is_gzip_enabled: $resource->isGzipEnabled(), + is_stripprefix_enabled: $resource->isStripprefixEnabled(), + ) + ); + break; + case ProxyTypes::CADDY->value: + $serviceLabels = $serviceLabels->merge( + fqdnLabelsForCaddy( + 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; + } } } } From be6d74a6a3c3f680d6f69d61c030b7484a05640a Mon Sep 17 00:00:00 2001 From: Lorenzo Migliorero Date: Thu, 18 Jul 2024 11:42:41 +0200 Subject: [PATCH 2/2] style: linting --- bootstrap/helpers/docker.php | 8 ++++---- bootstrap/helpers/shared.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index fa2a19c2a..355127130 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -536,7 +536,7 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview if ($pull_request_id === 0) { if ($application->fqdn) { $domains = str(data_get($application, 'fqdn'))->explode(','); - switch($application->destination->server->proxyType()) { + switch ($application->destination->server->proxyType()) { case ProxyTypes::TRAEFIK_V2->value: $labels = $labels->merge(fqdnLabelsForTraefik( uuid: $appUuid, @@ -547,7 +547,7 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview is_stripprefix_enabled: $application->isStripprefixEnabled(), redirect_direction: $application->redirect )); - break; + break; case ProxyTypes::CADDY->value: $labels = $labels->merge(fqdnLabelsForCaddy( network: $application->destination->network, @@ -559,7 +559,7 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview is_stripprefix_enabled: $application->isStripprefixEnabled(), redirect_direction: $application->redirect )); - break; + break; } } } else { @@ -569,7 +569,7 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview $domains = collect([]); } - switch($application->destination->server->proxyType()) { + switch ($application->destination->server->proxyType()) { case ProxyTypes::TRAEFIK_V2->value: $labels = $labels->merge(fqdnLabelsForTraefik( uuid: $appUuid, diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 9600b13d2..a909b28e9 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -1306,7 +1306,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $serviceLabels = $serviceLabels->merge($defaultLabels); if (! $isDatabase && $fqdns->count() > 0) { if ($fqdns) { - switch($resource->destination->server->proxyType()) { + switch ($resource->destination->server->proxyType()) { case ProxyTypes::TRAEFIK_V2->value: $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik( uuid: $resource->uuid,