From e18766ec21747f149a10dba2c0571c224b7b4852 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 2 Oct 2023 15:09:57 +0200 Subject: [PATCH 1/6] fix: if waitlist is disabled, redirect to register --- app/Http/Livewire/Waitlist/Index.php | 3 +++ config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Http/Livewire/Waitlist/Index.php b/app/Http/Livewire/Waitlist/Index.php index 06d92b6cb..c1e6ad939 100644 --- a/app/Http/Livewire/Waitlist/Index.php +++ b/app/Http/Livewire/Waitlist/Index.php @@ -23,6 +23,9 @@ class Index extends Component } public function mount() { + if (config('coolify.waitlist') == false) { + return redirect()->route('register'); + } $this->waitingInLine = Waitlist::whereVerified(true)->count(); $this->users = User::count(); if (isDev()) { diff --git a/config/sentry.php b/config/sentry.php index 47aa02db2..0cc516460 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.57', + 'release' => '4.0.0-beta.58', // 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 8ff3d53a5..87313c7d1 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Mon, 2 Oct 2023 15:51:06 +0200 Subject: [PATCH 2/6] wip --- app/Actions/Service/StartService.php | 2 ++ app/Models/Service.php | 31 ++++++++++++++----- ...1816_add_destination_to_services_table.php | 28 +++++++++++++++++ 3 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 database/migrations/2023_09_23_111816_add_destination_to_services_table.php diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.php index 10aa885bf..25a0614d9 100644 --- a/app/Actions/Service/StartService.php +++ b/app/Actions/Service/StartService.php @@ -10,6 +10,7 @@ class StartService use AsAction; public function handle(Service $service) { + $network = $service->destination->network; $service->saveComposeConfigs(); $commands[] = "cd " . $service->workdir(); $commands[] = "echo '####### Saved configuration files to {$service->workdir()}.'"; @@ -21,6 +22,7 @@ class StartService $commands[] = "echo '####### Starting containers.'"; $commands[] = "docker compose up -d --remove-orphans --force-recreate"; $commands[] = "docker network connect $service->uuid coolify-proxy 2>/dev/null || true"; + $commands[] = "docker network connect $network --alias $service->name-$service->uuid $service->name-$service->uuid 2>/dev/null || true"; $activity = remote_process($commands, $service->server); return $activity; } diff --git a/app/Models/Service.php b/app/Models/Service.php index 05be5fef4..c370e62b1 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -63,6 +63,10 @@ class Service extends BaseModel { return $this->hasMany(ServiceDatabase::class); } + public function destination() + { + return $this->morphTo(); + } public function environment() { return $this->belongsTo(Environment::class); @@ -124,9 +128,16 @@ class Service extends BaseModel $topLevelNetworks = collect(data_get($yaml, 'networks', [])); $dockerComposeVersion = data_get($yaml, 'version') ?? '3.8'; $services = data_get($yaml, 'services'); - $definedNetwork = $this->uuid; $generatedServiceFQDNS = collect([]); + if (is_null($this->destination)) { + $destination = $this->server->destinations()->first(); + if ($destination) { + $this->destination()->associate($destination); + $this->save(); + } + } + $definedNetwork = collect([$this->uuid]); $services = collect($services)->map(function ($service, $serviceName) use ($topLevelVolumes, $topLevelNetworks, $definedNetwork, $isNew, $generatedServiceFQDNS) { $serviceVolumes = collect(data_get($service, 'volumes', [])); @@ -237,13 +248,19 @@ class Service extends BaseModel return $value == $definedNetwork; }); if (!$definedNetworkExists) { - $topLevelNetworks->put($definedNetwork, [ - 'name' => $definedNetwork, - 'external' => true - ]); + foreach ($definedNetwork as $network) { + $topLevelNetworks->put($network, [ + 'name' => $network, + 'external' => true + ]); + } } $networks = $serviceNetworks->toArray(); - $networks = array_merge($networks, [$definedNetwork]); + foreach ($definedNetwork as $key => $network) { + $networks = array_merge($networks, [ + $network => null + ]); + } data_set($service, 'networks', $networks); // Collect/create/update volumes @@ -308,7 +325,7 @@ class Service extends BaseModel $target = Str::of($volume)->after(':')->beforeLast(':'); $source = $name; $volume = "$source:$target"; - } else if(is_array($volume)) { + } else if (is_array($volume)) { data_set($volume, 'source', $name); } $topLevelVolumes->put($name, null); diff --git a/database/migrations/2023_09_23_111816_add_destination_to_services_table.php b/database/migrations/2023_09_23_111816_add_destination_to_services_table.php new file mode 100644 index 000000000..2ec71bfdb --- /dev/null +++ b/database/migrations/2023_09_23_111816_add_destination_to_services_table.php @@ -0,0 +1,28 @@ +nullableMorphs('destination'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('services', function (Blueprint $table) { + $table->dropMorphs('destination'); + }); + } +}; From d446cd41039730868fd660ecddfe82059aae926a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 2 Oct 2023 16:38:05 +0200 Subject: [PATCH 3/6] feat: reset root password --- app/Console/Commands/ResetRootPassword.php | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/Console/Commands/ResetRootPassword.php diff --git a/app/Console/Commands/ResetRootPassword.php b/app/Console/Commands/ResetRootPassword.php new file mode 100644 index 000000000..61e0eb309 --- /dev/null +++ b/app/Console/Commands/ResetRootPassword.php @@ -0,0 +1,49 @@ +info('You are about to reset the root password.'); + $password = password('Give me a new password for root user: '); + $passwordAgain = password('Again'); + if ($password != $passwordAgain) { + $this->error('Passwords do not match.'); + return; + } + $this->info('Updating root password...'); + try { + User::find(0)->update(['password' => Hash::make($password)]); + $this->info('Root password updated successfully.'); + } catch (\Exception $e) { + $this->error('Failed to update root password.'); + return; + } + } +} From 540717e80987b7c86a85abc620ac60a3a3cf8fe0 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 2 Oct 2023 16:57:55 +0200 Subject: [PATCH 4/6] feat: attach Coolify defined networks to services --- app/Actions/Service/StartService.php | 7 ++++++- app/Http/Livewire/Project/New/DockerCompose.php | 2 -- app/Models/Service.php | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.php index 25a0614d9..965162037 100644 --- a/app/Actions/Service/StartService.php +++ b/app/Actions/Service/StartService.php @@ -4,6 +4,7 @@ namespace App\Actions\Service; use Lorisleiva\Actions\Concerns\AsAction; use App\Models\Service; +use Symfony\Component\Yaml\Yaml; class StartService { @@ -22,7 +23,11 @@ class StartService $commands[] = "echo '####### Starting containers.'"; $commands[] = "docker compose up -d --remove-orphans --force-recreate"; $commands[] = "docker network connect $service->uuid coolify-proxy 2>/dev/null || true"; - $commands[] = "docker network connect $network --alias $service->name-$service->uuid $service->name-$service->uuid 2>/dev/null || true"; + $compose = data_get($service,'docker_compose',[]); + $serviceNames = data_get(Yaml::parse($compose),'services',[]); + foreach($serviceNames as $serviceName => $serviceConfig){ + $commands[] = "docker network connect --alias {$serviceName}-{$service->uuid} $network {$serviceName}-{$service->uuid} 2>/dev/null || true"; + } $activity = remote_process($commands, $service->server); return $activity; } diff --git a/app/Http/Livewire/Project/New/DockerCompose.php b/app/Http/Livewire/Project/New/DockerCompose.php index ae3a1c08c..81c487ccf 100644 --- a/app/Http/Livewire/Project/New/DockerCompose.php +++ b/app/Http/Livewire/Project/New/DockerCompose.php @@ -32,8 +32,6 @@ class DockerCompose extends Component - type: volume source: mydata target: /data - volume: - nocopy: true - type: bind source: ./var/lib/ghost/data target: /data diff --git a/app/Models/Service.php b/app/Models/Service.php index c370e62b1..a430dc2dd 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -258,7 +258,7 @@ class Service extends BaseModel $networks = $serviceNetworks->toArray(); foreach ($definedNetwork as $key => $network) { $networks = array_merge($networks, [ - $network => null + $network ]); } data_set($service, 'networks', $networks); From 620f26a6f1a74de09b387ff30a2b1ce18ce1b80e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 2 Oct 2023 17:12:50 +0200 Subject: [PATCH 5/6] fix: add destination to new services --- app/Http/Controllers/ProjectController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 0e4c0e2c7..0b89ac0dc 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -6,7 +6,7 @@ use App\Models\EnvironmentVariable; use App\Models\Project; use App\Models\Server; use App\Models\Service; -use Illuminate\Support\Facades\Cache; +use App\Models\StandaloneDocker; use Illuminate\Support\Str; class ProjectController extends Controller @@ -75,11 +75,14 @@ class ProjectController extends Controller $oneClickDotEnvs = Str::of(base64_decode($oneClickDotEnvs))->split('/\r\n|\r|\n/'); } if ($oneClickService) { + $destination = StandaloneDocker::whereUuid($destination_uuid)->first(); $service = Service::create([ 'name' => "$oneClickServiceName-" . Str::random(10), 'docker_compose_raw' => base64_decode($oneClickService), 'environment_id' => $environment->id, 'server_id' => (int) $server_id, + 'destination_id' => $destination->id, + 'destination_type' => $destination->getMorphClass(), ]); $service->name = "$oneClickServiceName-" . $service->uuid; $service->save(); From dd5723d5965fdf54fba7884a6ca54d4eabc59c7b Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 2 Oct 2023 17:17:49 +0200 Subject: [PATCH 6/6] service: uptime kume hc updated --- templates/service-templates.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/service-templates.json b/templates/service-templates.json index 2b06a382a..22cf7dbfb 100644 --- a/templates/service-templates.json +++ b/templates/service-templates.json @@ -7,7 +7,7 @@ "uptime-kuma": { "documentation": "https://github.com/louislam/uptime-kuma", "slogan": "A free and fancy self-hosted monitoring tool.", - "compose": "c2VydmljZXM6CiAgdXB0aW1lLWt1bWE6CiAgICBpbWFnZTogbG91aXNsYW0vdXB0aW1lLWt1bWE6MQogICAgZW52aXJvbm1lbnQ6CiAgICAgIC0gU0VSVklDRV9GUUROCiAgICB2b2x1bWVzOgogICAgICAtIHVwdGltZS1rdW1hOi9hcHAvZGF0YQ==" + "compose": "c2VydmljZXM6CiAgdXB0aW1lLWt1bWE6CiAgICBpbWFnZTogbG91aXNsYW0vdXB0aW1lLWt1bWE6MQogICAgZW52aXJvbm1lbnQ6CiAgICAgIC0gU0VSVklDRV9GUUROCiAgICB2b2x1bWVzOgogICAgICAtIHVwdGltZS1rdW1hOi9hcHAvZGF0YQogICAgaGVhbHRoY2hlY2s6CiAgICAgIHRlc3Q6IFsiQ01ELVNIRUxMIiwgImV4dHJhL2hlYWx0aGNoZWNrIl0KICAgICAgaW50ZXJ2YWw6IDJzCiAgICAgIHRpbWVvdXQ6IDEwcwogICAgICByZXRyaWVzOiAxNQ==" }, "appsmith": { "documentation": "https://docs.appsmith.com/",