From 540717e80987b7c86a85abc620ac60a3a3cf8fe0 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 2 Oct 2023 16:57:55 +0200 Subject: [PATCH] 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);