Skip to content

Commit 92f90d4

Browse files
authored
Merge pull request coollabsio#2863 from lorenzomigliorero/feat/labels-by-proxy-type
Generate labels by proxy type
2 parents 59702c6 + 1b4a8aa commit 92f90d4

File tree

2 files changed

+108
-79
lines changed

2 files changed

+108
-79
lines changed

bootstrap/helpers/docker.php

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Enums\ProxyTypes;
34
use App\Models\Application;
45
use App\Models\ApplicationPreview;
56
use App\Models\Server;
@@ -539,51 +540,62 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview
539540
if ($pull_request_id === 0) {
540541
if ($application->fqdn) {
541542
$domains = str(data_get($application, 'fqdn'))->explode(',');
542-
$labels = $labels->merge(fqdnLabelsForTraefik(
543-
uuid: $appUuid,
544-
domains: $domains,
545-
onlyPort: $onlyPort,
546-
is_force_https_enabled: $application->isForceHttpsEnabled(),
547-
is_gzip_enabled: $application->isGzipEnabled(),
548-
is_stripprefix_enabled: $application->isStripprefixEnabled(),
549-
redirect_direction: $application->redirect
550-
));
551-
// Add Caddy labels
552-
$labels = $labels->merge(fqdnLabelsForCaddy(
553-
network: $application->destination->network,
554-
uuid: $appUuid,
555-
domains: $domains,
556-
onlyPort: $onlyPort,
557-
is_force_https_enabled: $application->isForceHttpsEnabled(),
558-
is_gzip_enabled: $application->isGzipEnabled(),
559-
is_stripprefix_enabled: $application->isStripprefixEnabled(),
560-
redirect_direction: $application->redirect
561-
));
543+
switch ($application->destination->server->proxyType()) {
544+
case ProxyTypes::TRAEFIK_V2->value:
545+
$labels = $labels->merge(fqdnLabelsForTraefik(
546+
uuid: $appUuid,
547+
domains: $domains,
548+
onlyPort: $onlyPort,
549+
is_force_https_enabled: $application->isForceHttpsEnabled(),
550+
is_gzip_enabled: $application->isGzipEnabled(),
551+
is_stripprefix_enabled: $application->isStripprefixEnabled(),
552+
redirect_direction: $application->redirect
553+
));
554+
break;
555+
case ProxyTypes::CADDY->value:
556+
$labels = $labels->merge(fqdnLabelsForCaddy(
557+
network: $application->destination->network,
558+
uuid: $appUuid,
559+
domains: $domains,
560+
onlyPort: $onlyPort,
561+
is_force_https_enabled: $application->isForceHttpsEnabled(),
562+
is_gzip_enabled: $application->isGzipEnabled(),
563+
is_stripprefix_enabled: $application->isStripprefixEnabled(),
564+
redirect_direction: $application->redirect
565+
));
566+
break;
567+
}
562568
}
563569
} else {
564570
if (data_get($preview, 'fqdn')) {
565571
$domains = str(data_get($preview, 'fqdn'))->explode(',');
566572
} else {
567573
$domains = collect([]);
568574
}
569-
$labels = $labels->merge(fqdnLabelsForTraefik(
570-
uuid: $appUuid,
571-
domains: $domains,
572-
onlyPort: $onlyPort,
573-
is_force_https_enabled: $application->isForceHttpsEnabled(),
574-
is_gzip_enabled: $application->isGzipEnabled(),
575-
is_stripprefix_enabled: $application->isStripprefixEnabled()
576-
));
577-
// Add Caddy labels
578-
$labels = $labels->merge(fqdnLabelsForCaddy(
579-
network: $application->destination->network,
580-
uuid: $appUuid,
581-
domains: $domains,
582-
onlyPort: $onlyPort,
583-
is_force_https_enabled: $application->isForceHttpsEnabled(),
584-
is_gzip_enabled: $application->isGzipEnabled(),
585-
is_stripprefix_enabled: $application->isStripprefixEnabled()
586-
));
575+
576+
switch ($application->destination->server->proxyType()) {
577+
case ProxyTypes::TRAEFIK_V2->value:
578+
$labels = $labels->merge(fqdnLabelsForTraefik(
579+
uuid: $appUuid,
580+
domains: $domains,
581+
onlyPort: $onlyPort,
582+
is_force_https_enabled: $application->isForceHttpsEnabled(),
583+
is_gzip_enabled: $application->isGzipEnabled(),
584+
is_stripprefix_enabled: $application->isStripprefixEnabled()
585+
));
586+
break;
587+
case ProxyTypes::CADDY->value:
588+
$labels = $labels->merge(fqdnLabelsForCaddy(
589+
network: $application->destination->network,
590+
uuid: $appUuid,
591+
domains: $domains,
592+
onlyPort: $onlyPort,
593+
is_force_https_enabled: $application->isForceHttpsEnabled(),
594+
is_gzip_enabled: $application->isGzipEnabled(),
595+
is_stripprefix_enabled: $application->isStripprefixEnabled()
596+
));
597+
break;
598+
}
587599

588600
}
589601

