fix: parse docker composer

This commit is contained in:
Andras Bacsai
2024-07-26 19:58:52 +02:00
parent b04f7686fd
commit 8a4e958663

View File

@@ -964,7 +964,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
data_set($service, 'networks', $networks->toArray()); data_set($service, 'networks', $networks->toArray());
} }
// Collect/create/update volumes
if ($serviceVolumes->count() > 0) { if ($serviceVolumes->count() > 0) {
$serviceVolumes = $serviceVolumes->map(function ($volume) use ($savedService, $topLevelVolumes) { $serviceVolumes = $serviceVolumes->map(function ($volume) use ($savedService, $topLevelVolumes) {
$type = null; $type = null;
@@ -977,6 +976,8 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
$target = str($volume)->after(':')->beforeLast(':'); $target = str($volume)->after(':')->beforeLast(':');
if ($source->startsWith('./') || $source->startsWith('/') || $source->startsWith('~')) { if ($source->startsWith('./') || $source->startsWith('/') || $source->startsWith('~')) {
$type = str('bind'); $type = str('bind');
// By default, we cannot determine if the bind is a directory or not, so we set it to directory
$isDirectory = true;
} else { } else {
$type = str('volume'); $type = str('volume');
} }
@@ -985,14 +986,19 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
$source = data_get_str($volume, 'source'); $source = data_get_str($volume, 'source');
$target = data_get_str($volume, 'target'); $target = data_get_str($volume, 'target');
$content = data_get($volume, 'content'); $content = data_get($volume, 'content');
$isDirectory = (bool) data_get($volume, 'isDirectory', false) || (bool) data_get($volume, 'is_directory', false); $isDirectory = (bool) data_get($volume, 'isDirectory', null) || (bool) data_get($volume, 'is_directory', null);
$foundConfig = $savedService->fileStorages()->whereMountPath($target)->first(); $foundConfig = $savedService->fileStorages()->whereMountPath($target)->first();
if ($foundConfig) { if ($foundConfig) {
$contentNotNull = data_get($foundConfig, 'content'); $contentNotNull = data_get($foundConfig, 'content');
if ($contentNotNull) { if ($contentNotNull) {
$content = $contentNotNull; $content = $contentNotNull;
} }
$isDirectory = (bool) data_get($volume, 'isDirectory', false) || (bool) data_get($volume, 'is_directory', false); $isDirectory = (bool) data_get($volume, 'isDirectory', null) || (bool) data_get($volume, 'is_directory', null);
}
if (is_null($isDirectory) && is_null($content)) {
// if isDirectory is not set & content is also not set, we assume it is a directory
ray('setting isDirectory to true');
$isDirectory = true;
} }
} }
if ($type?->value() === 'bind') { if ($type?->value() === 'bind') {
@@ -1058,17 +1064,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
data_set($service, 'volumes', $serviceVolumes->toArray()); data_set($service, 'volumes', $serviceVolumes->toArray());
} }
// Add env_file with at least .env to the service
// $envFile = collect(data_get($service, 'env_file', []));
// if ($envFile->count() > 0) {
// if (!$envFile->contains('.env')) {
// $envFile->push('.env');
// }
// } else {
// $envFile = collect(['.env']);
// }
// data_set($service, 'env_file', $envFile->toArray());
// Get variables from the service // Get variables from the service
foreach ($serviceVariables as $variableName => $variable) { foreach ($serviceVariables as $variableName => $variable) {
if (is_numeric($variableName)) { if (is_numeric($variableName)) {