Skip to content

Commit c0e11cd

Browse files
authored
vendors stack: support multiple domains & maintenance mode (#886)
* vendors: support multiple domains + maintenance mode * include maintenance * Fix traefik rule
1 parent 41e5ce3 commit c0e11cd

File tree

8 files changed

+37
-4
lines changed

8 files changed

+37
-4
lines changed

scripts/common.Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,22 @@ clean-default: .check_clean ## Cleans all outputs
245245
@.venv/bin/pip3 install --upgrade pip wheel setuptools
246246
@.venv/bin/pip3 install jinja2 j2cli[yaml]
247247
248+
249+
# https://github.com/kolypto/j2cli?tab=readme-ov-file#customization
250+
ifeq ($(shell test -f j2cli_customization.py && echo -n yes),yes)
251+
252+
define jinja
253+
.venv/bin/j2 --format=env $(1) .env -o $(2) --customize j2cli_customization.py
254+
endef
255+
256+
else
257+
248258
define jinja
249259
.venv/bin/j2 --format=env $(1) .env -o $(2)
250260
endef
251261
262+
endif
263+
252264
# Gracefully use defaults and potentially overwrite them, via https://stackoverflow.com/a/49804748
253265
%: %-default
254266
@ true

services/maintenance-page/docker-compose.yml.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ services:
2828
- traefik.enable=true
2929
- traefik.docker.network=${PUBLIC_NETWORK}
3030
- traefik.http.routers.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.priority={{MAINTENANCE_PAGES_TRAEFIK_PRIORITY}}
31-
- traefik.http.routers.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.rule={{ "Host(`" + j2item + "`)" }}
32-
- traefik.http.routers.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.rule=(Host(`{{j2item}}`) && PathPrefix(`/`)) || (HostRegexp(`services.{{j2item}}`,`{subhost:[a-zA-Z0-9-]+}.services.{{j2item}}`) && PathPrefix(`/`))
31+
- traefik.http.routers.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.rule=Host(`{{VENDOR_MANUAL_SUBDOMAIN_PREFIX}}.{{j2item}}`) || (Host(`{{j2item}}`) && PathPrefix(`/`)) || (HostRegexp(`services.{{j2item}}`,`{subhost:[a-zA-Z0-9-]+}.services.{{j2item}}`) && PathPrefix(`/`))
3332
- traefik.http.routers.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.tls=true
3433
- traefik.http.services.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.loadbalancer.server.port=80
3534
- traefik.http.routers.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.entrypoints=https

services/maintenance-page/template.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ PUBLIC_NETWORK=${PUBLIC_NETWORK}
88
MONITORED_NETWORK=${MONITORED_NETWORK}
99
REPO_CONFIG_LOCATION=${REPO_CONFIG_LOCATION}
1010
MAINTENANCE_PAGES_TRAEFIK_PRIORITY=${MAINTENANCE_PAGES_TRAEFIK_PRIORITY}
11+
VENDOR_MANUAL_SUBDOMAIN_PREFIX=${VENDOR_MANUAL_SUBDOMAIN_PREFIX}

services/vendors/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker-compose.yml

services/vendors/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ up-local: up
3030

3131
# Helpers -------------------------------------------------
3232

33+
.PHONY: docker-compose.yml
34+
docker-compose.yml: .venv .env
35+
@$(call jinja, docker-compose.yml.j2, docker-compose.yml.unlinted) && \
36+
$(_yq) docker-compose.yml.unlinted > docker-compose.yml; \
37+
rm docker-compose.yml.unlinted >/dev/null 2>&1;
38+
3339
.PHONY: ${TEMP_COMPOSE}
3440
${TEMP_COMPOSE}: docker-compose.yml .env
3541
${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@

services/vendors/docker-compose.yml renamed to services/vendors/docker-compose.yml.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ services:
44
manual:
55
image: ${VENDOR_MANUAL_IMAGE}
66
init: true
7+
{%- raw %}
78
hostname: "{{.Node.Hostname}}-{{.Task.Slot}}"
9+
{%- endraw %}
810
deploy:
911
replicas: ${VENDOR_MANUAL_REPLICAS}
1012
placement:
@@ -28,7 +30,7 @@ services:
2830
- traefik.http.services.vendor_manual.loadbalancer.server.port=${VENDOR_MANUAL_PORT}
2931
- traefik.http.routers.vendor_manual.entrypoints=https
3032
- traefik.http.routers.vendor_manual.tls=true
31-
- traefik.http.routers.vendor_manual.rule=Host(`${VENDOR_MANUAL_DOMAIN}`)
33+
- traefik.http.routers.vendor_manual.rule={{ generate_vendors_manual_traefik_rule(VENDOR_MANUAL_PRODUCTS, VENDOR_MANUAL_SUBDOMAIN_PREFIX) }}
3234
- traefik.http.routers.vendor_manual.middlewares=ops_gzip@swarm, authenticated_platform_user@swarm
3335
networks:
3436
- public
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def _generate_vendors_manual_traefik_rule(domains: str, subdomain_prefix: str) -> str:
2+
domain_list = domains.strip().strip(",").split(",")
3+
domains = [f"{subdomain_prefix}.{domain}" for domain in domain_list]
4+
return " || ".join(f"Host(`{d}`)" for d in domains)
5+
6+
7+
def j2_environment(env):
8+
env.globals.update(
9+
generate_vendors_manual_traefik_rule=_generate_vendors_manual_traefik_rule
10+
)
11+
return env

services/vendors/template.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
VENDOR_MANUAL_IMAGE=${VENDOR_MANUAL_IMAGE}
22
VENDOR_MANUAL_REPLICAS=${VENDOR_MANUAL_REPLICAS}
3-
VENDOR_MANUAL_DOMAIN=${VENDOR_MANUAL_DOMAIN}
3+
VENDOR_MANUAL_SUBDOMAIN_PREFIX=${VENDOR_MANUAL_SUBDOMAIN_PREFIX}
4+
VENDOR_MANUAL_PRODUCTS=${VENDOR_MANUAL_PRODUCTS}
45
VENDOR_MANUAL_PORT=${VENDOR_MANUAL_PORT}
56
PUBLIC_NETWORK=${PUBLIC_NETWORK}

0 commit comments

Comments
 (0)