refactor: Improve Docker Compose parsing for services

This commit is contained in:
Andras Bacsai 2024-05-31 10:34:07 +02:00
parent 9cc3be152f
commit c96daad12c

View File

@ -657,21 +657,10 @@ function getTopLevelNetworks(Service|Application $resource)
} }
} }
function parseDockerComposeForServices(Service $resource) {
if (!data_get($resource,'docker_compose_raw')) {
return collect([]);
}
try {
$yaml = Yaml::parse(data_get($resource,'docker_compose_raw'));
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
}
function parseDockerComposeFile(Service|Application $resource, bool $isNew = false, int $pull_request_id = 0, bool $is_pr = false) function parseDockerComposeFile(Service|Application $resource, bool $isNew = false, int $pull_request_id = 0, bool $is_pr = false)
{ {
ray()->clearAll(); ray()->clearAll();
if ($resource->getMorphClass() === 'App\Models\Service') { if ($resource->getMorphClass() === 'App\Models\Service') {
// return parseDockerComposeForServices($resource);
if ($resource->docker_compose_raw) { if ($resource->docker_compose_raw) {
try { try {
$yaml = Yaml::parse($resource->docker_compose_raw); $yaml = Yaml::parse($resource->docker_compose_raw);
@ -700,8 +689,8 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
} }
$tempTopLevelVolumes->put($volumeName, $volume); $tempTopLevelVolumes->put($volumeName, $volume);
} }
$topLevelVolumes = collect($tempTopLevelVolumes);
} }
$topLevelVolumes = collect($tempTopLevelVolumes);
$services = collect($services)->map(function ($service, $serviceName) use ($topLevelVolumes, $topLevelNetworks, $definedNetwork, $isNew, $generatedServiceFQDNS, $resource, $allServices) { $services = collect($services)->map(function ($service, $serviceName) use ($topLevelVolumes, $topLevelNetworks, $definedNetwork, $isNew, $generatedServiceFQDNS, $resource, $allServices) {
// Workarounds for beta users. // Workarounds for beta users.
if ($serviceName === 'registry') { if ($serviceName === 'registry') {
@ -1320,8 +1309,8 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
} }
$tempTopLevelVolumes->put($volumeName, $volume); $tempTopLevelVolumes->put($volumeName, $volume);
} }
$topLevelVolumes = collect($tempTopLevelVolumes);
} }
$topLevelVolumes = collect($tempTopLevelVolumes);
$topLevelNetworks = collect(data_get($yaml, 'networks', [])); $topLevelNetworks = collect(data_get($yaml, 'networks', []));
$services = data_get($yaml, 'services'); $services = data_get($yaml, 'services');