Compare commits

...

11 Commits

Author SHA1 Message Date
Andras Bacsai
2116d79aad Merge pull request #1538 from coollabsio/next
v4.0.0-beta.160
2023-12-12 14:32:24 +01:00
Andras Bacsai
4bc63e283c fix: service env variable ovewritten if it has a default value 2023-12-12 14:28:11 +01:00
Andras Bacsai
d5804f99c2 Merge pull request #1537 from coollabsio/next
v4.0.0-beta.159
2023-12-12 13:25:40 +01:00
Andras Bacsai
dfc353ce54 fix: ignore if dynamic config could not be set 2023-12-12 13:20:26 +01:00
Andras Bacsai
8f65ddb754 Merge pull request #1536 from coollabsio/next
v4.0.0-beta.158
2023-12-12 12:41:46 +01:00
Andras Bacsai
29e750f0b2 hmm 2023-12-12 12:31:29 +01:00
Andras Bacsai
b24661b876 fix 2023-12-12 12:13:14 +01:00
Andras Bacsai
bbbd605f32 fix: comma in traefik custom labels 2023-12-12 12:10:46 +01:00
Andras Bacsai
ff13cb4e26 fix: init 2023-12-12 12:01:53 +01:00
Andras Bacsai
5cb572b6a5 fix: run init command after production seeder 2023-12-12 11:54:10 +01:00
Andras Bacsai
d8b97e06cf wip: fix for comma in labels 2023-12-11 23:34:18 +01:00
11 changed files with 114 additions and 102 deletions

View File

