mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-17 17:21:04 +00:00
feat(deployments): generate SERVICE_NAME environment variables from Docker Compose services
- Added functionality to generate environment variables for each service defined in the Docker Compose file, transforming service names into uppercase and replacing special characters. - Updated the service parser to merge these generated variables with existing environment variables, enhancing deployment configuration.
This commit is contained in:
@@ -1263,6 +1263,21 @@ class Service extends BaseModel
|
||||
$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 @@ class Service extends BaseModel
|
||||
|
||||
return 3;
|
||||
});
|
||||
$envs = collect([]);
|
||||
foreach ($sorted as $env) {
|
||||
$envs->push("{$env->key}={$env->real_value}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user