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

Merge remote-tracking branch 'origin/develop' into develop

parents 694df379 8156494d
Branches develop
No related tags found
1 merge request!14Merging develop into main
Pipeline #1189628 passed with warnings
...@@ -12,6 +12,3 @@ indent_size = 2 ...@@ -12,6 +12,3 @@ indent_size = 2
charset = utf-8 charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true
insert_final_newline = true insert_final_newline = true
[{composer.json,composer.lock}]
indent_size = 4
include: include:
- project: 'gitlab-ci-cd/composer-packages' - project: 'gitlab-ci-cd/drupal'
ref: main ref: main
file: '/composer-packages.yml' file: '/private-modules.yml'
...@@ -6,7 +6,7 @@ use Symfony\Component\Filesystem\Filesystem; ...@@ -6,7 +6,7 @@ use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
/** /**
* Class Traefik. * Provides configuration methods for Traefik.
* *
* @package LakeDrops\DockerTraefik * @package LakeDrops\DockerTraefik
*/ */
...@@ -20,64 +20,88 @@ class Traefik { ...@@ -20,64 +20,88 @@ class Traefik {
protected string $name; protected string $name;
/** /**
* The domain.
*
* @var string * @var string
*/ */
protected string $domain; protected string $domain;
/** /**
* The HTTP port.
*
* @var int * @var int
*/ */
protected int $http_port; protected int $httpPort;
/** /**
* The HTTPS port.
*
* @var int * @var int
*/ */
protected int $https_port; protected int $httpsPort;
/** /**
* The certificate filename.
*
* @var string * @var string
*/ */
protected string $cert_filename; protected string $certFilename;
/** /**
* The key filename.
*
* @var string * @var string
*/ */
protected string $key_filename; protected string $keyFilename;
/** /**
* Flag for enabling the Portainer addon.
*
* @var bool * @var bool
*/ */
protected bool $addon_portainer = FALSE; protected bool $addonPortainer = FALSE;
/** /**
* The Trafik hub token.
*
* @var string * @var string
*/ */
protected string $hub_token = ''; protected string $hubToken = '';
/** /**
* The environment variables.
*
* @var array * @var array
*/ */
protected array $env; protected array $env;
/** /**
* Flag, if tls should be used.
*
* @var bool * @var bool
*/ */
protected bool $tls; protected bool $tls;
/** /**
* Flag, if the DNS challenge should be used.
*
* @var bool * @var bool
*/ */
protected bool $dns_challenge; protected bool $dnsChallenge;
/** /**
* The DNS challenge provider.
*
* @var string * @var string
*/ */
protected string $dns_challenge_provider; protected string $dnsChallengeProvider;
/** /**
* The DNS challenge resolver.
*
* @var string * @var string
*/ */
protected string $dns_challenge_resolver; protected string $dnsChallengeResolver;
/** /**
* Traefik constructor. * Traefik constructor.
...@@ -87,67 +111,74 @@ class Traefik { ...@@ -87,67 +111,74 @@ class Traefik {
* prefix of your project you would like to handle with Traefik. * prefix of your project you would like to handle with Traefik.
* @param string $domain * @param string $domain
* The domain name used for all local projects. * The domain name used for all local projects.
* @param int $http_port * @param int $httpPort
* Port for non secure requests. * Port for non secure requests.
* @param int $https_port * @param int $httpsPort
* Port for secure requests. * Port for secure requests.
* @param string $cert_filename * @param string $certFilename
* Filename of the SSL certificate. * Filename of the SSL certificate.
* @param string $key_filename * @param string $keyFilename
* Filename of the private key for the SSL certificate. * Filename of the private key for the SSL certificate.
* @param array $env * @param array $env
* A list of environment variables for the Traefik container. * A list of environment variables for the Traefik container.
* @param bool $tls * @param bool $tls
* Whether TLS should be supported. * Whether TLS should be supported.
* @param bool $dns_challenge * @param bool $dnsChallenge
* If TLS is supported, it uses the http challenge by default. Set to TRUE * If TLS is supported, it uses the http challenge by default. Set to TRUE
* to use the DNS challenge. * to use the DNS challenge.
* @param string $dns_challenge_provider * @param string $dnsChallengeProvider
* If DNS challenge should be used, a provider is required. For a list of * If DNS challenge should be used, a provider is required. For a list of
* supported providers: * supported providers.
* @see https://doc.traefik.io/traefik/https/acme/#providers * @param string $dnsChallengeResolver
* @param string $dns_challenge_resolver
* In some scenarios, the DNS resolver needs to be defined in order to * In some scenarios, the DNS resolver needs to be defined in order to
* prevent local or shadow DNS servers being used. * prevent local or shadow DNS servers being used.
*
* @see https://doc.traefik.io/traefik/https/acme/#providers
*/ */
public function __construct( public function __construct(
string $name, string $name,
string $domain = 'docker.localhost', string $domain = 'docker.localhost',
int $http_port = 8000, int $httpPort = 8000,
int $https_port = 8443, int $httpsPort = 8443,
string $cert_filename = '', string $certFilename = '',
string $key_filename = '', string $keyFilename = '',
array $env = [], array $env = [],
bool $tls = FALSE, bool $tls = FALSE,
bool $dns_challenge = FALSE, bool $dnsChallenge = FALSE,
string $dns_challenge_provider = '', string $dnsChallengeProvider = '',
string $dns_challenge_resolver = '' string $dnsChallengeResolver = ''
) { ) {
$this->name = $name; $this->name = $name;
$this->domain = $domain; $this->domain = $domain;
$this->http_port = $http_port; $this->httpPort = $httpPort;
$this->https_port = $https_port; $this->httpsPort = $httpsPort;
$this->cert_filename = $cert_filename; $this->certFilename = $certFilename;
$this->key_filename = $key_filename; $this->keyFilename = $keyFilename;
$this->env = $env; $this->env = $env;
$this->tls = $tls; $this->tls = $tls;
$this->dns_challenge = $dns_challenge; $this->dnsChallenge = $dnsChallenge;
$this->dns_challenge_provider = $dns_challenge_provider; $this->dnsChallengeProvider = $dnsChallengeProvider;
$this->dns_challenge_resolver = $dns_challenge_resolver; $this->dnsChallengeResolver = $dnsChallengeResolver;
} }
/** /**
* @param bool $addon_portainer * Sets the flag for the Portainer addon.
*
* @param bool $addonPortainer
* The flag.
*/ */
public function setAddonPortainer(bool $addon_portainer): void { public function setAddonPortainer(bool $addonPortainer): void {
$this->addon_portainer = $addon_portainer; $this->addonPortainer = $addonPortainer;
} }
/** /**
* @param string $hub_token * Sets the hub token.
*
* @param string $hubToken
* The hub token.
*/ */
public function setHubToken(string $hub_token): void { public function setHubToken(string $hubToken): void {
$this->hub_token = $hub_token; $this->hubToken = $hubToken;
} }
/** /**
...@@ -200,10 +231,15 @@ class Traefik { ...@@ -200,10 +231,15 @@ class Traefik {
} }
/** /**
* Updates or deletes the file.
*
* @param string $filename * @param string $filename
* The file name.
* @param string $content * @param string $content
* The file content. If empty, the file will be deleted, if it exists.
* *
* @return bool * @return bool
* TRUE, if an update was necessary, FALSE otherwise.
*/ */
private function updateFile(string $filename, string $content): bool { private function updateFile(string $filename, string $content): bool {
if ($content === '') { if ($content === '') {
...@@ -221,7 +257,10 @@ class Traefik { ...@@ -221,7 +257,10 @@ class Traefik {
} }
/** /**
* Gets the default config.
*
* @return array * @return array
* The default config.
*/ */
private function defaultDockerCompose(): array { private function defaultDockerCompose(): array {
$config = [ $config = [
...@@ -246,7 +285,7 @@ class Traefik { ...@@ -246,7 +285,7 @@ class Traefik {
'traefik-public', 'traefik-public',
], ],
'ports' => [ 'ports' => [
$this->http_port . ':80', $this->httpPort . ':80',
], ],
'labels' => [ 'labels' => [
'traefik.enable=true', 'traefik.enable=true',
...@@ -263,14 +302,14 @@ class Traefik { ...@@ -263,14 +302,14 @@ class Traefik {
], ],
'networks' => [ 'networks' => [
'traefik-public' => [ 'traefik-public' => [
'external' => true, 'external' => TRUE,
], ],
], ],
]; ];
if (!empty($this->env)) { if (!empty($this->env)) {
$config['services']['traefik']['environment'] = $this->env; $config['services']['traefik']['environment'] = $this->env;
} }
if ($this->addon_portainer) { if ($this->addonPortainer) {
$config['services']['portainer'] = [ $config['services']['portainer'] = [
'container_name' => 'portainer', 'container_name' => 'portainer',
'image' => 'portainer/portainer-ce:2.17.1', 'image' => 'portainer/portainer-ce:2.17.1',
...@@ -297,7 +336,7 @@ class Traefik { ...@@ -297,7 +336,7 @@ class Traefik {
], ],
]; ];
} }
if ($this->hub_token) { if ($this->hubToken) {
$config['services']['traefik']['command'][] = '--experimental.hub=true'; $config['services']['traefik']['command'][] = '--experimental.hub=true';
$config['services']['traefik']['command'][] = '--hub.tls.insecure=true'; $config['services']['traefik']['command'][] = '--hub.tls.insecure=true';
$config['services']['traefik']['command'][] = '--metrics.prometheus.addrouterslabels=true'; $config['services']['traefik']['command'][] = '--metrics.prometheus.addrouterslabels=true';
...@@ -308,7 +347,7 @@ class Traefik { ...@@ -308,7 +347,7 @@ class Traefik {
'image' => 'ghcr.io/traefik/hub-agent-traefik:v1.0.1', 'image' => 'ghcr.io/traefik/hub-agent-traefik:v1.0.1',
'command' => [ 'command' => [
'run', 'run',
'--hub.token=' . $this->hub_token, '--hub.token=' . $this->hubToken,
'--auth-server.advertise-url=http://hub-agent', '--auth-server.advertise-url=http://hub-agent',
'--traefik.host=traefik', '--traefik.host=traefik',
'--traefik.tls.insecure=true', '--traefik.tls.insecure=true',
...@@ -329,20 +368,20 @@ class Traefik { ...@@ -329,20 +368,20 @@ class Traefik {
$config['services']['traefik']['command'][] = '--entrypoints.websecure.address=:443'; $config['services']['traefik']['command'][] = '--entrypoints.websecure.address=:443';
$config['services']['traefik']['command'][] = '--entrypoints.web.http.redirections.entrypoint.to=websecure'; $config['services']['traefik']['command'][] = '--entrypoints.web.http.redirections.entrypoint.to=websecure';
$config['services']['traefik']['command'][] = '--certificatesresolvers.lakedrops.acme.email=admin@' . $this->domain; $config['services']['traefik']['command'][] = '--certificatesresolvers.lakedrops.acme.email=admin@' . $this->domain;
$config['services']['traefik']['ports'][] = $this->https_port . ':443'; $config['services']['traefik']['ports'][] = $this->httpsPort . ':443';
$config['services']['traefik']['labels'][] = 'traefik.http.routers.traefik.tls=true'; $config['services']['traefik']['labels'][] = 'traefik.http.routers.traefik.tls=true';
$config['services']['traefik']['labels'][] = 'traefik.http.routers.traefik.tls.certresolver=lakedrops'; $config['services']['traefik']['labels'][] = 'traefik.http.routers.traefik.tls.certresolver=lakedrops';
if ($this->addon_portainer) { if ($this->addonPortainer) {
$config['services']['portainer']['labels'][] = 'traefik.http.routers.frontend.tls=true'; $config['services']['portainer']['labels'][] = 'traefik.http.routers.frontend.tls=true';
$config['services']['portainer']['labels'][] = 'traefik.http.routers.frontend.tls.certresolver=lakedrops'; $config['services']['portainer']['labels'][] = 'traefik.http.routers.frontend.tls.certresolver=lakedrops';
$config['services']['portainer']['labels'][] = 'traefik.http.routers.edge.tls=true'; $config['services']['portainer']['labels'][] = 'traefik.http.routers.edge.tls=true';
$config['services']['portainer']['labels'][] = 'traefik.http.routers.edge.tls.certresolver=lakedrops'; $config['services']['portainer']['labels'][] = 'traefik.http.routers.edge.tls.certresolver=lakedrops';
} }
if ($this->dns_challenge && $this->dns_challenge_provider !== '') { if ($this->dnsChallenge && $this->dnsChallengeProvider !== '') {
$config['services']['traefik']['command'][] = '--certificatesresolvers.lakedrops.acme.dnschallenge=true'; $config['services']['traefik']['command'][] = '--certificatesresolvers.lakedrops.acme.dnschallenge=true';
$config['services']['traefik']['command'][] = '--certificatesresolvers.lakedrops.acme.dnschallenge.provider=' . $this->dns_challenge_provider; $config['services']['traefik']['command'][] = '--certificatesresolvers.lakedrops.acme.dnschallenge.provider=' . $this->dnsChallengeProvider;
if ($this->dns_challenge_resolver !== '') { if ($this->dnsChallengeResolver !== '') {
$config['services']['traefik']['command'][] = '--certificatesresolvers.lakedrops.acme.dnschallenge.resolvers=' . $this->dns_challenge_resolver; $config['services']['traefik']['command'][] = '--certificatesresolvers.lakedrops.acme.dnschallenge.resolvers=' . $this->dnsChallengeResolver;
} }
} }
else { else {
...@@ -354,16 +393,19 @@ class Traefik { ...@@ -354,16 +393,19 @@ class Traefik {
} }
/** /**
* Get the default certificate config.
*
* @return string * @return string
* The default certificate config.
*/ */
private function defaultCertificatesConfig(): string { private function defaultCertificatesConfig(): string {
if ($this->cert_filename === '' || $this->key_filename === '') { if ($this->certFilename === '' || $this->keyFilename === '') {
return ''; return '';
} }
return <<<EOF return <<<EOF
[[tls.certificates]] [[tls.certificates]]
certFile = "/certs/$this->cert_filename" certFile = "/certs/$this->certFilename"
keyFile = "/certs/$this->key_filename" keyFile = "/certs/$this->keyFilename"
EOF; EOF;
} }
......
{ {
"name": "lakedrops/docker-traefik", "name": "lakedrops/docker-traefik",
"description": "Library to prepare local Traefik Docker container which is used by e.g. Docker4Drupal.", "description": "Library to prepare local Traefik Docker container which is used by e.g. Docker4Drupal.",
"type": "library", "type": "library",
"keywords": ["Drupal", "Development", "Docker"], "keywords": [
"homepage": "https://gitlab.lakedrops.com/composer/library/docker-traefik", "Drupal",
"license": "GPL-2.0-or-later", "Development",
"authors": [ "Docker"
{ ],
"name": "Jürgen Haas", "homepage": "https://gitlab.lakedrops.com/composer/library/docker-traefik",
"email": "juergen.haas@lakedrops.com", "license": "GPL-2.0-or-later",
"homepage": "https://www.lakedrops.com", "authors": [
"role": "Drupal Expert" {
}, "name": "Jürgen Haas",
{ "email": "juergen.haas@lakedrops.com",
"name": "Daniel Speicher", "homepage": "https://www.lakedrops.com",
"email": "daniel.speicher@lakedrops.com", "role": "Drupal Expert"
"homepage": "https://www.lakedrops.com",
"role": "Drupal Expert"
},
{
"name": "Richard Papp",
"email": "richard.papp@lakedrops.com",
"homepage": "https://www.lakedrops.com",
"role": "Drupal Expert"
}
],
"support": {
"issues": "https://gitlab.lakedrops.com/composer/library/docker-traefik/issues",
"source": "https://gitlab.lakedrops.com/composer/library/docker-traefik/tree/main",
"docs": "https://devops-tools.docs.lakedrops.com/composer/library/docker-traefik/"
}, },
"require": { {
"php": ">=7.4", "name": "Daniel Speicher",
"symfony/filesystem": "^3.4||^4.4||^5.0||^6.0", "email": "daniel.speicher@lakedrops.com",
"symfony/yaml": "^3.4||^4.4||^5.0||^6.0" "homepage": "https://www.lakedrops.com",
"role": "Drupal Expert"
}, },
"require-dev": { {
"composer/composer": "^1||^2", "name": "Richard Papp",
"drupal/coder": "^8.3", "email": "richard.papp@lakedrops.com",
"phpunit/phpunit": "^9.5", "homepage": "https://www.lakedrops.com",
"roave/security-advisories": "dev-master", "role": "Drupal Expert"
"squizlabs/php_codesniffer": "^3.7" }
}, ],
"minimum-stability": "dev", "support": {
"prefer-stable": true, "issues": "https://gitlab.lakedrops.com/composer/library/docker-traefik/issues",
"autoload": { "source": "https://gitlab.lakedrops.com/composer/library/docker-traefik/tree/main",
"psr-4": { "docs": "https://devops-tools.docs.lakedrops.com/composer/library/docker-traefik/"
"LakeDrops\\DockerTraefik\\": "" },
} "require": {
}, "php": ">=8.1",
"config": { "symfony/filesystem": "*",
"allow-plugins": { "symfony/yaml": "*"
"dealerdirect/phpcodesniffer-composer-installer": true },
} "require-dev": {
"composer/composer": "^2",
"roave/security-advisories": "dev-latest"
},
"autoload": {
"psr-4": {
"LakeDrops\\DockerTraefik\\": ""
} }
}
} }
parameters:
level: 6
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false
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