Merge pull request #3374 from Vahor/host-network
fix: don't add `networks` key if `network_mode` is used
This commit is contained in:
@@ -16,8 +16,10 @@ class StartService
|
||||
$service->saveComposeConfigs();
|
||||
$commands[] = 'cd '.$service->workdir();
|
||||
$commands[] = "echo 'Saved configuration files to {$service->workdir()}.'";
|
||||
if($service->networks()->count() > 0){
|
||||
$commands[] = "echo 'Creating Docker network.'";
|
||||
$commands[] = "docker network inspect $service->uuid >/dev/null 2>&1 || docker network create --attachable $service->uuid";
|
||||
}
|
||||
$commands[] = 'echo Starting service.';
|
||||
$commands[] = "echo 'Pulling images.'";
|
||||
$commands[] = 'docker compose pull';
|
||||
|
||||
@@ -3109,6 +3109,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
||||
}
|
||||
$volumes = collect(data_get($service, 'volumes', []));
|
||||
$networks = collect(data_get($service, 'networks', []));
|
||||
$use_network_mode = data_get($service, 'network_mode') !== null;
|
||||
$depends_on = collect(data_get($service, 'depends_on', []));
|
||||
$labels = collect(data_get($service, 'labels', []));
|
||||
$environment = collect(data_get($service, 'environment', []));
|
||||
@@ -3308,6 +3309,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
||||
$depends_on = $newDependsOn;
|
||||
}
|
||||
}
|
||||
if(!$use_network_mode) {
|
||||
if ($topLevel->get('networks')?->count() > 0) {
|
||||
foreach ($topLevel->get('networks') as $networkName => $network) {
|
||||
if ($networkName === 'default') {
|
||||
@@ -3336,6 +3338,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect/create/update ports
|
||||
$collectedPorts = collect([]);
|
||||
@@ -3359,6 +3362,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
||||
|
||||
$networks_temp = collect();
|
||||
|
||||
if(!$use_network_mode) {
|
||||
foreach ($networks as $key => $network) {
|
||||
if (gettype($network) === 'string') {
|
||||
// networks:
|
||||
@@ -3385,6 +3389,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$normalEnvironments = $environment->diffKeys($allMagicEnvironments);
|
||||
$normalEnvironments = $normalEnvironments->filter(function ($value, $key) {
|
||||
@@ -3623,9 +3628,11 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
||||
$payload = collect($service)->merge([
|
||||
'container_name' => $containerName,
|
||||
'restart' => $restart->value(),
|
||||
'networks' => $networks_temp,
|
||||
'labels' => $serviceLabels,
|
||||
]);
|
||||
if(!$use_network_mode){
|
||||
$payload['networks'] = $networks_temp;
|
||||
}
|
||||
if ($ports->count() > 0) {
|
||||
$payload['ports'] = $ports;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user