Skip to content

Commit 0b00091

Browse files
committed
feat: able to generate only the required labels for resources
1 parent 92f90d4 commit 0b00091

File tree

5 files changed

+245
-98
lines changed

5 files changed

+245
-98
lines changed

app/Livewire/Server/Proxy.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class Proxy extends Component
2020

2121
protected $listeners = ['proxyStatusUpdated', 'saveConfiguration' => 'submit'];
2222

23+
protected $rules = [
24+
'server.settings.generate_exact_labels' => 'required|boolean',
25+
];
26+
2327
public function mount()
2428
{
2529
$this->selectedProxy = $this->server->proxyType();
@@ -31,13 +35,13 @@ public function proxyStatusUpdated()
3135
$this->dispatch('refresh')->self();
3236
}
3337

34-
public function change_proxy()
38+
public function changeProxy()
3539
{
3640
$this->server->proxy = null;
3741
$this->server->save();
3842
}
3943

40-
public function select_proxy($proxy_type)
44+
public function selectProxy($proxy_type)
4145
{
4246
$this->server->proxy->set('status', 'exited');
4347
$this->server->proxy->set('type', $proxy_type);
@@ -49,6 +53,17 @@ public function select_proxy($proxy_type)
4953
$this->dispatch('proxyStatusUpdated');
5054
}
5155

56+
public function instantSave()
57+
{
58+
try {
59+
$this->validate();
60+
$this->server->settings->save();
61+
$this->dispatch('success', 'Settings saved.');
62+
} catch (\Throwable $e) {
63+
return handleError($e, $this);
64+
}
65+
}
66+
5267
public function submit()
5368
{
5469
try {

bootstrap/helpers/docker.php

Lines changed: 78 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,73 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview
540540
if ($pull_request_id === 0) {
541541
if ($application->fqdn) {
542542
$domains = str(data_get($application, 'fqdn'))->explode(',');
543+
$shouldGenerateLabelsExactly = $application->destination->server->settings->generate_exact_labels;
544+
if ($shouldGenerateLabelsExactly) {
545+
switch ($application->destination->server->proxyType()) {
546+
case ProxyTypes::TRAEFIK->value:
547+
$labels = $labels->merge(fqdnLabelsForTraefik(
548+
uuid: $appUuid,
549+
domains: $domains,
550+
onlyPort: $onlyPort,
551+
is_force_https_enabled: $application->isForceHttpsEnabled(),
552+
is_gzip_enabled: $application->isGzipEnabled(),
553+
is_stripprefix_enabled: $application->isStripprefixEnabled(),
554+
redirect_direction: $application->redirect
555+
));
556+
break;
557+
case ProxyTypes::CADDY->value:
558+
$labels = $labels->merge(fqdnLabelsForCaddy(
559+
network: $application->destination->network,
560+
uuid: $appUuid,
561+
domains: $domains,
562+
onlyPort: $onlyPort,
563+
is_force_https_enabled: $application->isForceHttpsEnabled(),
564+
is_gzip_enabled: $application->isGzipEnabled(),
565+
is_stripprefix_enabled: $application->isStripprefixEnabled(),
566+
redirect_direction: $application->redirect
567+
));
568+
break;
569+
}
570+
} else {
571+
$labels = $labels->merge(fqdnLabelsForTraefik(
572+
uuid: $appUuid,
573+
domains: $domains,
574+
onlyPort: $onlyPort,
575+
is_force_https_enabled: $application->isForceHttpsEnabled(),
576+
is_gzip_enabled: $application->isGzipEnabled(),
577+
is_stripprefix_enabled: $application->isStripprefixEnabled(),
578+
redirect_direction: $application->redirect
579+
));
580+
$labels = $labels->merge(fqdnLabelsForCaddy(
581+
network: $application->destination->network,
582+
uuid: $appUuid,
583+
domains: $domains,
584+
onlyPort: $onlyPort,
585+
is_force_https_enabled: $application->isForceHttpsEnabled(),
586+
is_gzip_enabled: $application->isGzipEnabled(),
587+
is_stripprefix_enabled: $application->isStripprefixEnabled(),
588+
redirect_direction: $application->redirect
589+
));
590+
}
591+
592+
}
593+
} else {
594+
if (data_get($preview, 'fqdn')) {
595+
$domains = str(data_get($preview, 'fqdn'))->explode(',');
596+
} else {
597+
$domains = collect([]);
598+
}
599+
$shouldGenerateLabelsExactly = $application->destination->server->settings->generate_exact_labels;
600+
if ($shouldGenerateLabelsExactly) {
543601
switch ($application->destination->server->proxyType()) {
544-
case ProxyTypes::TRAEFIK_V2->value:
602+
case ProxyTypes::TRAEFIK->value:
545603
$labels = $labels->merge(fqdnLabelsForTraefik(
546604
uuid: $appUuid,
547605
domains: $domains,
548606
onlyPort: $onlyPort,
549607
is_force_https_enabled: $application->isForceHttpsEnabled(),
550608
is_gzip_enabled: $application->isGzipEnabled(),
551-
is_stripprefix_enabled: $application->isStripprefixEnabled(),
552-
redirect_direction: $application->redirect
609+
is_stripprefix_enabled: $application->isStripprefixEnabled()
553610
));
554611
break;
555612
case ProxyTypes::CADDY->value:
@@ -560,41 +617,28 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview
560617
onlyPort: $onlyPort,
561618
is_force_https_enabled: $application->isForceHttpsEnabled(),
562619
is_gzip_enabled: $application->isGzipEnabled(),
563-
is_stripprefix_enabled: $application->isStripprefixEnabled(),
564-
redirect_direction: $application->redirect
620+
is_stripprefix_enabled: $application->isStripprefixEnabled()
565621
));
566622
break;
567623
}
568-
}
569-
} else {
570-
if (data_get($preview, 'fqdn')) {
571-
$domains = str(data_get($preview, 'fqdn'))->explode(',');
572624
} else {
573-
$domains = collect([]);
574-
}
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;
625+
$labels = $labels->merge(fqdnLabelsForTraefik(
626+
uuid: $appUuid,
627+
domains: $domains,
628+
onlyPort: $onlyPort,
629+
is_force_https_enabled: $application->isForceHttpsEnabled(),
630+
is_gzip_enabled: $application->isGzipEnabled(),
631+
is_stripprefix_enabled: $application->isStripprefixEnabled()
632+
));
633+
$labels = $labels->merge(fqdnLabelsForCaddy(
634+
network: $application->destination->network,
635+
uuid: $appUuid,
636+
domains: $domains,
637+
onlyPort: $onlyPort,
638+
is_force_https_enabled: $application->isForceHttpsEnabled(),
639+
is_gzip_enabled: $application->isGzipEnabled(),
640+
is_stripprefix_enabled: $application->isStripprefixEnabled()
641+
));
598642
}
599643