@@ -35,7 +35,12 @@ class Init extends Command
} }
$this->cleanup_in_progress_application_deployments(); $this->cleanup_in_progress_application_deployments();
$this->cleanup_stucked_helper_containers(); $this->cleanup_stucked_helper_containers();
setup_dynamic_configuration();
try {
setup_dynamic_configuration();
} catch (\Throwable $e) {
echo "Could not setup dynamic configuration: {$e->getMessage()}\n";
}
$settings = InstanceSettings::get(); $settings = InstanceSettings::get();
if (!is_null(env('AUTOUPDATE', null))) { if (!is_null(env('AUTOUPDATE', null))) {

View File

@@ -874,11 +874,11 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
$environment_variables = $this->generate_environment_variables($ports); $environment_variables = $this->generate_environment_variables($ports);
if (data_get($this->application, 'custom_labels')) { if (data_get($this->application, 'custom_labels')) {
$labels = collect(str($this->application->custom_labels)->explode(',')); $labels = collect(preg_split("/\r\n|\n|\r/", base64_decode($this->application->custom_labels)));
$labels = $labels->filter(function ($value, $key) { $labels = $labels->filter(function ($value, $key) {
return !Str::startsWith($value, 'coolify.'); return !Str::startsWith($value, 'coolify.');
}); });
$this->application->custom_labels = $labels->implode(','); $this->application->custom_labels = base64_encode($labels->implode("\n"));
$this->application->save(); $this->application->save();
} else { } else {
$labels = collect(generateLabelsApplication($this->application, $this->preview)); $labels = collect(generateLabelsApplication($this->application, $this->preview));

View File

@@ -95,7 +95,6 @@ class General extends Component
'application.dockerfile_target_build' => 'Dockerfile target build', 'application.dockerfile_target_build' => 'Dockerfile target build',
'application.settings.is_static' => 'Is static', 'application.settings.is_static' => 'Is static',
]; ];
public function mount() public function mount()
{ {
try { try {
@@ -110,11 +109,17 @@ class General extends Component
$this->application->isConfigurationChanged(true); $this->application->isConfigurationChanged(true);
} }
$this->isConfigurationChanged = $this->application->isConfigurationChanged(); $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 { } 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->initialDockerComposeLocation = $this->application->docker_compose_location;
$this->checkLabelUpdates(); $this->checkLabelUpdates();
} }
@@ -233,14 +238,12 @@ class General extends Component
if ($this->application->publish_directory && $this->application->publish_directory !== '/') { if ($this->application->publish_directory && $this->application->publish_directory !== '/') {
$this->application->publish_directory = rtrim($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(',');
if ($this->application->build_pack === 'dockercompose') { if ($this->application->build_pack === 'dockercompose') {
$this->application->docker_compose_domains = json_encode($this->parsedServiceDomains); $this->application->docker_compose_domains = json_encode($this->parsedServiceDomains);
$this->parsedServices = $this->application->parseCompose(); $this->parsedServices = $this->application->parseCompose();
} }
$this->application->custom_labels = base64_encode($this->customLabels);
$this->application->save(); $this->application->save();
$showToaster && $this->dispatch('success', 'Application settings updated!'); $showToaster && $this->dispatch('success', 'Application settings updated!');
} catch (\Throwable $e) { } catch (\Throwable $e) {

View File

@@ -161,110 +161,112 @@ function setup_dynamic_configuration()
{ {
$dynamic_config_path = get_proxy_path() . "/dynamic"; $dynamic_config_path = get_proxy_path() . "/dynamic";
$settings = InstanceSettings::get(); $settings = InstanceSettings::get();
$server = Server::findOrFail(0); $server = Server::find(0);
$file = "$dynamic_config_path/coolify.yaml"; if ($server) {
if (empty($settings->fqdn)) { $file = "$dynamic_config_path/coolify.yaml";
instant_remote_process([ if (empty($settings->fqdn)) {
"rm -f $file", instant_remote_process([
], $server); "rm -f $file",
} else { ], $server);
$url = Url::fromString($settings->fqdn); } else {
$host = $url->getHost(); $url = Url::fromString($settings->fqdn);
$schema = $url->getScheme(); $host = $url->getHost();
$traefik_dynamic_conf = [ $schema = $url->getScheme();
'http' => $traefik_dynamic_conf = [
[ 'http' =>
'routers' =>
[ [
'coolify-http' => 'routers' =>
[ [
'entryPoints' => [ 'coolify-http' =>
0 => 'http',
],
'service' => 'coolify',
'rule' => "Host(`{$host}`)",
],
'coolify-realtime-ws' =>
[
'entryPoints' => [
0 => 'http',
],
'service' => 'coolify-realtime',
'rule' => "Host(`{$host}`) && PathPrefix(`/app`)",
],
],
'services' =>
[
'coolify' =>
[
'loadBalancer' =>
[ [
'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' =>
'coolify-realtime' =>
[
'loadBalancer' =>
[ [
'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'] = [ if ($schema === 'https') {
'entryPoints' => [ $traefik_dynamic_conf['http']['routers']['coolify-http']['middlewares'] = [
0 => 'https', 0 => 'redirect-to-https@docker',
], ];
'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;
$base64 = base64_encode($yaml); $traefik_dynamic_conf['http']['routers']['coolify-https'] = [
instant_remote_process([ 'entryPoints' => [
"mkdir -p $dynamic_config_path", 0 => 'https',
"echo '$base64' | base64 -d > $file", ],
], $server); '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') { $base64 = base64_encode($yaml);
ray($yaml); instant_remote_process([
"mkdir -p $dynamic_config_path",
"echo '$base64' | base64 -d > $file",
], $server);
if (config('app.env') == 'local') {
ray($yaml);
}
} }
} }
} }

View File

@@ -969,10 +969,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
} }
} }
} else { } else {
$foundEnv = EnvironmentVariable::where([
'key' => $key,
'service_id' => $resource->id,
])->first();
if ($value->contains(':-')) { if ($value->contains(':-')) {
$key = $value->before(':'); $key = $value->before(':');
$defaultValue = $value->after(':-'); $defaultValue = $value->after(':-');
@@ -989,6 +985,10 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
$key = $value; $key = $value;
$defaultValue = null; $defaultValue = null;
} }
$foundEnv = EnvironmentVariable::where([
'key' => $key,
'service_id' => $resource->id,
])->first();
if ($foundEnv) { if ($foundEnv) {
$defaultValue = data_get($foundEnv, 'value'); $defaultValue = data_get($foundEnv, 'value');
} }

View File

@@ -7,7 +7,7 @@ return [
// The release version of your application // The release version of your application
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) // 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.160',
// When left empty or `null` the Laravel environment will be used // When left empty or `null` the Laravel environment will be used
'environment' => config('app.env'), 'environment' => config('app.env'),

View File

@@ -1,3 +1,3 @@
<?php <?php
return '4.0.0-beta.157'; return '4.0.0-beta.160';

View File

@@ -14,6 +14,7 @@ use App\Models\StandaloneDocker;
use App\Models\Team; use App\Models\Team;
use App\Models\User; use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Process; use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;

View File

@@ -1,2 +1,3 @@
#!/command/execlineb -P #!/command/execlineb -P
s6-setuidgid webuser
php /var/www/html/artisan app:init php /var/www/html/artisan app:init

View File

@@ -4,7 +4,7 @@
"version": "3.12.36" "version": "3.12.36"
}, },
"v4": { "v4": {
"version": "4.0.0-beta.157" "version": "4.0.0-beta.160"
} }
} }
} }