mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-22 02:24:13 +00:00
fix(compose): normalize service-name keys for domains and env vars (#11040)
This commit is contained in:
@@ -10,6 +10,37 @@ use Illuminate\Support\Str;
|
||||
use Spatie\Url\Url;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* Stable short hash for compose service names used in Traefik router/service IDs.
|
||||
* Keeps api.test vs api-test distinct after label-safe normalization.
|
||||
*/
|
||||
function traefikServiceNameHash(string $serviceName): string
|
||||
{
|
||||
return substr(md5($serviceName), 0, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Label-safe Traefik router/service name segment for a compose service.
|
||||
* Dots (and other non [a-zA-Z0-9-]) break Docker/Traefik label paths; always append a hash
|
||||
* so normalized names like api.test and api-test never collide.
|
||||
*/
|
||||
function traefikSafeServiceNameSegment(string $serviceName): string
|
||||
{
|
||||
$normalized = str($serviceName)
|
||||
->replace('.', '-')
|
||||
->replace('_', '-')
|
||||
->replaceMatches('/[^a-zA-Z0-9-]+/', '-')
|
||||
->replaceMatches('/-+/', '-')
|
||||
->trim('-')
|
||||
->toString();
|
||||
|
||||
if ($normalized === '') {
|
||||
$normalized = 'service';
|
||||
}
|
||||
|
||||
return $normalized.'-'.traefikServiceNameHash($serviceName);
|
||||
}
|
||||
|
||||
function getCurrentApplicationContainerStatus(Server $server, int $id, ?int $pullRequestId = null, ?bool $includePullrequests = false): Collection
|
||||
{
|
||||
$containers = collect([]);
|
||||
@@ -507,8 +538,10 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
|
||||
$http_label = "http-{$loop}-{$uuid}";
|
||||
$https_label = "https-{$loop}-{$uuid}";
|
||||
if ($service_name) {
|
||||
$http_label = "http-{$loop}-{$uuid}-{$service_name}";
|
||||
$https_label = "https-{$loop}-{$uuid}-{$service_name}";
|
||||
// Dots in service names split Traefik label paths; hash avoids api.test/api-test collisions.
|
||||
$safeServiceName = traefikSafeServiceNameSegment($service_name);
|
||||
$http_label = "http-{$loop}-{$uuid}-{$safeServiceName}";
|
||||
$https_label = "https-{$loop}-{$uuid}-{$safeServiceName}";
|
||||
}
|
||||
if (str($image)->contains('ghost')) {
|
||||
$labels->push("traefik.http.middlewares.redir-ghost-{$uuid}.redirectregex.regex=^{$path}/(.*)");
|
||||
|
||||
Reference in New Issue
Block a user