bootstrap/helpers/shared.php

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use App\Enums\ApplicationDeploymentStatus;
4+
use App\Enums\ProxyTypes;
45
use App\Jobs\ServerFilesFromServerJob;
56
use App\Models\Application;
67
use App\Models\ApplicationDeploymentQueue;
@@ -1304,27 +1305,33 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
13041305
$serviceLabels = $serviceLabels->merge($defaultLabels);
13051306
if (! $isDatabase && $fqdns->count() > 0) {
13061307
if ($fqdns) {
1307-
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(
1308-
uuid: $resource->uuid,
1309-
domains: $fqdns,
1310-
is_force_https_enabled: true,
1311-
serviceLabels: $serviceLabels,
1312-
is_gzip_enabled: $savedService->isGzipEnabled(),
1313-
is_stripprefix_enabled: $savedService->isStripprefixEnabled(),
1314-
service_name: $serviceName,
1315-
image: data_get($service, 'image')
1316-
));
1317-
$serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(
1318-
network: $resource->destination->network,
1319-
uuid: $resource->uuid,
1320-
domains: $fqdns,
1321-
is_force_https_enabled: true,
1322-
serviceLabels: $serviceLabels,
1323-
is_gzip_enabled: $savedService->isGzipEnabled(),
1324-
is_stripprefix_enabled: $savedService->isStripprefixEnabled(),
1325-
service_name: $serviceName,
1326-
image: data_get($service, 'image')
1327-
));
1308+
switch ($resource->destination->server->proxyType()) {
1309+
case ProxyTypes::TRAEFIK_V2->value:
1310+
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(
1311+
uuid: $resource->uuid,
1312+
domains: $fqdns,
1313+
is_force_https_enabled: true,
1314+
serviceLabels: $serviceLabels,
1315+
is_gzip_enabled: $savedService->isGzipEnabled(),
1316+
is_stripprefix_enabled: $savedService->isStripprefixEnabled(),
1317+
service_name: $serviceName,
1318+
image: data_get($service, 'image')
1319+
));
1320+
break;
1321+
case ProxyTypes::CADDY->value:
1322+
$serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(
1323+
network: $resource->destination->network,
1324+
uuid: $resource->uuid,
1325+
domains: $fqdns,
1326+
is_force_https_enabled: true,
1327+
serviceLabels: $serviceLabels,
1328+
is_gzip_enabled: $savedService->isGzipEnabled(),
1329+
is_stripprefix_enabled: $savedService->isStripprefixEnabled(),
1330+
service_name: $serviceName,
1331+
image: data_get($service, 'image')
1332+
));
1333+
break;
1334+
}
13281335
}
13291336
}
13301337
if ($resource->server->isLogDrainEnabled() && $savedService->isLogDrainEnabled()) {
@@ -2030,26 +2037,36 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
20302037
});
20312038
}
20322039
}
2033-
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(
2034-
uuid: $resource->uuid,
2035-
domains: $fqdns,
2036-
serviceLabels: $serviceLabels,
2037-
generate_unique_uuid: $resource->build_pack === 'dockercompose',
2038-
image: data_get($service, 'image'),
2039-
is_force_https_enabled: $resource->isForceHttpsEnabled(),
2040-
is_gzip_enabled: $resource->isGzipEnabled(),
2041-
is_stripprefix_enabled: $resource->isStripprefixEnabled(),
2042-
));
2043-
$serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(
2044-
network: $resource->destination->network,
2045-
uuid: $resource->uuid,
2046-
domains: $fqdns,
2047-
serviceLabels: $serviceLabels,
2048-
image: data_get($service, 'image'),
2049-
is_force_https_enabled: $resource->isForceHttpsEnabled(),
2050-
is_gzip_enabled: $resource->isGzipEnabled(),
2051-
is_stripprefix_enabled: $resource->isStripprefixEnabled(),
2052-
));
2040+
switch ($server->proxyType()) {
2041+
case ProxyTypes::TRAEFIK_V2->value:
2042+
$serviceLabels = $serviceLabels->merge(
2043+
fqdnLabelsForTraefik(
2044+
uuid: $resource->uuid,
2045+
domains: $fqdns,
2046+
serviceLabels: $serviceLabels,
2047+
generate_unique_uuid: $resource->build_pack === 'dockercompose',
2048+
image: data_get($service, 'image'),
2049+
is_force_https_enabled: $resource->isForceHttpsEnabled(),
2050+
is_gzip_enabled: $resource->isGzipEnabled(),
2051+
is_stripprefix_enabled: $resource->isStripprefixEnabled(),
2052+
)
2053+
);
2054+
break;
2055+
case ProxyTypes::CADDY->value:
2056+
$serviceLabels = $serviceLabels->merge(
2057+
fqdnLabelsForCaddy(
2058+
network: $resource->destination->network,
2059+
uuid: $resource->uuid,
2060+
domains: $fqdns,
2061+
serviceLabels: $serviceLabels,
2062+
image: data_get($service, 'image'),
2063+
is_force_https_enabled: $resource->isForceHttpsEnabled(),
2064+
is_gzip_enabled: $resource->isGzipEnabled(),
2065+
is_stripprefix_enabled: $resource->isStripprefixEnabled(),
2066+
)
2067+
);
2068+
break;
2069+
}
20532070
}
20542071
}
20552072
}

0 commit comments

Comments
 (0)