From 49a53236b04e7cab9d649af9c6dd7faab36c4ff9 Mon Sep 17 00:00:00 2001 From: Vahor Date: Tue, 27 Aug 2024 16:45:07 +0200 Subject: [PATCH 1/9] add env vars --- app/Jobs/ApplicationDeploymentJob.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index a16164ffc..e96dfcd9a 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -905,6 +905,19 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue $envs->push("COOLIFY_CONTAINER_NAME={$this->container_name}"); } } + if ($this->application->environment_variables_preview->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $envs->push("COOLIFY_APP_NAME={$this->application->name}"); + } + if ($this->application->environment_variables_preview->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $envs->push("COOLIFY_SERVER_IP={$this->application->destination->server->ip}"); + } + if ($this->application->environment_variables_preview->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $envs->push("COOLIFY_ENVIRONMENT_NAME={$this->application->environment->name}"); + } + if ($this->application->environment_variables_preview->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $envs->push("COOLIFY_PROJECT_NAME={$this->application->project()->name}"); + } + foreach ($sorted_environment_variables_preview as $env) { $real_value = $env->real_value; if ($env->version === '4.0.0-beta.239') { @@ -953,6 +966,19 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue $envs->push("COOLIFY_CONTAINER_NAME={$this->container_name}"); } } + if ($this->application->environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $envs->push("COOLIFY_APP_NAME={$this->application->name}"); + } + if ($this->application->environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $envs->push("COOLIFY_SERVER_IP={$this->application->destination->server->ip}"); + } + if ($this->application->environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $envs->push("COOLIFY_ENVIRONMENT_NAME={$this->application->environment->name}"); + } + if ($this->application->environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $envs->push("COOLIFY_PROJECT_NAME={$this->application->project()->name}"); + } + foreach ($sorted_environment_variables as $env) { $real_value = $env->real_value; if ($env->version === '4.0.0-beta.239') { From eb22155dccab6131d504c6f10eba2832bb40abc1 Mon Sep 17 00:00:00 2001 From: Vahor Date: Tue, 27 Aug 2024 18:28:59 +0200 Subject: [PATCH 2/9] send new vars to logdrain --- app/Actions/Database/StartClickhouse.php | 1 + app/Actions/Database/StartDragonfly.php | 1 + app/Actions/Database/StartKeydb.php | 1 + app/Actions/Database/StartMariadb.php | 1 + app/Actions/Database/StartMongodb.php | 1 + app/Actions/Database/StartMysql.php | 1 + app/Actions/Database/StartPostgresql.php | 19 ++--- app/Actions/Database/StartRedis.php | 1 + app/Actions/Server/InstallLogDrain.php | 21 ++++-- app/Jobs/ApplicationDeploymentJob.php | 1 + bootstrap/helpers/shared.php | 91 ++++++++++++------------ 11 files changed, 80 insertions(+), 59 deletions(-) diff --git a/app/Actions/Database/StartClickhouse.php b/app/Actions/Database/StartClickhouse.php index 7cac97dd4..4943d926c 100644 --- a/app/Actions/Database/StartClickhouse.php +++ b/app/Actions/Database/StartClickhouse.php @@ -85,6 +85,7 @@ class StartClickhouse 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]; } diff --git a/app/Actions/Database/StartDragonfly.php b/app/Actions/Database/StartDragonfly.php index b71e12e8e..c03f100f9 100644 --- a/app/Actions/Database/StartDragonfly.php +++ b/app/Actions/Database/StartDragonfly.php @@ -85,6 +85,7 @@ class StartDragonfly 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]; } diff --git a/app/Actions/Database/StartKeydb.php b/app/Actions/Database/StartKeydb.php index 46a6a760e..b13bc7552 100644 --- a/app/Actions/Database/StartKeydb.php +++ b/app/Actions/Database/StartKeydb.php @@ -84,6 +84,7 @@ class StartKeydb 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]; } diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php index 4868a5d33..b2b5f8f00 100644 --- a/app/Actions/Database/StartMariadb.php +++ b/app/Actions/Database/StartMariadb.php @@ -79,6 +79,7 @@ class StartMariadb 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]; } diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php index b606cfe9e..3ec8f0aa5 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -87,6 +87,7 @@ class StartMongodb 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]; } diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php index 003a853f8..7eba18b6a 100644 --- a/app/Actions/Database/StartMysql.php +++ b/app/Actions/Database/StartMysql.php @@ -79,6 +79,7 @@ class StartMysql 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]; } diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index 5f13471b6..184cc6897 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -22,7 +22,7 @@ class StartPostgresql { $this->database = $database; $container_name = $this->database->uuid; - $this->configuration_dir = database_configuration_dir().'/'.$container_name; + $this->configuration_dir = database_configuration_dir() . '/' . $container_name; $this->commands = [ "echo 'Starting {$database->name}.'", @@ -87,6 +87,7 @@ class StartPostgresql 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]; } @@ -109,7 +110,7 @@ class StartPostgresql $docker_compose['services'][$container_name]['volumes'][] = [ 'type' => 'bind', 'source' => $init_script, - 'target' => '/docker-entrypoint-initdb.d/'.basename($init_script), + 'target' => '/docker-entrypoint-initdb.d/' . basename($init_script), 'read_only' => true, ]; } @@ -117,7 +118,7 @@ class StartPostgresql if (! is_null($this->database->postgres_conf) && ! empty($this->database->postgres_conf)) { $docker_compose['services'][$container_name]['volumes'][] = [ 'type' => 'bind', - 'source' => $this->configuration_dir.'/custom-postgres.conf', + 'source' => $this->configuration_dir . '/custom-postgres.conf', 'target' => '/etc/postgresql/postgresql.conf', 'read_only' => true, ]; @@ -149,10 +150,10 @@ class StartPostgresql $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { - $local_persistent_volumes[] = $persistentStorage->host_path.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; } else { $volume_name = $persistentStorage->name; - $local_persistent_volumes[] = $volume_name.':'.$persistentStorage->mount_path; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; } } @@ -183,18 +184,18 @@ class StartPostgresql $environment_variables->push("$env->key=$env->real_value"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('POSTGRES_USER'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('POSTGRES_USER'))->isEmpty()) { $environment_variables->push("POSTGRES_USER={$this->database->postgres_user}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('PGUSER'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('PGUSER'))->isEmpty()) { $environment_variables->push("PGUSER={$this->database->postgres_user}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('POSTGRES_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('POSTGRES_PASSWORD'))->isEmpty()) { $environment_variables->push("POSTGRES_PASSWORD={$this->database->postgres_password}"); } - if ($environment_variables->filter(fn ($env) => str($env)->contains('POSTGRES_DB'))->isEmpty()) { + if ($environment_variables->filter(fn($env) => str($env)->contains('POSTGRES_DB'))->isEmpty()) { $environment_variables->push("POSTGRES_DB={$this->database->postgres_db}"); } diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php index 3e1181522..ee78501ea 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -88,6 +88,7 @@ class StartRedis 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]; } diff --git a/app/Actions/Server/InstallLogDrain.php b/app/Actions/Server/InstallLogDrain.php index 034d89fe7..66b436e2b 100644 --- a/app/Actions/Server/InstallLogDrain.php +++ b/app/Actions/Server/InstallLogDrain.php @@ -40,6 +40,7 @@ class InstallLogDrain Name forward Buffer_Chunk_Size 1M Buffer_Max_Size 6M + Tag docker.* [FILTER] Name grep Match * @@ -48,6 +49,10 @@ class InstallLogDrain Name modify Match * Set server_name {$server->name} + Rename COOLIFY_APP_NAME coolify.app_name + Rename COOLIFY_PROJECT_NAME coolify.project_name + Rename COOLIFY_SERVER_IP coolify.server_ip + Rename COOLIFY_ENVIRONMENT_NAME coolify.environment_name [OUTPUT] Name nrlogs Match * @@ -71,6 +76,7 @@ class InstallLogDrain tag ${HIGHLIGHT_PROJECT_ID} Buffer_Chunk_Size 1M Buffer_Max_Size 6M + Tag docker.* [OUTPUT] Name forward Match * @@ -91,6 +97,7 @@ class InstallLogDrain Name forward Buffer_Chunk_Size 1M Buffer_Max_Size 6M + Tag docker.* [FILTER] Name grep Match * @@ -99,6 +106,10 @@ class InstallLogDrain Name modify Match * Set server_name {$server->name} + Rename COOLIFY_APP_NAME coolify.app_name + Rename COOLIFY_PROJECT_NAME coolify.project_name + Rename COOLIFY_SERVER_IP coolify.server_ip + Rename COOLIFY_ENVIRONMENT_NAME coolify.environment_name [OUTPUT] Name http Match * @@ -157,11 +168,11 @@ Files: $base_uri = $server->settings->logdrain_newrelic_base_uri; $base_path = config('coolify.base_config_path'); - $config_path = $base_path.'/log-drains'; - $fluent_bit_config = $config_path.'/fluent-bit.conf'; - $parsers_config = $config_path.'/parsers.conf'; - $compose_path = $config_path.'/docker-compose.yml'; - $readme_path = $config_path.'/README.md'; + $config_path = $base_path . '/log-drains'; + $fluent_bit_config = $config_path . '/fluent-bit.conf'; + $parsers_config = $config_path . '/parsers.conf'; + $compose_path = $config_path . '/docker-compose.yml'; + $readme_path = $config_path . '/README.md'; $command = [ "echo 'Saving configuration'", "mkdir -p $config_path", diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index e96dfcd9a..fe22292d4 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1756,6 +1756,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]; } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 3da005c3d..31ba7989f 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -63,27 +63,27 @@ function base_configuration_dir(): string } function application_configuration_dir(): string { - return base_configuration_dir().'/applications'; + return base_configuration_dir() . '/applications'; } function service_configuration_dir(): string { - return base_configuration_dir().'/services'; + return base_configuration_dir() . '/services'; } function database_configuration_dir(): string { - return base_configuration_dir().'/databases'; + return base_configuration_dir() . '/databases'; } function database_proxy_dir($uuid): string { - return base_configuration_dir()."/databases/$uuid/proxy"; + return base_configuration_dir() . "/databases/$uuid/proxy"; } function backup_dir(): string { - return base_configuration_dir().'/backups'; + return base_configuration_dir() . '/backups'; } function metrics_dir(): string { - return base_configuration_dir().'/metrics'; + return base_configuration_dir() . '/metrics'; } function generate_readme_file(string $name, string $updated_at): string @@ -118,8 +118,8 @@ function refreshSession(?Team $team = null): void $team = User::find(auth()->user()->id)->teams->first(); } } - Cache::forget('team:'.auth()->user()->id); - Cache::remember('team:'.auth()->user()->id, 3600, function () use ($team) { + Cache::forget('team:' . auth()->user()->id); + Cache::remember('team:' . auth()->user()->id, 3600, function () use ($team) { return $team; }); session(['currentTeam' => $team]); @@ -148,7 +148,7 @@ function handleError(?Throwable $error = null, ?Livewire\Component $livewire = n $message = null; } if ($customErrorMessage) { - $message = $customErrorMessage.' '.$message; + $message = $customErrorMessage . ' ' . $message; } if (isset($livewire)) { @@ -393,7 +393,7 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null Mail::send( [], [], - fn (Message $message) => $message + fn(Message $message) => $message ->to($email) ->replyTo($email) ->cc($cc) @@ -404,7 +404,7 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null Mail::send( [], [], - fn (Message $message) => $message + fn(Message $message) => $message ->to($email) ->subject($mail->subject) ->html((string) $mail->render()) @@ -627,19 +627,19 @@ function queryResourcesByUuid(string $uuid) function generatTagDeployWebhook($tag_name) { $baseUrl = base_url(); - $api = Url::fromString($baseUrl).'/api/v1'; + $api = Url::fromString($baseUrl) . '/api/v1'; $endpoint = "/deploy?tag=$tag_name"; - $url = $api.$endpoint; + $url = $api . $endpoint; return $url; } function generateDeployWebhook($resource) { $baseUrl = base_url(); - $api = Url::fromString($baseUrl).'/api/v1'; + $api = Url::fromString($baseUrl) . '/api/v1'; $endpoint = '/deploy'; $uuid = data_get($resource, 'uuid'); - $url = $api.$endpoint."?uuid=$uuid&force=false"; + $url = $api . $endpoint . "?uuid=$uuid&force=false"; return $url; } @@ -650,7 +650,7 @@ function generateGitManualWebhook($resource, $type) } if ($resource->getMorphClass() === 'App\Models\Application') { $baseUrl = base_url(); - $api = Url::fromString($baseUrl)."/webhooks/source/$type/events/manual"; + $api = Url::fromString($baseUrl) . "/webhooks/source/$type/events/manual"; return $api; } @@ -1819,7 +1819,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if (! $isDatabase) { if ($savedService->fqdn) { - data_set($savedService, 'fqdn', $savedService->fqdn.','.$fqdn); + data_set($savedService, 'fqdn', $savedService->fqdn . ',' . $fqdn); } else { data_set($savedService, 'fqdn', $fqdn); } @@ -1879,7 +1879,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if (Str::lower($forService) === $serviceName) { $fqdn = generateFqdn($resource->server, $containerName); } else { - $fqdn = generateFqdn($resource->server, Str::lower($forService).'-'.$resource->uuid); + $fqdn = generateFqdn($resource->server, Str::lower($forService) . '-' . $resource->uuid); } if ($port) { $fqdn = "$fqdn:$port"; @@ -2056,6 +2056,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]); } @@ -2083,7 +2084,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal updateCompose($savedService); return $service; - }); $envs_from_coolify = $resource->environment_variables()->get(); @@ -2215,7 +2215,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $volume->before(':'); $mount = $volume->after(':'); if ($name->startsWith('.') || $name->startsWith('~')) { - $dir = base_configuration_dir().'/applications/'.$resource->uuid; + $dir = base_configuration_dir() . '/applications/' . $resource->uuid; if ($name->startsWith('.')) { $name = $name->replaceFirst('.', $dir); } @@ -2223,12 +2223,12 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $name->replaceFirst('~', $dir); } if ($pull_request_id !== 0) { - $name = $name."-pr-$pull_request_id"; + $name = $name . "-pr-$pull_request_id"; } $volume = str("$name:$mount"); } else { if ($pull_request_id !== 0) { - $name = $name."-pr-$pull_request_id"; + $name = $name . "-pr-$pull_request_id"; $volume = str("$name:$mount"); if ($topLevelVolumes->has($name)) { $v = $topLevelVolumes->get($name); @@ -2267,7 +2267,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $volume->before(':'); $mount = $volume->after(':'); if ($pull_request_id !== 0) { - $name = $name."-pr-$pull_request_id"; + $name = $name . "-pr-$pull_request_id"; } $volume = str("$name:$mount"); } @@ -2278,7 +2278,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $read_only = data_get($volume, 'read_only'); if ($source && $target) { if ((str($source)->startsWith('.') || str($source)->startsWith('~'))) { - $dir = base_configuration_dir().'/applications/'.$resource->uuid; + $dir = base_configuration_dir() . '/applications/' . $resource->uuid; if (str($source, '.')) { $source = str($source)->replaceFirst('.', $dir); } @@ -2286,21 +2286,21 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $source = str($source)->replaceFirst('~', $dir); } if ($pull_request_id !== 0) { - $source = $source."-pr-$pull_request_id"; + $source = $source . "-pr-$pull_request_id"; } if ($read_only) { - data_set($volume, 'source', $source.':'.$target.':ro'); + data_set($volume, 'source', $source . ':' . $target . ':ro'); } else { - data_set($volume, 'source', $source.':'.$target); + data_set($volume, 'source', $source . ':' . $target); } } else { if ($pull_request_id !== 0) { - $source = $source."-pr-$pull_request_id"; + $source = $source . "-pr-$pull_request_id"; } if ($read_only) { - data_set($volume, 'source', $source.':'.$target.':ro'); + data_set($volume, 'source', $source . ':' . $target . ':ro'); } else { - data_set($volume, 'source', $source.':'.$target); + data_set($volume, 'source', $source . ':' . $target); } if (! str($source)->startsWith('/')) { if ($topLevelVolumes->has($source)) { @@ -2339,7 +2339,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $volume->before(':'); $mount = $volume->after(':'); if ($name->startsWith('.') || $name->startsWith('~')) { - $dir = base_configuration_dir().'/applications/'.$resource->uuid; + $dir = base_configuration_dir() . '/applications/' . $resource->uuid; if ($name->startsWith('.')) { $name = $name->replaceFirst('.', $dir); } @@ -2347,13 +2347,13 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $name->replaceFirst('~', $dir); } if ($pull_request_id !== 0) { - $name = $name."-pr-$pull_request_id"; + $name = $name . "-pr-$pull_request_id"; } $volume = str("$name:$mount"); } else { if ($pull_request_id !== 0) { $uuid = $resource->uuid; - $name = $uuid."-$name-pr-$pull_request_id"; + $name = $uuid . "-$name-pr-$pull_request_id"; $volume = str("$name:$mount"); if ($topLevelVolumes->has($name)) { $v = $topLevelVolumes->get($name); @@ -2372,7 +2372,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal } } else { $uuid = $resource->uuid; - $name = str($uuid."-$name"); + $name = str($uuid . "-$name"); $volume = str("$name:$mount"); if ($topLevelVolumes->has($name->value())) { $v = $topLevelVolumes->get($name->value()); @@ -2395,7 +2395,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $volume->before(':'); $mount = $volume->after(':'); if ($pull_request_id !== 0) { - $name = $name."-pr-$pull_request_id"; + $name = $name . "-pr-$pull_request_id"; } $volume = str("$name:$mount"); } @@ -2407,7 +2407,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if ($source && $target) { $uuid = $resource->uuid; if ((str($source)->startsWith('.') || str($source)->startsWith('~') || str($source)->startsWith('/'))) { - $dir = base_configuration_dir().'/applications/'.$resource->uuid; + $dir = base_configuration_dir() . '/applications/' . $resource->uuid; if (str($source, '.')) { $source = str($source)->replaceFirst('.', $dir); } @@ -2415,20 +2415,20 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $source = str($source)->replaceFirst('~', $dir); } if ($read_only) { - data_set($volume, 'source', $source.':'.$target.':ro'); + data_set($volume, 'source', $source . ':' . $target . ':ro'); } else { - data_set($volume, 'source', $source.':'.$target); + data_set($volume, 'source', $source . ':' . $target); } } else { if ($pull_request_id === 0) { - $source = $uuid."-$source"; + $source = $uuid . "-$source"; } else { - $source = $uuid."-$source-pr-$pull_request_id"; + $source = $uuid . "-$source-pr-$pull_request_id"; } if ($read_only) { - data_set($volume, 'source', $source.':'.$target.':ro'); + data_set($volume, 'source', $source . ':' . $target . ':ro'); } else { - data_set($volume, 'source', $source.':'.$target); + data_set($volume, 'source', $source . ':' . $target); } if (! str($source)->startsWith('/')) { if ($topLevelVolumes->has($source)) { @@ -2463,7 +2463,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if ($pull_request_id !== 0 && count($serviceDependencies) > 0) { $serviceDependencies = $serviceDependencies->map(function ($dependency) use ($pull_request_id) { - return $dependency."-pr-$pull_request_id"; + return $dependency . "-pr-$pull_request_id"; }); data_set($service, 'depends_on', $serviceDependencies->toArray()); } @@ -2634,7 +2634,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if (Str::lower($forService) === $serviceName) { $fqdn = generateFqdn($server, $containerName); } else { - $fqdn = generateFqdn($server, Str::lower($forService).'-'.$resource->uuid); + $fqdn = generateFqdn($server, Str::lower($forService) . '-' . $resource->uuid); } if ($port) { $fqdn = "$fqdn:$port"; @@ -2820,6 +2820,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal 'fluentd-address' => 'tcp://127.0.0.1:24224', 'fluentd-async' => 'true', 'fluentd-sub-second-precision' => 'true', + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', ], ]); } @@ -2843,7 +2844,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal }); if ($pull_request_id !== 0) { $services->each(function ($service, $serviceName) use ($pull_request_id, $services) { - $services[$serviceName."-pr-$pull_request_id"] = $service; + $services[$serviceName . "-pr-$pull_request_id"] = $service; data_forget($services, $serviceName); }); } From a245d16e0556191805072a6cbea318cc916a1541 Mon Sep 17 00:00:00 2001 From: Vahor Date: Tue, 27 Aug 2024 18:57:02 +0200 Subject: [PATCH 3/9] =?UTF-8?q?add=20env=20vars=20for=20db=20services=20?= =?UTF-8?q?=F0=9F=98=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Actions/Database/StartClickhouse.php | 15 +++++++++++++++ app/Actions/Database/StartKeydb.php | 15 +++++++++++++++ app/Actions/Database/StartMariadb.php | 15 +++++++++++++++ app/Actions/Database/StartMongodb.php | 15 +++++++++++++++ app/Actions/Database/StartMysql.php | 15 +++++++++++++++ app/Actions/Database/StartPostgresql.php | 15 +++++++++++++++ app/Actions/Database/StartRedis.php | 15 +++++++++++++++ 7 files changed, 105 insertions(+) diff --git a/app/Actions/Database/StartClickhouse.php b/app/Actions/Database/StartClickhouse.php index 4943d926c..508418557 100644 --- a/app/Actions/Database/StartClickhouse.php +++ b/app/Actions/Database/StartClickhouse.php @@ -168,6 +168,21 @@ class StartClickhouse $environment_variables->push("CLICKHOUSE_ADMIN_PASSWORD={$this->database->clickhouse_admin_password}"); } + // TODO: move this in a shared function + if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); + } + if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); + } + + return $environment_variables->all(); } } diff --git a/app/Actions/Database/StartKeydb.php b/app/Actions/Database/StartKeydb.php index b13bc7552..4493bf114 100644 --- a/app/Actions/Database/StartKeydb.php +++ b/app/Actions/Database/StartKeydb.php @@ -171,6 +171,21 @@ class StartKeydb $environment_variables->push("REDIS_PASSWORD={$this->database->keydb_password}"); } + // TODO: move this in a shared function + if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); + } + if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); + } + + return $environment_variables->all(); } diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php index b2b5f8f00..42b8ad272 100644 --- a/app/Actions/Database/StartMariadb.php +++ b/app/Actions/Database/StartMariadb.php @@ -177,6 +177,21 @@ class StartMariadb $environment_variables->push("MARIADB_PASSWORD={$this->database->mariadb_password}"); } + // TODO: move this in a shared function + if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); + } + if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); + } + + return $environment_variables->all(); } diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php index 3ec8f0aa5..954b8381a 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -190,6 +190,21 @@ class StartMongodb $environment_variables->push("MONGO_INITDB_DATABASE={$this->database->mongo_initdb_database}"); } + // TODO: move this in a shared function + if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); + } + if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); + } + + return $environment_variables->all(); } diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php index 7eba18b6a..9749eceac 100644 --- a/app/Actions/Database/StartMysql.php +++ b/app/Actions/Database/StartMysql.php @@ -177,6 +177,21 @@ class StartMysql $environment_variables->push("MYSQL_PASSWORD={$this->database->mysql_password}"); } + // TODO: move this in a shared function + if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); + } + if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); + } + + return $environment_variables->all(); } diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index 184cc6897..14a5a2930 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -199,6 +199,21 @@ class StartPostgresql $environment_variables->push("POSTGRES_DB={$this->database->postgres_db}"); } + // TODO: move this in a shared function + if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); + } + if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); + } + + return $environment_variables->all(); } diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php index ee78501ea..b7b32d304 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -176,6 +176,21 @@ class StartRedis $environment_variables->push("REDIS_PASSWORD={$this->database->redis_password}"); } + // TODO: move this in a shared function + if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); + } + if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); + } + if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); + } + + return $environment_variables->all(); } From 7103dccc72817fcfc14adb4e6e66a0806babc1a0 Mon Sep 17 00:00:00 2001 From: Vahor Date: Tue, 27 Aug 2024 19:09:04 +0200 Subject: [PATCH 4/9] add env vars for compose base apps --- app/Jobs/ApplicationDeploymentJob.php | 4 ++++ app/Models/Application.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index fe22292d4..ce798c715 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -905,6 +905,8 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue $envs->push("COOLIFY_CONTAINER_NAME={$this->container_name}"); } } + + // TODO: move this in a shared function if ($this->application->environment_variables_preview->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { $envs->push("COOLIFY_APP_NAME={$this->application->name}"); } @@ -966,6 +968,8 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue $envs->push("COOLIFY_CONTAINER_NAME={$this->container_name}"); } } + + // TODO: move this in a shared function if ($this->application->environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { $envs->push("COOLIFY_APP_NAME={$this->application->name}"); } diff --git a/app/Models/Application.php b/app/Models/Application.php index bb4dcdd0e..c788dd998 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -1471,6 +1471,20 @@ class Application extends BaseModel if ($this->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) { $environment->put('COOLIFY_CONTAINER_NAME', $containerName); } + // TODO: move this in a shared function + if ($this->environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $environment->push("COOLIFY_APP_NAME={$this->database->name}"); + } + if ($this->environment->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $environment->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); + } + if ($this->environment->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $environment->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); + } + if ($this->environment->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $environment->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); + } + // Remove SERVICE_FQDN and SERVICE_URL from environment $environment = $environment->filter(function ($value, $key) { return ! str($key)->startsWith('SERVICE_FQDN') && ! str($key)->startsWith('SERVICE_URL'); From 2d9c583af37679dcc6ecb57d4f1e3a66d0f83fcd Mon Sep 17 00:00:00 2001 From: Vahor Date: Tue, 27 Aug 2024 19:36:22 +0200 Subject: [PATCH 5/9] add env vars on old compose parser --- app/Actions/Server/InstallLogDrain.php | 4 ++-- bootstrap/helpers/shared.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/Actions/Server/InstallLogDrain.php b/app/Actions/Server/InstallLogDrain.php index 66b436e2b..d089fe991 100644 --- a/app/Actions/Server/InstallLogDrain.php +++ b/app/Actions/Server/InstallLogDrain.php @@ -48,7 +48,7 @@ class InstallLogDrain [FILTER] Name modify Match * - Set server_name {$server->name} + Set coolify.server_name {$server->name} Rename COOLIFY_APP_NAME coolify.app_name Rename COOLIFY_PROJECT_NAME coolify.project_name Rename COOLIFY_SERVER_IP coolify.server_ip @@ -105,7 +105,7 @@ class InstallLogDrain [FILTER] Name modify Match * - Set server_name {$server->name} + Set coolify.server_name {$server->name} Rename COOLIFY_APP_NAME coolify.app_name Rename COOLIFY_PROJECT_NAME coolify.project_name Rename COOLIFY_SERVER_IP coolify.server_ip diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 31ba7989f..83d0c3de3 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -2106,6 +2106,21 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal } } $parsedServiceVariables->put('COOLIFY_CONTAINER_NAME', "$serviceName-{$resource->uuid}"); + + // TODO: move this in a shared function + if (! $parsedServiceVariables->has('COOLIFY_APP_NAME')) { + $parsedServiceVariables->put('COOLIFY_APP_NAME', $resource->name); + } + if (! $parsedServiceVariables->has('COOLIFY_SERVER_IP')) { + $parsedServiceVariables->put("COOLIFY_SERVER_IP", $resource->destination->server->ip); + } + if (! $parsedServiceVariables->has('COOLIFY_ENVIRONMENT_NAME')) { + $parsedServiceVariables->put("COOLIFY_ENVIRONMENT_NAME", $resource->environment->name); + } + if (! $parsedServiceVariables->has('COOLIFY_PROJECT_NAME')) { + $parsedServiceVariables->put('COOLIFY_PROJECT_NAME', $resource->project()->name); + } + $parsedServiceVariables = $parsedServiceVariables->map(function ($value, $key) use ($envs_from_coolify) { if (! str($value)->startsWith('$')) { $found_env = $envs_from_coolify->where('key', $key)->first(); From c87732b065f1664f4951ce95a815678e94011109 Mon Sep 17 00:00:00 2001 From: Vahor Date: Tue, 27 Aug 2024 20:47:17 +0200 Subject: [PATCH 6/9] revert format --- app/Actions/Database/StartPostgresql.php | 18 ++--- app/Actions/Server/InstallLogDrain.php | 10 +-- bootstrap/helpers/shared.php | 89 ++++++++++++------------ 3 files changed, 59 insertions(+), 58 deletions(-) diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index 14a5a2930..65a7c6515 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -22,7 +22,7 @@ class StartPostgresql { $this->database = $database; $container_name = $this->database->uuid; - $this->configuration_dir = database_configuration_dir() . '/' . $container_name; + $this->configuration_dir = database_configuration_dir().'/'.$container_name; $this->commands = [ "echo 'Starting {$database->name}.'", @@ -110,7 +110,7 @@ class StartPostgresql $docker_compose['services'][$container_name]['volumes'][] = [ 'type' => 'bind', 'source' => $init_script, - 'target' => '/docker-entrypoint-initdb.d/' . basename($init_script), + 'target' => '/docker-entrypoint-initdb.d/'.basename($init_script), 'read_only' => true, ]; } @@ -118,7 +118,7 @@ class StartPostgresql if (! is_null($this->database->postgres_conf) && ! empty($this->database->postgres_conf)) { $docker_compose['services'][$container_name]['volumes'][] = [ 'type' => 'bind', - 'source' => $this->configuration_dir . '/custom-postgres.conf', + 'source' => $this->configuration_dir.'/custom-postgres.conf', 'target' => '/etc/postgresql/postgresql.conf', 'read_only' => true, ]; @@ -150,10 +150,10 @@ class StartPostgresql $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { - $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; + $local_persistent_volumes[] = $persistentStorage->host_path.':'.$persistentStorage->mount_path; } else { $volume_name = $persistentStorage->name; - $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + $local_persistent_volumes[] = $volume_name.':'.$persistentStorage->mount_path; } } @@ -184,18 +184,18 @@ class StartPostgresql $environment_variables->push("$env->key=$env->real_value"); } - if ($environment_variables->filter(fn($env) => str($env)->contains('POSTGRES_USER'))->isEmpty()) { + if ($environment_variables->filter(fn ($env) => str($env)->contains('POSTGRES_USER'))->isEmpty()) { $environment_variables->push("POSTGRES_USER={$this->database->postgres_user}"); } - if ($environment_variables->filter(fn($env) => str($env)->contains('PGUSER'))->isEmpty()) { + if ($environment_variables->filter(fn ($env) => str($env)->contains('PGUSER'))->isEmpty()) { $environment_variables->push("PGUSER={$this->database->postgres_user}"); } - if ($environment_variables->filter(fn($env) => str($env)->contains('POSTGRES_PASSWORD'))->isEmpty()) { + if ($environment_variables->filter(fn ($env) => str($env)->contains('POSTGRES_PASSWORD'))->isEmpty()) { $environment_variables->push("POSTGRES_PASSWORD={$this->database->postgres_password}"); } - if ($environment_variables->filter(fn($env) => str($env)->contains('POSTGRES_DB'))->isEmpty()) { + if ($environment_variables->filter(fn ($env) => str($env)->contains('POSTGRES_DB'))->isEmpty()) { $environment_variables->push("POSTGRES_DB={$this->database->postgres_db}"); } diff --git a/app/Actions/Server/InstallLogDrain.php b/app/Actions/Server/InstallLogDrain.php index d089fe991..4d49a85db 100644 --- a/app/Actions/Server/InstallLogDrain.php +++ b/app/Actions/Server/InstallLogDrain.php @@ -168,11 +168,11 @@ Files: $base_uri = $server->settings->logdrain_newrelic_base_uri; $base_path = config('coolify.base_config_path'); - $config_path = $base_path . '/log-drains'; - $fluent_bit_config = $config_path . '/fluent-bit.conf'; - $parsers_config = $config_path . '/parsers.conf'; - $compose_path = $config_path . '/docker-compose.yml'; - $readme_path = $config_path . '/README.md'; + $config_path = $base_path.'/log-drains'; + $fluent_bit_config = $config_path.'/fluent-bit.conf'; + $parsers_config = $config_path.'/parsers.conf'; + $compose_path = $config_path.'/docker-compose.yml'; + $readme_path = $config_path.'/README.md'; $command = [ "echo 'Saving configuration'", "mkdir -p $config_path", diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 83d0c3de3..966587558 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -63,27 +63,27 @@ function base_configuration_dir(): string } function application_configuration_dir(): string { - return base_configuration_dir() . '/applications'; + return base_configuration_dir().'/applications'; } function service_configuration_dir(): string { - return base_configuration_dir() . '/services'; + return base_configuration_dir().'/services'; } function database_configuration_dir(): string { - return base_configuration_dir() . '/databases'; + return base_configuration_dir().'/databases'; } function database_proxy_dir($uuid): string { - return base_configuration_dir() . "/databases/$uuid/proxy"; + return base_configuration_dir()."/databases/$uuid/proxy"; } function backup_dir(): string { - return base_configuration_dir() . '/backups'; + return base_configuration_dir().'/backups'; } function metrics_dir(): string { - return base_configuration_dir() . '/metrics'; + return base_configuration_dir().'/metrics'; } function generate_readme_file(string $name, string $updated_at): string @@ -118,8 +118,8 @@ function refreshSession(?Team $team = null): void $team = User::find(auth()->user()->id)->teams->first(); } } - Cache::forget('team:' . auth()->user()->id); - Cache::remember('team:' . auth()->user()->id, 3600, function () use ($team) { + Cache::forget('team:'.auth()->user()->id); + Cache::remember('team:'.auth()->user()->id, 3600, function () use ($team) { return $team; }); session(['currentTeam' => $team]); @@ -148,7 +148,7 @@ function handleError(?Throwable $error = null, ?Livewire\Component $livewire = n $message = null; } if ($customErrorMessage) { - $message = $customErrorMessage . ' ' . $message; + $message = $customErrorMessage.' '.$message; } if (isset($livewire)) { @@ -393,7 +393,7 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null Mail::send( [], [], - fn(Message $message) => $message + fn (Message $message) => $message ->to($email) ->replyTo($email) ->cc($cc) @@ -404,7 +404,7 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null Mail::send( [], [], - fn(Message $message) => $message + fn (Message $message) => $message ->to($email) ->subject($mail->subject) ->html((string) $mail->render()) @@ -627,19 +627,19 @@ function queryResourcesByUuid(string $uuid) function generatTagDeployWebhook($tag_name) { $baseUrl = base_url(); - $api = Url::fromString($baseUrl) . '/api/v1'; + $api = Url::fromString($baseUrl).'/api/v1'; $endpoint = "/deploy?tag=$tag_name"; - $url = $api . $endpoint; + $url = $api.$endpoint; return $url; } function generateDeployWebhook($resource) { $baseUrl = base_url(); - $api = Url::fromString($baseUrl) . '/api/v1'; + $api = Url::fromString($baseUrl).'/api/v1'; $endpoint = '/deploy'; $uuid = data_get($resource, 'uuid'); - $url = $api . $endpoint . "?uuid=$uuid&force=false"; + $url = $api.$endpoint."?uuid=$uuid&force=false"; return $url; } @@ -650,7 +650,7 @@ function generateGitManualWebhook($resource, $type) } if ($resource->getMorphClass() === 'App\Models\Application') { $baseUrl = base_url(); - $api = Url::fromString($baseUrl) . "/webhooks/source/$type/events/manual"; + $api = Url::fromString($baseUrl)."/webhooks/source/$type/events/manual"; return $api; } @@ -1819,7 +1819,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if (! $isDatabase) { if ($savedService->fqdn) { - data_set($savedService, 'fqdn', $savedService->fqdn . ',' . $fqdn); + data_set($savedService, 'fqdn', $savedService->fqdn.','.$fqdn); } else { data_set($savedService, 'fqdn', $fqdn); } @@ -1879,7 +1879,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if (Str::lower($forService) === $serviceName) { $fqdn = generateFqdn($resource->server, $containerName); } else { - $fqdn = generateFqdn($resource->server, Str::lower($forService) . '-' . $resource->uuid); + $fqdn = generateFqdn($resource->server, Str::lower($forService).'-'.$resource->uuid); } if ($port) { $fqdn = "$fqdn:$port"; @@ -2084,6 +2084,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal updateCompose($savedService); return $service; + }); $envs_from_coolify = $resource->environment_variables()->get(); @@ -2230,7 +2231,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $volume->before(':'); $mount = $volume->after(':'); if ($name->startsWith('.') || $name->startsWith('~')) { - $dir = base_configuration_dir() . '/applications/' . $resource->uuid; + $dir = base_configuration_dir().'/applications/'.$resource->uuid; if ($name->startsWith('.')) { $name = $name->replaceFirst('.', $dir); } @@ -2238,12 +2239,12 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $name->replaceFirst('~', $dir); } if ($pull_request_id !== 0) { - $name = $name . "-pr-$pull_request_id"; + $name = $name."-pr-$pull_request_id"; } $volume = str("$name:$mount"); } else { if ($pull_request_id !== 0) { - $name = $name . "-pr-$pull_request_id"; + $name = $name."-pr-$pull_request_id"; $volume = str("$name:$mount"); if ($topLevelVolumes->has($name)) { $v = $topLevelVolumes->get($name); @@ -2282,7 +2283,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $volume->before(':'); $mount = $volume->after(':'); if ($pull_request_id !== 0) { - $name = $name . "-pr-$pull_request_id"; + $name = $name."-pr-$pull_request_id"; } $volume = str("$name:$mount"); } @@ -2293,7 +2294,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $read_only = data_get($volume, 'read_only'); if ($source && $target) { if ((str($source)->startsWith('.') || str($source)->startsWith('~'))) { - $dir = base_configuration_dir() . '/applications/' . $resource->uuid; + $dir = base_configuration_dir().'/applications/'.$resource->uuid; if (str($source, '.')) { $source = str($source)->replaceFirst('.', $dir); } @@ -2301,21 +2302,21 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $source = str($source)->replaceFirst('~', $dir); } if ($pull_request_id !== 0) { - $source = $source . "-pr-$pull_request_id"; + $source = $source."-pr-$pull_request_id"; } if ($read_only) { - data_set($volume, 'source', $source . ':' . $target . ':ro'); + data_set($volume, 'source', $source.':'.$target.':ro'); } else { - data_set($volume, 'source', $source . ':' . $target); + data_set($volume, 'source', $source.':'.$target); } } else { if ($pull_request_id !== 0) { - $source = $source . "-pr-$pull_request_id"; + $source = $source."-pr-$pull_request_id"; } if ($read_only) { - data_set($volume, 'source', $source . ':' . $target . ':ro'); + data_set($volume, 'source', $source.':'.$target.':ro'); } else { - data_set($volume, 'source', $source . ':' . $target); + data_set($volume, 'source', $source.':'.$target); } if (! str($source)->startsWith('/')) { if ($topLevelVolumes->has($source)) { @@ -2354,7 +2355,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $volume->before(':'); $mount = $volume->after(':'); if ($name->startsWith('.') || $name->startsWith('~')) { - $dir = base_configuration_dir() . '/applications/' . $resource->uuid; + $dir = base_configuration_dir().'/applications/'.$resource->uuid; if ($name->startsWith('.')) { $name = $name->replaceFirst('.', $dir); } @@ -2362,13 +2363,13 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $name->replaceFirst('~', $dir); } if ($pull_request_id !== 0) { - $name = $name . "-pr-$pull_request_id"; + $name = $name."-pr-$pull_request_id"; } $volume = str("$name:$mount"); } else { if ($pull_request_id !== 0) { $uuid = $resource->uuid; - $name = $uuid . "-$name-pr-$pull_request_id"; + $name = $uuid."-$name-pr-$pull_request_id"; $volume = str("$name:$mount"); if ($topLevelVolumes->has($name)) { $v = $topLevelVolumes->get($name); @@ -2387,7 +2388,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal } } else { $uuid = $resource->uuid; - $name = str($uuid . "-$name"); + $name = str($uuid."-$name"); $volume = str("$name:$mount"); if ($topLevelVolumes->has($name->value())) { $v = $topLevelVolumes->get($name->value()); @@ -2410,7 +2411,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $name = $volume->before(':'); $mount = $volume->after(':'); if ($pull_request_id !== 0) { - $name = $name . "-pr-$pull_request_id"; + $name = $name."-pr-$pull_request_id"; } $volume = str("$name:$mount"); } @@ -2422,7 +2423,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if ($source && $target) { $uuid = $resource->uuid; if ((str($source)->startsWith('.') || str($source)->startsWith('~') || str($source)->startsWith('/'))) { - $dir = base_configuration_dir() . '/applications/' . $resource->uuid; + $dir = base_configuration_dir().'/applications/'.$resource->uuid; if (str($source, '.')) { $source = str($source)->replaceFirst('.', $dir); } @@ -2430,20 +2431,20 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $source = str($source)->replaceFirst('~', $dir); } if ($read_only) { - data_set($volume, 'source', $source . ':' . $target . ':ro'); + data_set($volume, 'source', $source.':'.$target.':ro'); } else { - data_set($volume, 'source', $source . ':' . $target); + data_set($volume, 'source', $source.':'.$target); } } else { if ($pull_request_id === 0) { - $source = $uuid . "-$source"; + $source = $uuid."-$source"; } else { - $source = $uuid . "-$source-pr-$pull_request_id"; + $source = $uuid."-$source-pr-$pull_request_id"; } if ($read_only) { - data_set($volume, 'source', $source . ':' . $target . ':ro'); + data_set($volume, 'source', $source.':'.$target.':ro'); } else { - data_set($volume, 'source', $source . ':' . $target); + data_set($volume, 'source', $source.':'.$target); } if (! str($source)->startsWith('/')) { if ($topLevelVolumes->has($source)) { @@ -2478,7 +2479,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if ($pull_request_id !== 0 && count($serviceDependencies) > 0) { $serviceDependencies = $serviceDependencies->map(function ($dependency) use ($pull_request_id) { - return $dependency . "-pr-$pull_request_id"; + return $dependency."-pr-$pull_request_id"; }); data_set($service, 'depends_on', $serviceDependencies->toArray()); } @@ -2649,7 +2650,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if (Str::lower($forService) === $serviceName) { $fqdn = generateFqdn($server, $containerName); } else { - $fqdn = generateFqdn($server, Str::lower($forService) . '-' . $resource->uuid); + $fqdn = generateFqdn($server, Str::lower($forService).'-'.$resource->uuid); } if ($port) { $fqdn = "$fqdn:$port"; @@ -2859,7 +2860,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal }); if ($pull_request_id !== 0) { $services->each(function ($service, $serviceName) use ($pull_request_id, $services) { - $services[$serviceName . "-pr-$pull_request_id"] = $service; + $services[$serviceName."-pr-$pull_request_id"] = $service; data_forget($services, $serviceName); }); } From 0cf595e552f140f42f59b343bc06e9ad34516c52 Mon Sep 17 00:00:00 2001 From: Vahor Date: Tue, 27 Aug 2024 20:52:51 +0200 Subject: [PATCH 7/9] remove unused tag --- app/Actions/Server/InstallLogDrain.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Actions/Server/InstallLogDrain.php b/app/Actions/Server/InstallLogDrain.php index 4d49a85db..9b6741211 100644 --- a/app/Actions/Server/InstallLogDrain.php +++ b/app/Actions/Server/InstallLogDrain.php @@ -40,7 +40,6 @@ class InstallLogDrain Name forward Buffer_Chunk_Size 1M Buffer_Max_Size 6M - Tag docker.* [FILTER] Name grep Match * @@ -76,7 +75,6 @@ class InstallLogDrain tag ${HIGHLIGHT_PROJECT_ID} Buffer_Chunk_Size 1M Buffer_Max_Size 6M - Tag docker.* [OUTPUT] Name forward Match * @@ -97,7 +95,6 @@ class InstallLogDrain Name forward Buffer_Chunk_Size 1M Buffer_Max_Size 6M - Tag docker.* [FILTER] Name grep Match * From b51065a003ec5bf67bfc32ba4d084660977e23e8 Mon Sep 17 00:00:00 2001 From: Vahor Date: Wed, 28 Aug 2024 11:11:14 +0200 Subject: [PATCH 8/9] add generate_fluentd_configuration() method in shared --- app/Actions/Database/StartClickhouse.php | 10 +----- app/Actions/Database/StartDragonfly.php | 10 +----- app/Actions/Database/StartKeydb.php | 10 +----- app/Actions/Database/StartMariadb.php | 10 +----- app/Actions/Database/StartMongodb.php | 10 +----- app/Actions/Database/StartMysql.php | 10 +----- app/Actions/Database/StartPostgresql.php | 10 +----- app/Actions/Database/StartRedis.php | 10 +----- app/Jobs/ApplicationDeploymentJob.php | 10 +----- app/Models/Application.php | 9 +---- app/Models/Service.php | 9 +---- bootstrap/helpers/shared.php | 42 +++++++++--------------- 12 files changed, 27 insertions(+), 123 deletions(-) diff --git a/app/Actions/Database/StartClickhouse.php b/app/Actions/Database/StartClickhouse.php index 508418557..7316bcd32 100644 --- a/app/Actions/Database/StartClickhouse.php +++ b/app/Actions/Database/StartClickhouse.php @@ -79,15 +79,7 @@ class StartClickhouse data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { - $docker_compose['services'][$container_name]['logging'] = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]; + $docker_compose['services'][$container_name]['logging'] = generate_fluentd_configuration(); } if (count($this->database->ports_mappings_array) > 0) { $docker_compose['services'][$container_name]['ports'] = $this->database->ports_mappings_array; diff --git a/app/Actions/Database/StartDragonfly.php b/app/Actions/Database/StartDragonfly.php index c03f100f9..621834df0 100644 --- a/app/Actions/Database/StartDragonfly.php +++ b/app/Actions/Database/StartDragonfly.php @@ -79,15 +79,7 @@ class StartDragonfly data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { - $docker_compose['services'][$container_name]['logging'] = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]; + $docker_compose['services'][$container_name]['logging'] = generate_fluentd_configuration(); } if (count($this->database->ports_mappings_array) > 0) { $docker_compose['services'][$container_name]['ports'] = $this->database->ports_mappings_array; diff --git a/app/Actions/Database/StartKeydb.php b/app/Actions/Database/StartKeydb.php index 4493bf114..5b49b42e7 100644 --- a/app/Actions/Database/StartKeydb.php +++ b/app/Actions/Database/StartKeydb.php @@ -78,15 +78,7 @@ class StartKeydb data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { - $docker_compose['services'][$container_name]['logging'] = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]; + $docker_compose['services'][$container_name]['logging'] = generate_fluentd_configuration(); } if (count($this->database->ports_mappings_array) > 0) { $docker_compose['services'][$container_name]['ports'] = $this->database->ports_mappings_array; diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php index 42b8ad272..045ae4014 100644 --- a/app/Actions/Database/StartMariadb.php +++ b/app/Actions/Database/StartMariadb.php @@ -73,15 +73,7 @@ class StartMariadb data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { - $docker_compose['services'][$container_name]['logging'] = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]; + $docker_compose['services'][$container_name]['logging'] = generate_fluentd_configuration(); } if (count($this->database->ports_mappings_array) > 0) { $docker_compose['services'][$container_name]['ports'] = $this->database->ports_mappings_array; diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php index 954b8381a..154510836 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -81,15 +81,7 @@ class StartMongodb data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { - $docker_compose['services'][$container_name]['logging'] = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]; + $docker_compose['services'][$container_name]['logging'] = generate_fluentd_configuration(); } if (count($this->database->ports_mappings_array) > 0) { $docker_compose['services'][$container_name]['ports'] = $this->database->ports_mappings_array; diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php index 9749eceac..0ffc93578 100644 --- a/app/Actions/Database/StartMysql.php +++ b/app/Actions/Database/StartMysql.php @@ -73,15 +73,7 @@ class StartMysql data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { - $docker_compose['services'][$container_name]['logging'] = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]; + $docker_compose['services'][$container_name]['logging'] = generate_fluentd_configuration(); } if (count($this->database->ports_mappings_array) > 0) { $docker_compose['services'][$container_name]['ports'] = $this->database->ports_mappings_array; diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index 65a7c6515..f719a0fed 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -81,15 +81,7 @@ class StartPostgresql data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { - $docker_compose['services'][$container_name]['logging'] = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]; + $docker_compose['services'][$container_name]['logging'] = generate_fluentd_configuration(); } if (count($this->database->ports_mappings_array) > 0) { $docker_compose['services'][$container_name]['ports'] = $this->database->ports_mappings_array; diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php index b7b32d304..be33a4834 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -82,15 +82,7 @@ class StartRedis data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { - $docker_compose['services'][$container_name]['logging'] = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]; + $docker_compose['services'][$container_name]['logging'] = generate_fluentd_configuration(); } if (count($this->database->ports_mappings_array) > 0) { $docker_compose['services'][$container_name]['ports'] = $this->database->ports_mappings_array; diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index ce798c715..0cddf1d54 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1754,15 +1754,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue $docker_compose['services'][$this->container_name]['labels'] = $labels; } if ($this->server->isLogDrainEnabled() && $this->application->isLogDrainEnabled()) { - $docker_compose['services'][$this->container_name]['logging'] = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]; + $docker_compose['services'][$this->container_name]['logging'] = generate_fluentd_configuration(); } if ($this->application->settings->is_gpu_enabled) { $docker_compose['services'][$this->container_name]['deploy']['resources']['reservations']['devices'] = [ diff --git a/app/Models/Application.php b/app/Models/Application.php index c788dd998..604568df4 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -1131,14 +1131,7 @@ class Application extends BaseModel $logging = data_get($service, 'logging'); if ($server->isLogDrainEnabled() && $this->isLogDrainEnabled()) { - $logging = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - ], - ]; + $logging = generate_fluentd_configuration(); } $volumes = collect(data_get($service, 'volumes', [])); diff --git a/app/Models/Service.php b/app/Models/Service.php index 521f06427..d9d3a32fc 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -1050,14 +1050,7 @@ class Service extends BaseModel $logging = data_get($service, 'logging'); if ($server->isLogDrainEnabled() && $this->isLogDrainEnabled()) { - $logging = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - ], - ]; + $logging = generate_fluentd_configuration(); } $volumes = collect(data_get($service, 'volumes', [])); diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 966587558..a48c9754e 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -2050,15 +2050,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal } } if ($resource->server->isLogDrainEnabled() && $savedService->isLogDrainEnabled()) { - data_set($service, 'logging', [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]); + data_set($service, 'logging', generate_fluentd_configuration()); } if ($serviceLabels->count() > 0) { if ($resource->is_container_label_escape_enabled) { @@ -2830,15 +2822,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $serviceLabels = $serviceLabels->merge($defaultLabels); if ($server->isLogDrainEnabled() && $resource->isLogDrainEnabled()) { - data_set($service, 'logging', [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', - ], - ]); + data_set($service, 'logging', generate_fluentd_configuration()); } if ($serviceLabels->count() > 0) { if ($resource->settings->is_container_label_escape_enabled) { @@ -2939,14 +2923,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0) $logging = data_get($service, 'logging'); if ($server->isLogDrainEnabled() && $resource->isLogDrainEnabled()) { - $logging = [ - 'driver' => 'fluentd', - 'options' => [ - 'fluentd-address' => 'tcp://127.0.0.1:24224', - 'fluentd-async' => 'true', - 'fluentd-sub-second-precision' => 'true', - ], - ]; + $logging = generate_fluentd_configuration(); } $volumes = collect(data_get($service, 'volumes', [])); $networks = collect(data_get($service, 'networks', [])); @@ -3356,3 +3333,16 @@ function newParser(Application|Service $resource, int $pull_request_id = 0) return $topLevel; } + +function generate_fluentd_configuration() : array { + return [ + 'driver' => 'fluentd', + 'options' => [ + 'fluentd-address' => 'tcp://127.0.0.1:24224', + 'fluentd-async' => 'true', + 'fluentd-sub-second-precision' => 'true', + // env vars are used in the LogDrain configurations + 'env' => 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME', + ] + ]; +} From f6d649307c58c70288f320aadea9e77abc781d58 Mon Sep 17 00:00:00 2001 From: Vahor Date: Wed, 28 Aug 2024 13:30:59 +0200 Subject: [PATCH 9/9] test add_coolif_default_environment_variables --- app/Actions/Database/StartClickhouse.php | 15 +----------- app/Actions/Database/StartKeydb.php | 15 +----------- app/Actions/Database/StartMariadb.php | 15 +----------- app/Actions/Database/StartMongodb.php | 15 +----------- app/Actions/Database/StartMysql.php | 15 +----------- app/Actions/Database/StartPostgresql.php | 15 +----------- app/Actions/Database/StartRedis.php | 15 +----------- app/Jobs/ApplicationDeploymentJob.php | 28 ++--------------------- app/Models/Application.php | 14 +----------- bootstrap/helpers/shared.php | 29 ++++++++++++++++++++++++ 10 files changed, 39 insertions(+), 137 deletions(-) diff --git a/app/Actions/Database/StartClickhouse.php b/app/Actions/Database/StartClickhouse.php index 7316bcd32..c8d787cb2 100644 --- a/app/Actions/Database/StartClickhouse.php +++ b/app/Actions/Database/StartClickhouse.php @@ -160,20 +160,7 @@ class StartClickhouse $environment_variables->push("CLICKHOUSE_ADMIN_PASSWORD={$this->database->clickhouse_admin_password}"); } - // TODO: move this in a shared function - if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { - $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); - } - if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); - } - + add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables); return $environment_variables->all(); } diff --git a/app/Actions/Database/StartKeydb.php b/app/Actions/Database/StartKeydb.php index 5b49b42e7..9290efc7c 100644 --- a/app/Actions/Database/StartKeydb.php +++ b/app/Actions/Database/StartKeydb.php @@ -163,20 +163,7 @@ class StartKeydb $environment_variables->push("REDIS_PASSWORD={$this->database->keydb_password}"); } - // TODO: move this in a shared function - if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { - $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); - } - if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); - } - + add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables); return $environment_variables->all(); } diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php index 045ae4014..f37a5e361 100644 --- a/app/Actions/Database/StartMariadb.php +++ b/app/Actions/Database/StartMariadb.php @@ -169,20 +169,7 @@ class StartMariadb $environment_variables->push("MARIADB_PASSWORD={$this->database->mariadb_password}"); } - // TODO: move this in a shared function - if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { - $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); - } - if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); - } - + add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables); return $environment_variables->all(); } diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php index 154510836..42fc8f348 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -182,20 +182,7 @@ class StartMongodb $environment_variables->push("MONGO_INITDB_DATABASE={$this->database->mongo_initdb_database}"); } - // TODO: move this in a shared function - if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { - $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); - } - if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); - } - + add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables); return $environment_variables->all(); } diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php index 0ffc93578..2043342fe 100644 --- a/app/Actions/Database/StartMysql.php +++ b/app/Actions/Database/StartMysql.php @@ -169,20 +169,7 @@ class StartMysql $environment_variables->push("MYSQL_PASSWORD={$this->database->mysql_password}"); } - // TODO: move this in a shared function - if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { - $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); - } - if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); - } - + add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables); return $environment_variables->all(); } diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index f719a0fed..bc37fd5cf 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -191,20 +191,7 @@ class StartPostgresql $environment_variables->push("POSTGRES_DB={$this->database->postgres_db}"); } - // TODO: move this in a shared function - if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { - $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); - } - if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); - } - + add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables); return $environment_variables->all(); } diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php index be33a4834..b837414d6 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -168,20 +168,7 @@ class StartRedis $environment_variables->push("REDIS_PASSWORD={$this->database->redis_password}"); } - // TODO: move this in a shared function - if ($environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_APP_NAME={$this->database->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { - $environment_variables->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); - } - if ($environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); - } - if ($environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { - $environment_variables->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); - } - + add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables); return $environment_variables->all(); } diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 0cddf1d54..725b84c70 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -906,19 +906,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue } } - // TODO: move this in a shared function - if ($this->application->environment_variables_preview->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { - $envs->push("COOLIFY_APP_NAME={$this->application->name}"); - } - if ($this->application->environment_variables_preview->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { - $envs->push("COOLIFY_SERVER_IP={$this->application->destination->server->ip}"); - } - if ($this->application->environment_variables_preview->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { - $envs->push("COOLIFY_ENVIRONMENT_NAME={$this->application->environment->name}"); - } - if ($this->application->environment_variables_preview->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { - $envs->push("COOLIFY_PROJECT_NAME={$this->application->project()->name}"); - } + add_coolify_default_environment_variables($this->application, $environment, $this->application->environment_variables_preview); foreach ($sorted_environment_variables_preview as $env) { $real_value = $env->real_value; @@ -969,19 +957,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue } } - // TODO: move this in a shared function - if ($this->application->environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { - $envs->push("COOLIFY_APP_NAME={$this->application->name}"); - } - if ($this->application->environment_variables->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { - $envs->push("COOLIFY_SERVER_IP={$this->application->destination->server->ip}"); - } - if ($this->application->environment_variables->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { - $envs->push("COOLIFY_ENVIRONMENT_NAME={$this->application->environment->name}"); - } - if ($this->application->environment_variables->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { - $envs->push("COOLIFY_PROJECT_NAME={$this->application->project()->name}"); - } + add_coolify_default_environment_variables($this->application, $envs, $this->application->environment_variables); foreach ($sorted_environment_variables as $env) { $real_value = $env->real_value; diff --git a/app/Models/Application.php b/app/Models/Application.php index 604568df4..a24301abc 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -1464,19 +1464,7 @@ class Application extends BaseModel if ($this->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) { $environment->put('COOLIFY_CONTAINER_NAME', $containerName); } - // TODO: move this in a shared function - if ($this->environment_variables->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { - $environment->push("COOLIFY_APP_NAME={$this->database->name}"); - } - if ($this->environment->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { - $environment->push("COOLIFY_SERVER_IP={$this->database->destination->server->ip}"); - } - if ($this->environment->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { - $environment->push("COOLIFY_ENVIRONMENT_NAME={$this->database->environment->name}"); - } - if ($this->environment->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { - $environment->push("COOLIFY_PROJECT_NAME={$this->database->project()->name}"); - } + add_coolify_default_environment_variables($this->database, $environment, $this->environment_variables); // Remove SERVICE_FQDN and SERVICE_URL from environment $environment = $environment->filter(function ($value, $key) { diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index a48c9754e..99f2b9d8d 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -3346,3 +3346,32 @@ function generate_fluentd_configuration() : array { ] ]; } + +/** +* This method adds the default environment variables to the resource. +* - COOLIFY_APP_NAME +* - COOLIFY_PROJECT_NAME +* - COOLIFY_SERVER_IP +* - COOLIFY_ENVIRONMENT_NAME +* +* Theses variables are added in place to the $where_to_add array. +* +* @param StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|Application $resource +* @param Collection $where_to_add +* @param Collection|null $where_to_check +* +*/ +function add_coolify_default_environment_variables(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|Application $resource, Collection &$where_to_add, ?Collection $where_to_check = null) { + if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_APP_NAME')->isEmpty()) { + $where_to_add->push("COOLIFY_APP_NAME={$resource->name}"); + } + if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_SERVER_IP')->isEmpty()) { + $where_to_add->push("COOLIFY_SERVER_IP={$resource->destination->server->ip}"); + } + if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_ENVIRONMENT_NAME')->isEmpty()) { + $where_to_add->push("COOLIFY_ENVIRONMENT_NAME={$resource->environment->name}"); + } + if ($where_to_check != null && $where_to_check->where('key', 'COOLIFY_PROJECT_NAME')->isEmpty()) { + $where_to_add->push("COOLIFY_PROJECT_NAME={$resource->project()->name}"); + } +}