Merge pull request #6757 from coollabsio/next
feat(deployments): generate SERVICE_NAME environment variables from Docker Compose services
This commit is contained in:
commit
390f6337fe
2 changed files with 19 additions and 2 deletions
|
|
@ -1263,6 +1263,21 @@ public function saveComposeConfigs()
|
|||
$commands[] = "cd $workdir";
|
||||
$commands[] = 'rm -f .env || true';
|
||||
|
||||
$envs = collect([]);
|
||||
|
||||
// Generate SERVICE_NAME_* environment variables from docker-compose services
|
||||
if ($this->docker_compose) {
|
||||
try {
|
||||
$dockerCompose = \Symfony\Component\Yaml\Yaml::parse($this->docker_compose);
|
||||
$services = data_get($dockerCompose, 'services', []);
|
||||
foreach ($services as $serviceName => $_) {
|
||||
$envs->push('SERVICE_NAME_'.str($serviceName)->replace('-', '_')->replace('.', '_')->upper().'='.$serviceName);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
ray($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$envs_from_coolify = $this->environment_variables()->get();
|
||||
$sorted = $envs_from_coolify->sortBy(function ($env) {
|
||||
if (str($env->key)->startsWith('SERVICE_')) {
|
||||
|
|
@ -1274,7 +1289,6 @@ public function saveComposeConfigs()
|
|||
|
||||
return 3;
|
||||
});
|
||||
$envs = collect([]);
|
||||
foreach ($sorted as $env) {
|
||||
$envs->push("{$env->key}={$env->real_value}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1172,6 +1172,9 @@ function serviceParser(Service $resource): Collection
|
|||
|
||||
$parsedServices = collect([]);
|
||||
|
||||
// Generate SERVICE_NAME variables for docker compose services
|
||||
$serviceNameEnvironments = generateDockerComposeServiceName($services);
|
||||
|
||||
$allMagicEnvironments = collect([]);
|
||||
// Presave services
|
||||
foreach ($services as $serviceName => $service) {
|
||||
|
|
@ -1988,7 +1991,7 @@ function serviceParser(Service $resource): Collection
|
|||
$payload['volumes'] = $volumesParsed;
|
||||
}
|
||||
if ($environment->count() > 0 || $coolifyEnvironments->count() > 0) {
|
||||
$payload['environment'] = $environment->merge($coolifyEnvironments);
|
||||
$payload['environment'] = $environment->merge($coolifyEnvironments)->merge($serviceNameEnvironments);
|
||||
}
|
||||
if ($logging) {
|
||||
$payload['logging'] = $logging;
|
||||
|
|
|
|||
Loading…
Reference in a new issue