Add customer domain Traefik routing
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
function pnpaas_traefik_labels(?string $domain, string $containerName): array
|
||||
{
|
||||
$domain = strtolower(trim((string)$domain));
|
||||
if ($domain === '') {
|
||||
return [];
|
||||
}
|
||||
if (strlen($domain) > 253 || !preg_match('/^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/', $domain)) {
|
||||
throw new InvalidArgumentException('Die Kundendomain ist kein gültiger FQDN.');
|
||||
}
|
||||
|
||||
$routerName = strtolower(trim((string)preg_replace('/[^a-z0-9-]+/i', '-', $containerName), '-'));
|
||||
if ($routerName === '' || strlen($routerName) > 63) {
|
||||
throw new InvalidArgumentException('Der Instanzname kann nicht als Traefik-Router verwendet werden.');
|
||||
}
|
||||
|
||||
return [
|
||||
'traefik.enable' => 'true',
|
||||
'traefik.docker.network' => 'traefik-public',
|
||||
'traefik.http.routers.' . $routerName . '.rule' => 'Host(`' . $domain . '`)',
|
||||
'traefik.http.routers.' . $routerName . '.entrypoints' => 'websecure',
|
||||
'traefik.http.routers.' . $routerName . '.tls' => 'true',
|
||||
'traefik.http.routers.' . $routerName . '.tls.certresolver' => 'le',
|
||||
'traefik.http.services.' . $routerName . '.loadbalancer.server.port' => '30000',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user