feat: attach Coolify defined networks to services

This commit is contained in:
Andras Bacsai 2023-10-02 16:57:55 +02:00
parent d446cd4103
commit 540717e809
3 changed files with 7 additions and 4 deletions

View File

@ -4,6 +4,7 @@
use Lorisleiva\Actions\Concerns\AsAction;
use App\Models\Service;
use Symfony\Component\Yaml\Yaml;
class StartService
{
@ -22,7 +23,11 @@ public function handle(Service $service)
$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;
}

View File

@ -32,8 +32,6 @@ public function mount()
- type: volume
source: mydata
target: /data
volume:
nocopy: true
- type: bind
source: ./var/lib/ghost/data
target: /data

View File

@ -258,7 +258,7 @@ public function parse(bool $isNew = false): Collection
$networks = $serviceNetworks->toArray();
foreach ($definedNetwork as $key => $network) {
$networks = array_merge($networks, [
$network => null
$network
]);
}
data_set($service, 'networks', $networks);