feat: COOLIFY_CONTAINER_NAME predefined variable

This commit is contained in:
Andras Bacsai 2024-06-14 14:23:40 +02:00
parent b17be37aee
commit 1ecd0307ed
2 changed files with 14 additions and 0 deletions

View File

@ -828,6 +828,9 @@ private function save_environment_variables()
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_BRANCH')->isEmpty()) {
$envs->push("COOLIFY_BRANCH={$local_branch}");
}
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) {
$envs->push("COOLIFY_CONTAINER_NAME={$this->container_name}");
}
foreach ($sorted_environment_variables_preview as $env) {
$real_value = $env->real_value;
if ($env->version === '4.0.0-beta.239') {
@ -869,6 +872,9 @@ private function save_environment_variables()
if ($this->application->environment_variables->where('key', 'COOLIFY_BRANCH')->isEmpty()) {
$envs->push("COOLIFY_BRANCH={$local_branch}");
}
if ($this->application->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) {
$envs->push("COOLIFY_CONTAINER_NAME={$this->container_name}");
}
foreach ($sorted_environment_variables as $env) {
$real_value = $env->real_value;
if ($env->version === '4.0.0-beta.239') {

View File

@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
use Symfony\Component\Yaml\Yaml;
class Service extends BaseModel
{
@ -837,6 +838,13 @@ public function saveComposeConfigs()
$commands[] = "mkdir -p $workdir";
$commands[] = "cd $workdir";
$json = Yaml::parse($this->docker_compose);
foreach($json['services'] as $service => $config) {
$envs = collect($config['environment']);
$envs->push("COOLIFY_CONTAINER_NAME=$service-{$this->uuid}");
data_set($json, "services.$service.environment", $envs->toArray());
}
$this->docker_compose = Yaml::dump($json);
$docker_compose_base64 = base64_encode($this->docker_compose);
$commands[] = "echo $docker_compose_base64 | base64 -d | tee docker-compose.yml > /dev/null";
$envs = $this->environment_variables()->get();