Skip to content
Snippets Groups Projects
Commit 99a5647c authored by jurgenhaas's avatar jurgenhaas
Browse files

composer/plugin/docker4drupal#48 Improve setup to only work on a single network traefik-public

Update Traefik to 2.6
Update Portainer to 2.11.1
parent b0a4f22c
No related branches found
No related tags found
No related merge requests found
...@@ -84,23 +84,17 @@ class Traefik { ...@@ -84,23 +84,17 @@ class Traefik {
/** /**
* Update the Traefik container. * Update the Traefik container.
*
* @param bool $rewrite
*/ */
public function update($rewrite = FALSE): void { public function update(): void {
// Update host wider traefik container. // Update host wide traefik container.
$traefikPath = $_SERVER['HOME'] . '/.traefik'; $traefikPath = $_SERVER['HOME'] . '/.traefik';
$traefikCertPath = $_SERVER['HOME'] . '/.traefik/certs'; $traefikCertPath = $_SERVER['HOME'] . '/.traefik/certs';
$traefikConfigPath = $_SERVER['HOME'] . '/.traefik/configuration'; $traefikConfigPath = $_SERVER['HOME'] . '/.traefik/configuration';
$traefikFile = $traefikPath . '/docker-compose.yml'; $traefikFile = $traefikPath . '/docker-compose.yml';
$fs = new Filesystem(); $fs = new Filesystem();
if (!$rewrite && $fs->exists($traefikFile)) { if (!$fs->exists($traefikPath)) {
$traefik = Yaml::parse(file_get_contents($traefikFile));
}
else {
$fs->mkdir($traefikPath); $fs->mkdir($traefikPath);
$traefik = $this->defaultDockerCompose();
} }
if (!$fs->exists($traefikCertPath)) { if (!$fs->exists($traefikCertPath)) {
$fs->mkdir($traefikCertPath); $fs->mkdir($traefikCertPath);
...@@ -109,18 +103,12 @@ class Traefik { ...@@ -109,18 +103,12 @@ class Traefik {
$fs->mkdir($traefikConfigPath); $fs->mkdir($traefikConfigPath);
} }
file_put_contents($traefikConfigPath . '/certificates.toml', $this->defaultCertificatesConfig()); file_put_contents($traefikConfigPath . '/certificates.toml', $this->defaultCertificatesConfig());
file_put_contents($traefikFile, Yaml::dump($this->defaultDockerCompose(), 9, 2));
if (!in_array($this->name, $traefik['services']['traefik']['networks'], TRUE)) { $cwd = getcwd();
$traefik['services']['traefik']['networks'][] = $this->name; chdir($traefikPath);
$traefik['networks'][$this->name] = [ exec('docker network create traefik-public 2>/dev/null');
'driver' => 'bridge', exec('docker compose --project-name traefik up -d');
]; chdir($cwd);
file_put_contents($traefikFile, Yaml::dump($traefik, 9, 2));
$cwd = getcwd();
chdir($traefikPath);
exec('docker compose --project-name traefik up -d');
chdir($cwd);
}
} }
/** /**
...@@ -131,7 +119,7 @@ class Traefik { ...@@ -131,7 +119,7 @@ class Traefik {
'version' => '3.3', 'version' => '3.3',
'services' => [ 'services' => [
'traefik' => [ 'traefik' => [
'image' => 'traefik:v2.3', 'image' => 'traefik:2.6',
'command' => [ 'command' => [
'--api=true', '--api=true',
'--api.dashboard=true', '--api.dashboard=true',
...@@ -147,7 +135,7 @@ class Traefik { ...@@ -147,7 +135,7 @@ class Traefik {
], ],
'restart' => 'unless-stopped', 'restart' => 'unless-stopped',
'networks' => [ 'networks' => [
'internal', 'traefik-public',
], ],
'ports' => [ 'ports' => [
$this->http_port . ':80', $this->http_port . ':80',
...@@ -155,7 +143,7 @@ class Traefik { ...@@ -155,7 +143,7 @@ class Traefik {
], ],
'labels' => [ 'labels' => [
'traefik.enable=true', 'traefik.enable=true',
'traefik.network=internal', 'traefik.network=traefik-public',
'traefik.http.routers.traefik.service=api@internal', 'traefik.http.routers.traefik.service=api@internal',
'traefik.http.routers.traefik.rule=Host(`traefik.' . $this->domain . '`)', 'traefik.http.routers.traefik.rule=Host(`traefik.' . $this->domain . '`)',
], ],
...@@ -167,22 +155,22 @@ class Traefik { ...@@ -167,22 +155,22 @@ class Traefik {
], ],
], ],
'networks' => [ 'networks' => [
'internal' => [ 'traefik-public' => [
'internal' => true, 'external' => true,
], ],
], ],
]; ];
if ($this->addon_portainer) { if ($this->addon_portainer) {
$config['services']['portainer'] = [ $config['services']['portainer'] = [
'image' => 'portainer/portainer-ce:2.0.0', 'image' => 'portainer/portainer-ce:2.11.1',
'command' => '-H unix:///var/run/docker.sock', 'command' => '-H unix:///var/run/docker.sock',
'restart' => 'unless-stopped', 'restart' => 'unless-stopped',
'networks' => [ 'networks' => [
'internal', 'traefik-public',
], ],
'labels' => [ 'labels' => [
'traefik.enable=true', 'traefik.enable=true',
'traefik.network=internal', 'traefik.network=traefik-public',
'traefik.http.routers.frontend.rule=Host(`portainer.' . $this->domain . '`)', 'traefik.http.routers.frontend.rule=Host(`portainer.' . $this->domain . '`)',
'traefik.http.routers.frontend.entrypoints=websecure', 'traefik.http.routers.frontend.entrypoints=websecure',
'traefik.http.services.frontend.loadbalancer.server.port=9000', 'traefik.http.services.frontend.loadbalancer.server.port=9000',
......
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