An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
wip
Andras Bacsai7d1a76570c2a
diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.phpindex 10aa885bf1..25a0614d91 100644--- a/app/Actions/Service/StartService.php+++ b/app/Actions/Service/StartService.php@@ -10,6 +10,7 @@ class StartServiceuse 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.phpindex 05be5fef4d..c370e62b1d 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 BaseModelreturn $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.phpnew file mode 100644index 0000000000..2ec71bfdbe--- /dev/null+++ b/database/migrations/2023_09_23_111816_add_destination_to_services_table.php@@ -0,0 +1,28 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('services', function (Blueprint $table) {+ $table->nullableMorphs('destination');+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('services', function (Blueprint $table) {+ $table->dropMorphs('destination');+ });+ }+};