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
No related tags found
No related merge requests found
......@@ -191,6 +191,7 @@ docker4drupal:
ci_home: /home/gitlab-runner
docker0:
ip: [IP OF YOUR DOCKER HOST]
proxy: [IP OF TRAEFIK PROXY]
live:
root: ''
uri: ''
......
......@@ -38,6 +38,9 @@ class Handler extends BaseHandler {
'ip' => ($this->isCiContext() || $this->isLocalDevMode()) ?
$this->getDockerGateway() :
$this->getLocalIpv4('docker0'),
'proxy' => ($this->isCiContext() || $this->isLocalDevMode()) ?
$this->getDockerProxy($projectname) :
FALSE,
],
'live' => [
'root' => '',
......@@ -358,6 +361,18 @@ class Handler extends BaseHandler {
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
*
......@@ -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
{% if drupal.version >= 8 %}
{% if docker0.proxy %}
$settings['reverse_proxy'] = TRUE;
$settings['reverse_proxy_addresses'] = array("{{ docker0.proxy }}");
{% endif %}
$settings['trusted_host_patterns'] = array(
'^{{ projectname }}\.docker\.localhost$',
'^{{ 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