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