From d8b97e06cfdee64a9d4425431e2bb522ab9e3e54 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 11 Dec 2023 23:34:18 +0100 Subject: [PATCH 1/6] wip: fix for comma in labels --- app/Jobs/ApplicationDeploymentJob.php | 5 +++-- app/Livewire/Project/Application/General.php | 22 +++++++++++++------- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 08c388084..be38ee581 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -874,11 +874,12 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $environment_variables = $this->generate_environment_variables($ports); if (data_get($this->application, 'custom_labels')) { - $labels = collect(str($this->application->custom_labels)->explode(',')); + ray(base64_decode($this->application->custom_labels)); + $labels = collect(preg_split("/\r\n|\n|\r/", base64_decode($this->application->custom_labels))); $labels = $labels->filter(function ($value, $key) { return !Str::startsWith($value, 'coolify.'); }); - $this->application->custom_labels = $labels->implode(','); + $this->application->custom_labels = base64_encode($labels); $this->application->save(); } else { $labels = collect(generateLabelsApplication($this->application, $this->preview)); diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index bc6838d5d..3d68771f4 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -95,7 +95,6 @@ class General extends Component 'application.dockerfile_target_build' => 'Dockerfile target build', 'application.settings.is_static' => 'Is static', ]; - public function mount() { try { @@ -110,11 +109,17 @@ class General extends Component $this->application->isConfigurationChanged(true); } $this->isConfigurationChanged = $this->application->isConfigurationChanged(); - if (is_null(data_get($this->application, 'custom_labels'))) { - $this->customLabels = str(implode(",", generateLabelsApplication($this->application)))->replace(',', "\n"); + + if (base64_encode(base64_decode(data_get($this->application, 'custom_labels'), true)) === data_get($this->application, 'custom_labels')) { + ray('custom_labels is base64 encoded'); } else { - $this->customLabels = str($this->application->custom_labels)->replace(',', "\n"); + ray('custom_labels is not base64 encoded'); + $this->application->custom_labels = str($this->application->custom_labels)->replace(',', "\n"); + $this->application->custom_labels = base64_encode(data_get($this->application, 'custom_labels')); + $this->application->save(); } + + $this->customLabels = base64_decode(data_get($this->application, 'custom_labels')); $this->initialDockerComposeLocation = $this->application->docker_compose_location; $this->checkLabelUpdates(); } @@ -233,10 +238,11 @@ class General extends Component if ($this->application->publish_directory && $this->application->publish_directory !== '/') { $this->application->publish_directory = rtrim($this->application->publish_directory, '/'); } - if (gettype($this->customLabels) === 'string') { - $this->customLabels = str($this->customLabels)->replace(',', "\n"); - } - $this->application->custom_labels = $this->customLabels->explode("\n")->implode(','); + $this->application->custom_labels = base64_encode($this->customLabels); + // if (gettype($this->customLabels) === 'string') { + // $this->customLabels = str($this->customLabels)->replace(',', "\n"); + // } + // $this->application->custom_labels = $this->customLabels->explode("\n")->implode(','); if ($this->application->build_pack === 'dockercompose') { $this->application->docker_compose_domains = json_encode($this->parsedServiceDomains); $this->parsedServices = $this->application->parseCompose(); diff --git a/config/sentry.php b/config/sentry.php index 1cd69403b..43ac820bd 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.157', + 'release' => '4.0.0-beta.158', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 5c2f640e6..5eb844939 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Tue, 12 Dec 2023 11:54:10 +0100 Subject: [PATCH 2/6] fix: run init command after production seeder --- database/seeders/ProductionSeeder.php | 2 ++ .../prod-ssu/etc/s6-overlay/s6-rc.d/user/contents.d/init-script | 0 2 files changed, 2 insertions(+) delete mode 100644 docker/prod-ssu/etc/s6-overlay/s6-rc.d/user/contents.d/init-script diff --git a/database/seeders/ProductionSeeder.php b/database/seeders/ProductionSeeder.php index aaf07bb7a..8e53c6e7a 100644 --- a/database/seeders/ProductionSeeder.php +++ b/database/seeders/ProductionSeeder.php @@ -14,6 +14,7 @@ use App\Models\StandaloneDocker; use App\Models\Team; use App\Models\User; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Process; use Illuminate\Support\Facades\Storage; @@ -144,5 +145,6 @@ class ProductionSeeder extends Seeder } catch (\Throwable $e) { echo "Error: {$e->getMessage()}\n"; } + Artisan::call('app:init'); } } diff --git a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/user/contents.d/init-script b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/user/contents.d/init-script deleted file mode 100644 index e69de29bb..000000000 From ff13cb4e2676701f4f0f5387504bd3e13a95c17a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Dec 2023 12:01:53 +0100 Subject: [PATCH 3/6] fix: init --- database/seeders/ProductionSeeder.php | 1 - .../s6-overlay/s6-rc.d/init-seeder/dependencies.d/db-migration | 0 .../prod-ssu/etc/s6-overlay/s6-rc.d/user/contents.d/init-script | 0 3 files changed, 1 deletion(-) create mode 100644 docker/prod-ssu/etc/s6-overlay/s6-rc.d/init-seeder/dependencies.d/db-migration create mode 100644 docker/prod-ssu/etc/s6-overlay/s6-rc.d/user/contents.d/init-script diff --git a/database/seeders/ProductionSeeder.php b/database/seeders/ProductionSeeder.php index 8e53c6e7a..eb5880c32 100644 --- a/database/seeders/ProductionSeeder.php +++ b/database/seeders/ProductionSeeder.php @@ -145,6 +145,5 @@ class ProductionSeeder extends Seeder } catch (\Throwable $e) { echo "Error: {$e->getMessage()}\n"; } - Artisan::call('app:init'); } } diff --git a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/init-seeder/dependencies.d/db-migration b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/init-seeder/dependencies.d/db-migration new file mode 100644 index 000000000..e69de29bb diff --git a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/user/contents.d/init-script b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/user/contents.d/init-script new file mode 100644 index 000000000..e69de29bb From bbbd605f32b829b13b8b0ce50e5f1f721a3023e3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Dec 2023 12:10:46 +0100 Subject: [PATCH 4/6] fix: comma in traefik custom labels --- app/Jobs/ApplicationDeploymentJob.php | 3 +-- app/Livewire/Project/Application/General.php | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index be38ee581..cafddfa82 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -874,12 +874,11 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $environment_variables = $this->generate_environment_variables($ports); if (data_get($this->application, 'custom_labels')) { - ray(base64_decode($this->application->custom_labels)); $labels = collect(preg_split("/\r\n|\n|\r/", base64_decode($this->application->custom_labels))); $labels = $labels->filter(function ($value, $key) { return !Str::startsWith($value, 'coolify.'); }); - $this->application->custom_labels = base64_encode($labels); + $this->application->custom_labels = base64_encode($labels->implode("\n")); $this->application->save(); } else { $labels = collect(generateLabelsApplication($this->application, $this->preview)); diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index 3d68771f4..7587031fd 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -238,15 +238,12 @@ class General extends Component if ($this->application->publish_directory && $this->application->publish_directory !== '/') { $this->application->publish_directory = rtrim($this->application->publish_directory, '/'); } - $this->application->custom_labels = base64_encode($this->customLabels); - // if (gettype($this->customLabels) === 'string') { - // $this->customLabels = str($this->customLabels)->replace(',', "\n"); - // } - // $this->application->custom_labels = $this->customLabels->explode("\n")->implode(','); if ($this->application->build_pack === 'dockercompose') { $this->application->docker_compose_domains = json_encode($this->parsedServiceDomains); $this->parsedServices = $this->application->parseCompose(); } + + $this->application->custom_labels = base64_encode($this->customLabels); $this->application->save(); $showToaster && $this->dispatch('success', 'Application settings updated!'); } catch (\Throwable $e) { From b24661b876ac472a10c2ea2e4de2571facde2ce6 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Dec 2023 12:13:14 +0100 Subject: [PATCH 5/6] fix --- bootstrap/helpers/proxy.php | 170 ++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 84 deletions(-) diff --git a/bootstrap/helpers/proxy.php b/bootstrap/helpers/proxy.php index 3fa657216..b738b5a9d 100644 --- a/bootstrap/helpers/proxy.php +++ b/bootstrap/helpers/proxy.php @@ -161,110 +161,112 @@ function setup_dynamic_configuration() { $dynamic_config_path = get_proxy_path() . "/dynamic"; $settings = InstanceSettings::get(); - $server = Server::findOrFail(0); - $file = "$dynamic_config_path/coolify.yaml"; - if (empty($settings->fqdn)) { - instant_remote_process([ - "rm -f $file", - ], $server); - } else { - $url = Url::fromString($settings->fqdn); - $host = $url->getHost(); - $schema = $url->getScheme(); - $traefik_dynamic_conf = [ - 'http' => - [ - 'routers' => + $server = Server::find(0); + if ($server) { + $file = "$dynamic_config_path/coolify.yaml"; + if (empty($settings->fqdn)) { + instant_remote_process([ + "rm -f $file", + ], $server); + } else { + $url = Url::fromString($settings->fqdn); + $host = $url->getHost(); + $schema = $url->getScheme(); + $traefik_dynamic_conf = [ + 'http' => [ - 'coolify-http' => + 'routers' => [ - 'entryPoints' => [ - 0 => 'http', - ], - 'service' => 'coolify', - 'rule' => "Host(`{$host}`)", - ], - 'coolify-realtime-ws' => - [ - 'entryPoints' => [ - 0 => 'http', - ], - 'service' => 'coolify-realtime', - 'rule' => "Host(`{$host}`) && PathPrefix(`/app`)", - ], - ], - 'services' => - [ - 'coolify' => - [ - 'loadBalancer' => + 'coolify-http' => [ - 'servers' => + 'entryPoints' => [ + 0 => 'http', + ], + 'service' => 'coolify', + 'rule' => "Host(`{$host}`)", + ], + 'coolify-realtime-ws' => + [ + 'entryPoints' => [ + 0 => 'http', + ], + 'service' => 'coolify-realtime', + 'rule' => "Host(`{$host}`) && PathPrefix(`/app`)", + ], + ], + 'services' => + [ + 'coolify' => + [ + 'loadBalancer' => [ - 0 => + 'servers' => [ - 'url' => 'http://coolify:80', + 0 => + [ + 'url' => 'http://coolify:80', + ], ], ], ], - ], - 'coolify-realtime' => - [ - 'loadBalancer' => + 'coolify-realtime' => [ - 'servers' => + 'loadBalancer' => [ - 0 => + 'servers' => [ - 'url' => 'http://coolify-realtime:6001', + 0 => + [ + 'url' => 'http://coolify-realtime:6001', + ], ], ], ], ], ], - ], - ]; - - if ($schema === 'https') { - $traefik_dynamic_conf['http']['routers']['coolify-http']['middlewares'] = [ - 0 => 'redirect-to-https@docker', ]; - $traefik_dynamic_conf['http']['routers']['coolify-https'] = [ - 'entryPoints' => [ - 0 => 'https', - ], - 'service' => 'coolify', - 'rule' => "Host(`{$host}`)", - 'tls' => [ - 'certresolver' => 'letsencrypt', - ], - ]; - $traefik_dynamic_conf['http']['routers']['coolify-realtime-wss'] = [ - 'entryPoints' => [ - 0 => 'https', - ], - 'service' => 'coolify-realtime', - 'rule' => "Host(`{$host}`) && PathPrefix(`/app`)", - 'tls' => [ - 'certresolver' => 'letsencrypt', - ], - ]; - } - $yaml = Yaml::dump($traefik_dynamic_conf, 12, 2); - $yaml = - "# This file is automatically generated by Coolify.\n" . - "# Do not edit it manually (only if you know what are you doing).\n\n" . - $yaml; + if ($schema === 'https') { + $traefik_dynamic_conf['http']['routers']['coolify-http']['middlewares'] = [ + 0 => 'redirect-to-https@docker', + ]; - $base64 = base64_encode($yaml); - instant_remote_process([ - "mkdir -p $dynamic_config_path", - "echo '$base64' | base64 -d > $file", - ], $server); + $traefik_dynamic_conf['http']['routers']['coolify-https'] = [ + 'entryPoints' => [ + 0 => 'https', + ], + 'service' => 'coolify', + 'rule' => "Host(`{$host}`)", + 'tls' => [ + 'certresolver' => 'letsencrypt', + ], + ]; + $traefik_dynamic_conf['http']['routers']['coolify-realtime-wss'] = [ + 'entryPoints' => [ + 0 => 'https', + ], + 'service' => 'coolify-realtime', + 'rule' => "Host(`{$host}`) && PathPrefix(`/app`)", + 'tls' => [ + 'certresolver' => 'letsencrypt', + ], + ]; + } + $yaml = Yaml::dump($traefik_dynamic_conf, 12, 2); + $yaml = + "# This file is automatically generated by Coolify.\n" . + "# Do not edit it manually (only if you know what are you doing).\n\n" . + $yaml; - if (config('app.env') == 'local') { - ray($yaml); + $base64 = base64_encode($yaml); + instant_remote_process([ + "mkdir -p $dynamic_config_path", + "echo '$base64' | base64 -d > $file", + ], $server); + + if (config('app.env') == 'local') { + ray($yaml); + } } } } From 29e750f0b2d7a8dbd9f78b7c754b5b5d63eb524c Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Dec 2023 12:31:29 +0100 Subject: [PATCH 6/6] hmm --- docker/prod-ssu/etc/s6-overlay/s6-rc.d/init-script/up | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/init-script/up b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/init-script/up index 09595f708..3b252b782 100644 --- a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/init-script/up +++ b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/init-script/up @@ -1,2 +1,3 @@ #!/command/execlineb -P +s6-setuidgid webuser php /var/www/html/artisan app:init