mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-20 10:23:30 +00:00
fix(compose): normalize service-name keys for domains and env vars (#11040)
This commit is contained in:
+26
-28
@@ -2082,34 +2082,7 @@ class Application extends BaseModel
|
||||
$this->save();
|
||||
$parsedServices = $this->parse();
|
||||
if ($this->docker_compose_domains) {
|
||||
$decoded = json_decode($this->docker_compose_domains, true);
|
||||
$json = collect(is_array($decoded) ? $decoded : []);
|
||||
$normalized = collect();
|
||||
foreach ($json as $key => $value) {
|
||||
$normalizedKey = (string) str($key)->replace('-', '_')->replace('.', '_');
|
||||
$normalized->put($normalizedKey, $value);
|
||||
}
|
||||
$json = $normalized;
|
||||
$services = collect(data_get($parsedServices, 'services', []));
|
||||
foreach ($services as $name => $service) {
|
||||
if (str($name)->contains('-') || str($name)->contains('.')) {
|
||||
$replacedName = str($name)->replace('-', '_')->replace('.', '_');
|
||||
$services->put((string) $replacedName, $service);
|
||||
$services->forget((string) $name);
|
||||
}
|
||||
}
|
||||
$names = collect($services)->keys()->toArray();
|
||||
$jsonNames = $json->keys()->toArray();
|
||||
$diff = array_diff($jsonNames, $names);
|
||||
$json = $json->filter(function ($value, $key) use ($diff) {
|
||||
return ! in_array($key, $diff);
|
||||
});
|
||||
if ($json) {
|
||||
$this->docker_compose_domains = json_encode($json);
|
||||
} else {
|
||||
$this->docker_compose_domains = null;
|
||||
}
|
||||
$this->save();
|
||||
$this->reconcileDockerComposeDomains($parsedServices);
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -2126,6 +2099,31 @@ class Application extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
private function reconcileDockerComposeDomains(mixed $parsedServices): void
|
||||
{
|
||||
$services = collect(data_get($parsedServices, 'services', []));
|
||||
$serviceNames = $services->keys()->map(fn ($name) => (string) $name)->all();
|
||||
|
||||
if ($serviceNames === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = json_decode($this->docker_compose_domains, true);
|
||||
$rekeyed = rekeyComposeDomainsToServiceNames(
|
||||
is_array($decoded) ? $decoded : [],
|
||||
$serviceNames,
|
||||
);
|
||||
|
||||
$domains = collect($rekeyed)->filter(
|
||||
fn ($value, $key) => findComposeServiceName((string) $key, $serviceNames) !== null
|
||||
);
|
||||
|
||||
$this->docker_compose_domains = $domains->isNotEmpty()
|
||||
? json_encode($domains->all())
|
||||
: null;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function parseContainerLabels(?ApplicationPreview $preview = null)
|
||||
{
|
||||
$customLabels = data_get($this, 'custom_labels');
|
||||
|
||||
Reference in New Issue
Block a user