fix: better parsign performance for huge compose files

fix: env parsing
This commit is contained in:
Andras Bacsai
2024-06-25 10:34:56 +02:00
parent 1de8657a56
commit 1266810c4d
4 changed files with 66 additions and 53 deletions

View File

@@ -11,7 +11,7 @@ class EditCompose extends Component
public $serviceId;
protected $listeners = ['refreshEnvs' => 'mount'];
protected $listeners = ['refreshEnvs', 'envsUpdated'];
protected $rules = [
'service.docker_compose_raw' => 'required',
@@ -19,6 +19,17 @@ class EditCompose extends Component
'service.is_container_label_escape_enabled' => 'required',
];
public function envsUpdated()
{
$this->dispatch('saveCompose', $this->service->docker_compose_raw);
$this->refreshEnvs();
}
public function refreshEnvs()
{
$this->service = Service::find($this->serviceId);
}
public function mount()
{
$this->service = Service::find($this->serviceId);

View File

@@ -112,7 +112,7 @@ class Show extends Component
$this->serialize();
$this->env->save();
$this->dispatch('success', 'Environment variable updated.');
$this->dispatch('refreshEnvs');
$this->dispatch('envsUpdated');
} catch (\Exception $e) {
return handleError($e);
}

View File

@@ -839,33 +839,13 @@ class Service extends BaseModel
$commands[] = "cd $workdir";
$json = Yaml::parse($this->docker_compose);
$envs_from_coolify = $this->environment_variables()->get();
// foreach ($json['services'] as $service => $config) {
// if (data_get($config, 'environment') === null) {
// data_set($json, "services.$service.environment", []);
// $envs = collect([]);
// } else {
// $envs = collect($config['environment']);
// }
// // $envs->put('COOLIFY_CONTAINER_NAME', "$service-{$this->uuid}");
// foreach ($envs_from_coolify as $env) {
// $envs = $envs->map(function ($value) use ($env) {
// if (str($value)->startsWith($env->key)) {
// return "{$env->key}={$env->real_value}";
// }
// return $value;
// });
// }
// $envs = $envs->unique();
// data_set($json, "services.$service.environment", $envs->toArray());
// }
$this->docker_compose = Yaml::dump($json, 10, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
$docker_compose_base64 = base64_encode($this->docker_compose);
$commands[] = "echo $docker_compose_base64 | base64 -d | tee docker-compose.yml > /dev/null";
$commands[] = 'rm -f .env || true';
$envs_from_coolify = $this->environment_variables()->get();
foreach ($envs_from_coolify as $env) {
$commands[] = "echo '{$env->key}={$env->real_value}' >> .env";
}
@@ -884,7 +864,6 @@ class Service extends BaseModel
{
$networks = getTopLevelNetworks($this);
// ray($networks);
return $networks;
}
}