Merge pull request #1656 from nextcloud/enh/noid/fix-exposing-containers

fix exposing containers
This commit is contained in:
Simon L 2023-01-02 17:55:32 +01:00 committed by GitHub
commit 454269ec5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 18 deletions

View file

@ -5,12 +5,12 @@ namespace AIO\Container;
class ContainerPort { class ContainerPort {
public string $port; public string $port;
public string $ipBinding; public string $ipBinding;
public bool $protocol; public string $protocol;
public function __construct( public function __construct(
string $port, string $port,
string $ipBinding, string $ipBinding,
bool $protocol string $protocol
) { ) {
$this->port = $port; $this->port = $port;
$this->ipBinding = $ipBinding; $this->ipBinding = $ipBinding;

View file

@ -77,6 +77,17 @@ class ContainerDefinitionFetcher
$ports = new ContainerPorts(); $ports = new ContainerPorts();
foreach ($entry['ports'] as $value) { foreach ($entry['ports'] as $value) {
if ($value['port_number'] === '%APACHE_PORT%') {
$value['port_number'] = $this->configurationManager->GetApachePort();
} elseif ($value['port_number'] === '%TALK_PORT%') {
$value['port_number'] = $this->configurationManager->GetTalkPort();
}
if ($value['ip_binding'] === '%APACHE_IP_BINDING%') {
$value['ip_binding'] = $this->configurationManager->GetApacheIPBinding();
}
$ports->AddPort( $ports->AddPort(
new ContainerPort( new ContainerPort(
$value['port_number'], $value['port_number'],

View file

@ -361,31 +361,19 @@ class DockerActionManager
$exposedPorts = []; $exposedPorts = [];
if ($container->GetInternalPort() !== 'host') { if ($container->GetInternalPort() !== 'host') {
foreach($container->GetPorts()->GetPorts() as $value) { foreach($container->GetPorts()->GetPorts() as $value) {
$exposedPorts[$value->port] = null; $portWithProtocol = $value->port . '/' . $value->protocol;
$exposedPorts[$portWithProtocol] = null;
} }
} }
if(count($exposedPorts) > 0) { if(count($exposedPorts) > 0) {
$requestBody['ExposedPorts'] = $exposedPorts;
foreach ($container->GetPorts()->GetPorts() as $value) { foreach ($container->GetPorts()->GetPorts() as $value) {
$port = $value->port; $port = $value->port;
if($port === '%APACHE_PORT%') {
$port = $this->configurationManager->GetApachePort();
} elseif($port === '%TALK_PORT%') {
$port = $this->configurationManager->GetTalkPort();
}
$ipBinding = $value->ipBinding; $ipBinding = $value->ipBinding;
if($ipBinding === '%APACHE_IP_BINDING%') {
$ipBinding = $this->configurationManager->GetApacheIPBinding();
}
if ($ipBinding === '') {
$ipBinding = '0.0.0.0';
}
$protocol = $value->protocol; $protocol = $value->protocol;
$portWithProtocol = $port . '/' . $protocol; $portWithProtocol = $port . '/' . $protocol;
$requestBody['ExposedPorts'][$portWithProtocol] = null; $requestBody['HostConfig']['PortBindings'][$portWithProtocol] = [
$requestBody['HostConfig']['PortBindings'][$port] = [
[ [
'HostPort' => $port, 'HostPort' => $port,
'HostIp' => $ipBinding, 'HostIp' => $ipBinding,