diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.php index 10aa885bf..965162037 100644 --- a/app/Actions/Service/StartService.php +++ b/app/Actions/Service/StartService.php @@ -4,12 +4,14 @@ namespace App\Actions\Service; use Lorisleiva\Actions\Concerns\AsAction; use App\Models\Service; +use Symfony\Component\Yaml\Yaml; 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 +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"; + $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/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; + } + } +} 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(); 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/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/app/Models/Service.php b/app/Models/Service.php index 05be5fef4..a430dc2dd 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 + ]); + } 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/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 @@ nullableMorphs('destination'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('services', function (Blueprint $table) { + $table->dropMorphs('destination'); + }); + } +}; 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/", diff --git a/versions.json b/versions.json index 7278e5b68..e2ac07709 100644 --- a/versions.json +++ b/versions.json @@ -4,7 +4,7 @@ "version": "3.12.36" }, "v4": { - "version": "4.0.0-beta.57" + "version": "4.0.0-beta.58" } } }