600644
}

bootstrap/helpers/shared.php

Lines changed: 108 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,32 +1305,57 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
13051305
$serviceLabels = $serviceLabels->merge($defaultLabels);
13061306
if (! $isDatabase && $fqdns->count() > 0) {
13071307
if ($fqdns) {
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;
1308+
$shouldGenerateLabelsExactly = $resource->server->settings->generate_exact_labels;
1309+
if ($shouldGenerateLabelsExactly) {
1310+
switch ($resource->server->proxyType()) {
1311+
case ProxyTypes::TRAEFIK->value:
1312+
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(
1313+
uuid: $resource->uuid,
1314+
domains: $fqdns,
1315+
is_force_https_enabled: true,
1316+
serviceLabels: $serviceLabels,
1317+
is_gzip_enabled: $savedService->isGzipEnabled(),
1318+
is_stripprefix_enabled: $savedService->isStripprefixEnabled(),
1319+
service_name: $serviceName,
1320+
image: data_get($service, 'image')
1321+
));
1322+
break;
1323+
case ProxyTypes::CADDY->value:
1324+
$serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(
1325+
network: $resource->destination->network,
1326+
uuid: $resource->uuid,
1327+
domains: $fqdns,
1328+
is_force_https_enabled: true,
1329+
serviceLabels: $serviceLabels,
1330+
is_gzip_enabled: $savedService->isGzipEnabled(),
1331+
is_stripprefix_enabled: $savedService->isStripprefixEnabled(),
1332+
service_name: $serviceName,
1333+
image: data_get($service, 'image')
1334+
));
1335+
break;
1336+
}
1337+
} else {
1338+
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(
1339+
uuid: $resource->uuid,
1340+
domains: $fqdns,
1341+
is_force_https_enabled: true,
1342+
serviceLabels: $serviceLabels,
1343+
is_gzip_enabled: $savedService->isGzipEnabled(),
1344+
is_stripprefix_enabled: $savedService->isStripprefixEnabled(),
1345+
service_name: $serviceName,
1346+
image: data_get($service, 'image')
1347+
));
1348+
$serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(
1349+
network: $resource->destination->network,
1350+
uuid: $resource->uuid,
1351+
domains: $fqdns,
1352+
is_force_https_enabled: true,
1353+
serviceLabels: $serviceLabels,
1354+
is_gzip_enabled: $savedService->isGzipEnabled(),
1355+
is_stripprefix_enabled: $savedService->isStripprefixEnabled(),
1356+
service_name: $serviceName,
1357+
image: data_get($service, 'image')
1358+
));
13341359
}
13351360
}
13361361
}
@@ -2037,35 +2062,63 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
20372062
});
20382063
}
20392064
}
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;
2065+
$shouldGenerateLabelsExactly = $server->settings->generate_exact_labels;
2066+
if ($shouldGenerateLabelsExactly) {
2067+
switch ($server->proxyType()) {
2068+
case ProxyTypes::TRAEFIK->value:
2069+
$serviceLabels = $serviceLabels->merge(
2070+
fqdnLabelsForTraefik(
2071+
uuid: $resource->uuid,
2072+
domains: $fqdns,
2073+
serviceLabels: $serviceLabels,
2074+
generate_unique_uuid: $resource->build_pack === 'dockercompose',
2075+
image: data_get($service, 'image'),
2076+
is_force_https_enabled: $resource->isForceHttpsEnabled(),
2077+
is_gzip_enabled: $resource->isGzipEnabled(),
2078+
is_stripprefix_enabled: $resource->isStripprefixEnabled(),
2079+
)
2080+
);
2081+
break;
2082+
case ProxyTypes::CADDY->value:
2083+
$serviceLabels = $serviceLabels->merge(
2084+
fqdnLabelsForCaddy(
2085+
network: $resource->destination->network,
2086+
uuid: $resource->uuid,
2087+
domains: $fqdns,
2088+
serviceLabels: $serviceLabels,
2089+
image: data_get($service, 'image'),
2090+
is_force_https_enabled: $resource->isForceHttpsEnabled(),
2091+
is_gzip_enabled: $resource->isGzipEnabled(),
2092+
is_stripprefix_enabled: $resource->isStripprefixEnabled(),
2093+
)
2094+
);
2095+
break;
2096+
}
2097+
} else {
2098+
$serviceLabels = $serviceLabels->merge(
2099+
fqdnLabelsForTraefik(
2100+
uuid: $resource->uuid,
2101+
domains: $fqdns,
2102+
serviceLabels: $serviceLabels,
2103+
generate_unique_uuid: $resource->build_pack === 'dockercompose',
2104+
image: data_get($service, 'image'),
2105+
is_force_https_enabled: $resource->isForceHttpsEnabled(),
2106+
is_gzip_enabled: $resource->isGzipEnabled(),
2107+
is_stripprefix_enabled: $resource->isStripprefixEnabled(),
2108+
)
2109+
);
2110+
$serviceLabels = $serviceLabels->merge(
2111+
fqdnLabelsForCaddy(
2112+
network: $resource->destination->network,
2113+
uuid: $resource->uuid,
2114+
domains: $fqdns,
2115+
serviceLabels: $serviceLabels,
2116+
image: data_get($service, 'image'),
2117+
is_force_https_enabled: $resource->isForceHttpsEnabled(),
2118+
is_gzip_enabled: $resource->isGzipEnabled(),
2119+
is_stripprefix_enabled: $resource->isStripprefixEnabled(),
2120+
)
2121+
);
20692122
}
20702123
}
20712124
}

0 commit comments

Comments
 (0)