Skip to content
Snippets Groups Projects
Commit 55d692b4 authored by jurgenhaas's avatar jurgenhaas
Browse files

docker/l3d#48 Add support for reverse proxy

parent f40151be
No related branches found
Tags v3.0.1
No related merge requests found
...@@ -191,6 +191,7 @@ docker4drupal: ...@@ -191,6 +191,7 @@ docker4drupal:
ci_home: /home/gitlab-runner ci_home: /home/gitlab-runner
docker0: docker0:
ip: [IP OF YOUR DOCKER HOST] ip: [IP OF YOUR DOCKER HOST]
proxy: [IP OF TRAEFIK PROXY]
live: live:
root: '' root: ''
uri: '' uri: ''
......
...@@ -38,6 +38,9 @@ class Handler extends BaseHandler { ...@@ -38,6 +38,9 @@ class Handler extends BaseHandler {
'ip' => ($this->isCiContext() || $this->isLocalDevMode()) ? 'ip' => ($this->isCiContext() || $this->isLocalDevMode()) ?
$this->getDockerGateway() : $this->getDockerGateway() :
$this->getLocalIpv4('docker0'), $this->getLocalIpv4('docker0'),
'proxy' => ($this->isCiContext() || $this->isLocalDevMode()) ?
$this->getDockerProxy($projectname) :
FALSE,
], ],
'live' => [ 'live' => [
'root' => '', 'root' => '',
...@@ -358,6 +361,18 @@ class Handler extends BaseHandler { ...@@ -358,6 +361,18 @@ class Handler extends BaseHandler {
return $container['NetworkSettings']['Gateway']; return $container['NetworkSettings']['Gateway'];
} }
/**
* @return string
*/
private function getDockerProxy(string $projectname): string {
foreach ($this->readNetworkConfig($projectname)['Containers'] as $container) {
if (isset($container['Name']) && $container['Name'] === 'traefik_traefik_1') {
return explode('/', $container['IPv4Address'])[0];
}
}
return '127.0.0.1';
}
/** /**
* @param $projectRoot * @param $projectRoot
* *
...@@ -402,4 +417,23 @@ class Handler extends BaseHandler { ...@@ -402,4 +417,23 @@ class Handler extends BaseHandler {
]; ];
} }
/**
* @param string $projectname
*
* @return array
*/
private function readNetworkConfig(string $projectname): array {
try {
$output = [];
exec('docker network inspect traefik_' . $projectname, $output);
return json_decode(implode('', $output), TRUE)[0];
}
catch (Exception $ex) {
// Ignore.
}
return [
'Containers' => [],
];
}
} }
<?php <?php
{% if drupal.version >= 8 %} {% if drupal.version >= 8 %}
{% if docker0.proxy %}
$settings['reverse_proxy'] = TRUE;
$settings['reverse_proxy_addresses'] = array("{{ docker0.proxy }}");
{% endif %}
$settings['trusted_host_patterns'] = array( $settings['trusted_host_patterns'] = array(
'^{{ projectname }}\.docker\.localhost$', '^{{ projectname }}\.docker\.localhost$',
'^{{ webserver.type }}$', '^{{ webserver.type }}$',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment