fix: remove SERVICE_ stuff from raw compose
feat: multiport predefined compose fix: use predefined name as prefix for fqdn
This commit is contained in:
parent
d4a7d0d25f
commit
af69575b29
@ -140,7 +140,7 @@ public function parse(bool $isNew = false): Collection
|
|||||||
}
|
}
|
||||||
$definedNetwork = collect([$this->uuid]);
|
$definedNetwork = collect([$this->uuid]);
|
||||||
|
|
||||||
$services = collect($services)->map(function ($service, $serviceName) use ($topLevelVolumes, $topLevelNetworks, $definedNetwork, $isNew, $generatedServiceFQDNS) {
|
$services = collect($services)->map(function ($service, $serviceName) use ($topLevelVolumes, $topLevelNetworks, $definedNetwork, $isNew, $generatedServiceFQDNS, $yaml) {
|
||||||
$serviceVolumes = collect(data_get($service, 'volumes', []));
|
$serviceVolumes = collect(data_get($service, 'volumes', []));
|
||||||
$servicePorts = collect(data_get($service, 'ports', []));
|
$servicePorts = collect(data_get($service, 'ports', []));
|
||||||
$serviceNetworks = collect(data_get($service, 'networks', []));
|
$serviceNetworks = collect(data_get($service, 'networks', []));
|
||||||
@ -266,7 +266,7 @@ public function parse(bool $isNew = false): Collection
|
|||||||
|
|
||||||
// Collect/create/update volumes
|
// Collect/create/update volumes
|
||||||
if ($serviceVolumes->count() > 0) {
|
if ($serviceVolumes->count() > 0) {
|
||||||
$serviceVolumes = $serviceVolumes->map(function ($volume) use ($savedService, $topLevelVolumes, $isNew) {
|
$serviceVolumes = $serviceVolumes->map(function ($volume) use ($savedService, $topLevelVolumes, $isNew, $yaml) {
|
||||||
$type = null;
|
$type = null;
|
||||||
$source = null;
|
$source = null;
|
||||||
$target = null;
|
$target = null;
|
||||||
@ -384,9 +384,20 @@ public function parse(bool $isNew = false): Collection
|
|||||||
$value = Str::of($variable);
|
$value = Str::of($variable);
|
||||||
}
|
}
|
||||||
if ($key->startsWith('SERVICE_FQDN')) {
|
if ($key->startsWith('SERVICE_FQDN')) {
|
||||||
if (is_null(data_get($savedService, 'fqdn'))) {
|
if ($isNew) {
|
||||||
$fqdn = generateFqdn($this->server, $containerName);
|
$name = $key->after('SERVICE_FQDN_')->beforeLast('_')->lower();
|
||||||
if (substr_count($key->value(), '_') === 2) {
|
$fqdn = generateFqdn($this->server, "{$name->value()}-{$this->uuid}");
|
||||||
|
if (substr_count($key->value(), '_') === 3) {
|
||||||
|
// SERVICE_FQDN_UMAMI_1000
|
||||||
|
$port = $key->afterLast('_');
|
||||||
|
} else {
|
||||||
|
// SERVICE_FQDN_UMAMI
|
||||||
|
$port = null;
|
||||||
|
}
|
||||||
|
if ($port) {
|
||||||
|
$fqdn = "$fqdn:$port";
|
||||||
|
}
|
||||||
|
if (substr_count($key->value(), '_') >= 2) {
|
||||||
if (is_null($value)) {
|
if (is_null($value)) {
|
||||||
$value = Str::of('/');
|
$value = Str::of('/');
|
||||||
}
|
}
|
||||||
@ -403,12 +414,27 @@ public function parse(bool $isNew = false): Collection
|
|||||||
}
|
}
|
||||||
$fqdn = "$fqdn$path";
|
$fqdn = "$fqdn$path";
|
||||||
}
|
}
|
||||||
|
// } else if (substr_count($key->value(), '_') === 3) {
|
||||||
|
// if (is_null($value)) {
|
||||||
|
// $value = Str::of('/');
|
||||||
|
// }
|
||||||
|
// $path = $value->value();
|
||||||
|
// }
|
||||||
if (!$isDatabase) {
|
if (!$isDatabase) {
|
||||||
|
if ($savedService->fqdn) {
|
||||||
|
$fqdn = $savedService->fqdn . ',' . $fqdn;
|
||||||
|
} else {
|
||||||
|
$fqdn = $fqdn;
|
||||||
|
}
|
||||||
$savedService->fqdn = $fqdn;
|
$savedService->fqdn = $fqdn;
|
||||||
$savedService->save();
|
$savedService->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data_forget($service, "environment.$variableName");
|
data_forget($service, "environment.$variableName");
|
||||||
|
$yaml = data_forget($yaml, "services.$serviceName.environment.$variableName");
|
||||||
|
if (count(data_get($yaml, 'services.' . $serviceName . '.environment')) === 0) {
|
||||||
|
$yaml = data_forget($yaml, "services.$serviceName.environment");
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($value?->startsWith('$')) {
|
if ($value?->startsWith('$')) {
|
||||||
@ -522,14 +548,12 @@ public function parse(bool $isNew = false): Collection
|
|||||||
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik($fqdns, $containerName, true));
|
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik($fqdns, $containerName, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data_set($service, 'labels', $serviceLabels->toArray());
|
data_set($service, 'labels', $serviceLabels->toArray());
|
||||||
data_forget($service, 'is_database');
|
data_forget($service, 'is_database');
|
||||||
data_set($service, 'restart', RESTART_MODE);
|
data_set($service, 'restart', RESTART_MODE);
|
||||||
data_set($service, 'container_name', $containerName);
|
data_set($service, 'container_name', $containerName);
|
||||||
data_forget($service, 'volumes.*.content');
|
data_forget($service, 'volumes.*.content');
|
||||||
data_forget($service, 'volumes.*.isDirectory');
|
data_forget($service, 'volumes.*.isDirectory');
|
||||||
|
|
||||||
// Remove unnecessary variables from service.environment
|
// Remove unnecessary variables from service.environment
|
||||||
$withoutServiceEnvs = collect([]);
|
$withoutServiceEnvs = collect([]);
|
||||||
collect(data_get($service, 'environment'))->each(function ($value, $key) use ($withoutServiceEnvs) {
|
collect(data_get($service, 'environment'))->each(function ($value, $key) use ($withoutServiceEnvs) {
|
||||||
@ -538,6 +562,7 @@ public function parse(bool $isNew = false): Collection
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
data_set($service, 'environment', $withoutServiceEnvs->toArray());
|
data_set($service, 'environment', $withoutServiceEnvs->toArray());
|
||||||
|
$this->docker_compose_raw = Yaml::dump($yaml, 10, 2);
|
||||||
return $service;
|
return $service;
|
||||||
});
|
});
|
||||||
$finalServices = [
|
$finalServices = [
|
||||||
@ -546,7 +571,6 @@ public function parse(bool $isNew = false): Collection
|
|||||||
'volumes' => $topLevelVolumes->toArray(),
|
'volumes' => $topLevelVolumes->toArray(),
|
||||||
'networks' => $topLevelNetworks->toArray(),
|
'networks' => $topLevelNetworks->toArray(),
|
||||||
];
|
];
|
||||||
$this->docker_compose_raw = Yaml::dump($yaml, 10, 2);
|
|
||||||
$this->docker_compose = Yaml::dump($finalServices, 10, 2);
|
$this->docker_compose = Yaml::dump($finalServices, 10, 2);
|
||||||
$this->save();
|
$this->save();
|
||||||
$this->saveComposeConfigs();
|
$this->saveComposeConfigs();
|
||||||
|
Loading…
Reference in New Issue
Block a user