From 23968e7886d7f790e7d01d162595a2b5c9c99c52 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sun, 1 Oct 2023 13:28:33 +0200 Subject: [PATCH 1/5] version++ --- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/sentry.php b/config/sentry.php index 788868730..58b909f0a 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.54', + 'release' => '4.0.0-beta.55', // 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 209bb48f3..c70227f5a 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Sun, 1 Oct 2023 13:59:22 +0200 Subject: [PATCH 2/5] fix: services should have destination as well --- app/Actions/Service/StartService.php | 12 +++++-- app/Actions/Service/StopService.php | 6 ++-- app/Http/Controllers/ProjectController.php | 8 +++-- app/Models/Service.php | 33 ++++++++++++++++++- ...1815_add_destination_to_services_table.php | 28 ++++++++++++++++ 5 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 database/migrations/2023_09_23_111815_add_destination_to_services_table.php diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.php index 10aa885bf..a099d1445 100644 --- a/app/Actions/Service/StartService.php +++ b/app/Actions/Service/StartService.php @@ -13,14 +13,20 @@ class StartService $service->saveComposeConfigs(); $commands[] = "cd " . $service->workdir(); $commands[] = "echo '####### Saved configuration files to {$service->workdir()}.'"; - $commands[] = "echo '####### Creating Docker network.'"; - $commands[] = "docker network create --attachable {$service->uuid} >/dev/null 2>/dev/null || true"; + if (is_null($service->destination)) { + $dockerNetwork = $service->uuid; + $commands[] = "echo '####### Creating Docker network.'"; + $commands[] = "docker network create --attachable {$dockerNetwork} >/dev/null 2>/dev/null || true"; + } $commands[] = "echo '####### Starting service {$service->name} on {$service->server->name}.'"; $commands[] = "echo '####### Pulling images.'"; $commands[] = "docker compose pull"; $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"; + if (is_null($service->destination)) { + $commands[] = "echo '####### Connecting to proxy network.'"; + $commands[] = "docker network connect coolify-proxy {$dockerNetwork} 2>/dev/null || true"; + } $activity = remote_process($commands, $service->server); return $activity; } diff --git a/app/Actions/Service/StopService.php b/app/Actions/Service/StopService.php index 82128f47d..d6ec09de3 100644 --- a/app/Actions/Service/StopService.php +++ b/app/Actions/Service/StopService.php @@ -20,7 +20,9 @@ class StopService instant_remote_process(["docker rm -f {$db->name}-{$service->uuid}"], $service->server); $db->update(['status' => 'exited']); } - instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy 2>/dev/null"], $service->server, false); - instant_remote_process(["docker network rm {$service->uuid} 2>/dev/null"], $service->server, false); + if (is_null($service->destination)) { + instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy 2>/dev/null"], $service->server, false); + instant_remote_process(["docker network rm {$service->uuid} 2>/dev/null"], $service->server, false); + } } } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 0e4c0e2c7..77c979059 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 @@ -66,20 +66,22 @@ class ProjectController extends Controller 'database_uuid' => $standalone_postgresql->uuid, ]); } - if ($type->startsWith('one-click-service-') && !is_null( (int)$server_id)) { + if ($type->startsWith('one-click-service-') && !is_null((int)$server_id)) { $oneClickServiceName = $type->after('one-click-service-')->value(); $oneClickService = data_get($services, "$oneClickServiceName.compose"); - ray($oneClickServiceName); $oneClickDotEnvs = data_get($services, "$oneClickServiceName.envs", null); if ($oneClickDotEnvs) { $oneClickDotEnvs = Str::of(base64_decode($oneClickDotEnvs))->split('/\r\n|\r|\n/'); } if ($oneClickService) { + $destination = StandaloneDocker::where('uuid', $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' => (int) $destination->id, + 'destination_type' => $destination->getMorphClass(), ]); $service->name = "$oneClickServiceName-" . $service->uuid; $service->save(); diff --git a/app/Models/Service.php b/app/Models/Service.php index 883a2a784..2fbd2ae16 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -59,6 +59,10 @@ class Service extends BaseModel { return $this->hasMany(ServiceApplication::class); } + public function destination() + { + return $this->morphTo(); + } public function databases() { return $this->hasMany(ServiceDatabase::class); @@ -120,15 +124,23 @@ class Service extends BaseModel throw new \Exception($e->getMessage()); } + if ($this->server->destinations()->count() === 1) { + $this->destination()->associate($this->server->destinations()->first()); + } $topLevelVolumes = collect(data_get($yaml, 'volumes', [])); $topLevelNetworks = collect(data_get($yaml, 'networks', [])); $dockerComposeVersion = data_get($yaml, 'version') ?? '3.8'; $services = data_get($yaml, 'services'); - $definedNetwork = $this->uuid; + if ($this->destination) { + $definedNetwork = $this->destination->network; + } else { + $definedNetwork = $this->uuid; + } $generatedServiceFQDNS = collect([]); $services = collect($services)->map(function ($service, $serviceName) use ($topLevelVolumes, $topLevelNetworks, $definedNetwork, $isNew, $generatedServiceFQDNS) { + $serviceName = Str::of($serviceName)->before("-$this->uuid")->value; $serviceVolumes = collect(data_get($service, 'volumes', [])); $servicePorts = collect(data_get($service, 'ports', [])); $serviceNetworks = collect(data_get($service, 'networks', [])); @@ -493,6 +505,25 @@ class Service extends BaseModel data_set($service, 'environment', $withoutServiceEnvs->toArray()); return $service; }); + $services = $services->mapWithKeys(function ($service, $serviceName) { + if (!Str::of($serviceName)->contains($this->uuid)) { + $newServiceName = $serviceName . '-' . $this->uuid; + return [$newServiceName => $service]; + } + return [$serviceName => $service]; + }); + + $yaml = collect($yaml); + $yamlServices = collect(data_get($yaml, 'services', [])); + $yamlServices = $yamlServices->mapWithKeys(function ($service, $serviceName) { + if (!Str::of($serviceName)->contains($this->uuid)) { + $newServiceName = $serviceName . '-' . $this->uuid; + return [$newServiceName => $service]; + } + return [$serviceName => $service]; + }); + $yaml->put('services', $yamlServices->toArray()); + $yaml = $yaml->toArray(); $finalServices = [ 'version' => $dockerComposeVersion, 'services' => $services->toArray(), diff --git a/database/migrations/2023_09_23_111815_add_destination_to_services_table.php b/database/migrations/2023_09_23_111815_add_destination_to_services_table.php new file mode 100644 index 000000000..2ec71bfdb --- /dev/null +++ b/database/migrations/2023_09_23_111815_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 b3c8c881b7c6fa0ea34fe03f5538338ab6f09ce6 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sun, 1 Oct 2023 15:31:25 +0200 Subject: [PATCH 3/5] Revert "fix: services should have destination as well" This reverts commit 9ab5a1f7bdfdccfca3c8ca2a17b9f4c7ed04c0a3. --- app/Actions/Service/StartService.php | 12 ++----- app/Actions/Service/StopService.php | 6 ++-- app/Http/Controllers/ProjectController.php | 8 ++--- app/Models/Service.php | 33 +------------------ ...1815_add_destination_to_services_table.php | 28 ---------------- 5 files changed, 9 insertions(+), 78 deletions(-) delete mode 100644 database/migrations/2023_09_23_111815_add_destination_to_services_table.php diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.php index a099d1445..10aa885bf 100644 --- a/app/Actions/Service/StartService.php +++ b/app/Actions/Service/StartService.php @@ -13,20 +13,14 @@ class StartService $service->saveComposeConfigs(); $commands[] = "cd " . $service->workdir(); $commands[] = "echo '####### Saved configuration files to {$service->workdir()}.'"; - if (is_null($service->destination)) { - $dockerNetwork = $service->uuid; - $commands[] = "echo '####### Creating Docker network.'"; - $commands[] = "docker network create --attachable {$dockerNetwork} >/dev/null 2>/dev/null || true"; - } + $commands[] = "echo '####### Creating Docker network.'"; + $commands[] = "docker network create --attachable {$service->uuid} >/dev/null 2>/dev/null || true"; $commands[] = "echo '####### Starting service {$service->name} on {$service->server->name}.'"; $commands[] = "echo '####### Pulling images.'"; $commands[] = "docker compose pull"; $commands[] = "echo '####### Starting containers.'"; $commands[] = "docker compose up -d --remove-orphans --force-recreate"; - if (is_null($service->destination)) { - $commands[] = "echo '####### Connecting to proxy network.'"; - $commands[] = "docker network connect coolify-proxy {$dockerNetwork} 2>/dev/null || true"; - } + $commands[] = "docker network connect $service->uuid coolify-proxy 2>/dev/null || true"; $activity = remote_process($commands, $service->server); return $activity; } diff --git a/app/Actions/Service/StopService.php b/app/Actions/Service/StopService.php index d6ec09de3..82128f47d 100644 --- a/app/Actions/Service/StopService.php +++ b/app/Actions/Service/StopService.php @@ -20,9 +20,7 @@ class StopService instant_remote_process(["docker rm -f {$db->name}-{$service->uuid}"], $service->server); $db->update(['status' => 'exited']); } - if (is_null($service->destination)) { - instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy 2>/dev/null"], $service->server, false); - instant_remote_process(["docker network rm {$service->uuid} 2>/dev/null"], $service->server, false); - } + instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy 2>/dev/null"], $service->server, false); + instant_remote_process(["docker network rm {$service->uuid} 2>/dev/null"], $service->server, false); } } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 77c979059..0e4c0e2c7 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 App\Models\StandaloneDocker; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; class ProjectController extends Controller @@ -66,22 +66,20 @@ class ProjectController extends Controller 'database_uuid' => $standalone_postgresql->uuid, ]); } - if ($type->startsWith('one-click-service-') && !is_null((int)$server_id)) { + if ($type->startsWith('one-click-service-') && !is_null( (int)$server_id)) { $oneClickServiceName = $type->after('one-click-service-')->value(); $oneClickService = data_get($services, "$oneClickServiceName.compose"); + ray($oneClickServiceName); $oneClickDotEnvs = data_get($services, "$oneClickServiceName.envs", null); if ($oneClickDotEnvs) { $oneClickDotEnvs = Str::of(base64_decode($oneClickDotEnvs))->split('/\r\n|\r|\n/'); } if ($oneClickService) { - $destination = StandaloneDocker::where('uuid', $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' => (int) $destination->id, - 'destination_type' => $destination->getMorphClass(), ]); $service->name = "$oneClickServiceName-" . $service->uuid; $service->save(); diff --git a/app/Models/Service.php b/app/Models/Service.php index 2fbd2ae16..883a2a784 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -59,10 +59,6 @@ class Service extends BaseModel { return $this->hasMany(ServiceApplication::class); } - public function destination() - { - return $this->morphTo(); - } public function databases() { return $this->hasMany(ServiceDatabase::class); @@ -124,23 +120,15 @@ class Service extends BaseModel throw new \Exception($e->getMessage()); } - if ($this->server->destinations()->count() === 1) { - $this->destination()->associate($this->server->destinations()->first()); - } $topLevelVolumes = collect(data_get($yaml, 'volumes', [])); $topLevelNetworks = collect(data_get($yaml, 'networks', [])); $dockerComposeVersion = data_get($yaml, 'version') ?? '3.8'; $services = data_get($yaml, 'services'); - if ($this->destination) { - $definedNetwork = $this->destination->network; - } else { - $definedNetwork = $this->uuid; - } + $definedNetwork = $this->uuid; $generatedServiceFQDNS = collect([]); $services = collect($services)->map(function ($service, $serviceName) use ($topLevelVolumes, $topLevelNetworks, $definedNetwork, $isNew, $generatedServiceFQDNS) { - $serviceName = Str::of($serviceName)->before("-$this->uuid")->value; $serviceVolumes = collect(data_get($service, 'volumes', [])); $servicePorts = collect(data_get($service, 'ports', [])); $serviceNetworks = collect(data_get($service, 'networks', [])); @@ -505,25 +493,6 @@ class Service extends BaseModel data_set($service, 'environment', $withoutServiceEnvs->toArray()); return $service; }); - $services = $services->mapWithKeys(function ($service, $serviceName) { - if (!Str::of($serviceName)->contains($this->uuid)) { - $newServiceName = $serviceName . '-' . $this->uuid; - return [$newServiceName => $service]; - } - return [$serviceName => $service]; - }); - - $yaml = collect($yaml); - $yamlServices = collect(data_get($yaml, 'services', [])); - $yamlServices = $yamlServices->mapWithKeys(function ($service, $serviceName) { - if (!Str::of($serviceName)->contains($this->uuid)) { - $newServiceName = $serviceName . '-' . $this->uuid; - return [$newServiceName => $service]; - } - return [$serviceName => $service]; - }); - $yaml->put('services', $yamlServices->toArray()); - $yaml = $yaml->toArray(); $finalServices = [ 'version' => $dockerComposeVersion, 'services' => $services->toArray(), diff --git a/database/migrations/2023_09_23_111815_add_destination_to_services_table.php b/database/migrations/2023_09_23_111815_add_destination_to_services_table.php deleted file mode 100644 index 2ec71bfdb..000000000 --- a/database/migrations/2023_09_23_111815_add_destination_to_services_table.php +++ /dev/null @@ -1,28 +0,0 @@ -nullableMorphs('destination'); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('services', function (Blueprint $table) { - $table->dropMorphs('destination'); - }); - } -}; From aefdc76805672e2e3455496f23b9e767bafe6af6 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sun, 1 Oct 2023 17:27:12 +0200 Subject: [PATCH 4/5] fix: dockerfile expose is not overwritten --- app/Http/Livewire/Project/New/SimpleDockerfile.php | 3 +++ bootstrap/helpers/docker.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Livewire/Project/New/SimpleDockerfile.php b/app/Http/Livewire/Project/New/SimpleDockerfile.php index be65475a3..8a1d2c024 100644 --- a/app/Http/Livewire/Project/New/SimpleDockerfile.php +++ b/app/Http/Livewire/Project/New/SimpleDockerfile.php @@ -45,6 +45,9 @@ CMD ["nginx", "-g", "daemon off;"] $environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first(); $port = get_port_from_dockerfile($this->dockerfile); + if (!$port) { + $port = 80; + } $application = Application::create([ 'name' => 'dockerfile-' . new Cuid2(7), 'repository_project_id' => 0, diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index fdb682a72..e22a3596c 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -113,7 +113,7 @@ function generateApplicationContainerName(Application $application, $pull_reques return $application->uuid . '-' . $now; } } -function get_port_from_dockerfile($dockerfile): int +function get_port_from_dockerfile($dockerfile): int|null { $dockerfile_array = explode("\n", $dockerfile); $found_exposed_port = null; @@ -127,7 +127,7 @@ function get_port_from_dockerfile($dockerfile): int if ($found_exposed_port) { return (int)$found_exposed_port->value(); } - return 80; + return null; } function defaultLabels($id, $name, $pull_request_id = 0, string $type = 'application', $subType = null, $subId = null) From 5c45908087f385496c49d9dee2a0786234c0d9c8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sun, 1 Oct 2023 17:39:57 +0200 Subject: [PATCH 5/5] fix: if app settings is not saved to db --- .../Livewire/Project/Application/General.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php index b87f82bd7..6281f45dd 100644 --- a/app/Http/Livewire/Project/Application/General.php +++ b/app/Http/Livewire/Project/Application/General.php @@ -104,13 +104,15 @@ class General extends Component } public function mount() { - $this->is_static = $this->application->settings->is_static; - $this->is_git_submodules_enabled = $this->application->settings->is_git_submodules_enabled; - $this->is_git_lfs_enabled = $this->application->settings->is_git_lfs_enabled; - $this->is_debug_enabled = $this->application->settings->is_debug_enabled; - $this->is_preview_deployments_enabled = $this->application->settings->is_preview_deployments_enabled; - $this->is_auto_deploy_enabled = $this->application->settings->is_auto_deploy_enabled; - $this->is_force_https_enabled = $this->application->settings->is_force_https_enabled; + if (data_get($this->application,'settings')) { + $this->is_static = $this->application->settings->is_static; + $this->is_git_submodules_enabled = $this->application->settings->is_git_submodules_enabled; + $this->is_git_lfs_enabled = $this->application->settings->is_git_lfs_enabled; + $this->is_debug_enabled = $this->application->settings->is_debug_enabled; + $this->is_preview_deployments_enabled = $this->application->settings->is_preview_deployments_enabled; + $this->is_auto_deploy_enabled = $this->application->settings->is_auto_deploy_enabled; + $this->is_force_https_enabled = $this->application->settings->is_force_https_enabled; + } } public function submit()