diff --git a/scripts/common.Makefile b/scripts/common.Makefile index d2022001..553ec38d 100644 --- a/scripts/common.Makefile +++ b/scripts/common.Makefile @@ -97,6 +97,22 @@ export DEPLOYMENT_FQDNS_TESTING_CAPTURE_TRAEFIK_RULE:=$(shell set -o allexport; echo $$DEPLOYMENT_FQDNS_TESTING_CAPTURE_TRAEFIK_RULE; \ set +o allexport; ) +export DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE:=$(shell set -o allexport; \ + source $(REPO_CONFIG_LOCATION); \ + if [ -z "$${DEPLOYMENT_FQDNS}" ]; then \ + DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE="(Host(\`www.$$MACHINE_FQDN\`) && PathPrefix(\`/\`))"; \ + else \ + IFS=', ' read -r -a hosts <<< "$${DEPLOYMENT_FQDNS}"; \ + DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE="(Host(\`www.$$MACHINE_FQDN\`) && PathPrefix(\`/\`))"; \ + for element in "$${hosts[@]}"; \ + do \ + DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE="$$DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE || (Host(\`www.$$element\`) && PathPrefix(\`/\`))";\ + done; \ + DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE="$$DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE"; \ + fi; \ + echo $$DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE; \ + set +o allexport; ) + export DEPLOYMENT_FQDNS_APPMOTION_CAPTURE_TRAEFIK_RULE:=$(shell set -o allexport; \ source $(REPO_CONFIG_LOCATION); \ if [ -z "$${DEPLOYMENT_FQDNS}" ]; then \ diff --git a/services/traefik/docker-compose.yml.j2 b/services/traefik/docker-compose.yml.j2 index 71e6bb30..7424204a 100644 --- a/services/traefik/docker-compose.yml.j2 +++ b/services/traefik/docker-compose.yml.j2 @@ -97,7 +97,7 @@ services: # via https://community.traefik.io/t/v2-2-8-global-redirect-www-to-non-www-with-http-to-https/7428 # see also: https://community.traefik.io/t/get-a-valid-ssl-certificate-for-www-domains-via-traefik-and-lets-encrypt/2023 # Global redirection: https (www.) to https - - traefik.http.routers.www-catchall.rule=Host(`www.osparc.local`) + - traefik.http.routers.www-catchall.rule={{ DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE.strip("\"") }} - traefik.http.routers.www-catchall.priority=100000 - traefik.http.routers.www-catchall.entrypoints=https,http - traefik.http.routers.www-catchall.tls=true diff --git a/services/traefik/template.env b/services/traefik/template.env index acde96d1..bb36e5bf 100644 --- a/services/traefik/template.env +++ b/services/traefik/template.env @@ -31,7 +31,7 @@ CERTIFICATE_GENERATION_FQDNS='${CERTIFICATE_GENERATION_FQDNS}' CERTIFICATE_RESOLVE_DNS_CHALLANGE_IP=${CERTIFICATE_RESOLVE_DNS_CHALLANGE_IP} OPS_TRAEFIK_LETSENCRYPT_ACME_CA_SERVER=${OPS_TRAEFIK_LETSENCRYPT_ACME_CA_SERVER} OPS_TRAEFIK_LOGLEVEL=${OPS_TRAEFIK_LOGLEVEL} - +DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE="${DEPLOYMENT_FQDNS_WWW_CAPTURE_TRAEFIK_RULE}" PUBLIC_NETWORK=${PUBLIC_NETWORK} MONITORED_NETWORK=${MONITORED_NETWORK}