Skip to content

Commit

Permalink
vendors stack: support multiple domains & maintenance mode (ITISFound…
Browse files Browse the repository at this point in the history
…ation#886)

* vendors: support multiple domains + maintenance mode

* include maintenance

* Fix traefik rule
  • Loading branch information
YuryHrytsuk authored Nov 21, 2024
1 parent 41e5ce3 commit c0e11cd
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 4 deletions.
12 changes: 12 additions & 0 deletions scripts/common.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,22 @@ clean-default: .check_clean ## Cleans all outputs
@.venv/bin/pip3 install --upgrade pip wheel setuptools
@.venv/bin/pip3 install jinja2 j2cli[yaml]
# https://github.com/kolypto/j2cli?tab=readme-ov-file#customization
ifeq ($(shell test -f j2cli_customization.py && echo -n yes),yes)
define jinja
.venv/bin/j2 --format=env $(1) .env -o $(2) --customize j2cli_customization.py
endef
else
define jinja
.venv/bin/j2 --format=env $(1) .env -o $(2)
endef
endif
# Gracefully use defaults and potentially overwrite them, via https://stackoverflow.com/a/49804748
%: %-default
@ true
3 changes: 1 addition & 2 deletions services/maintenance-page/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ services:
- traefik.enable=true
- traefik.docker.network=${PUBLIC_NETWORK}
- traefik.http.routers.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.priority={{MAINTENANCE_PAGES_TRAEFIK_PRIORITY}}
- traefik.http.routers.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.rule={{ "Host(`" + j2item + "`)" }}
- 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(`/`))
- 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(`/`))
- traefik.http.routers.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.tls=true
- traefik.http.services.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.loadbalancer.server.port=80
- traefik.http.routers.{{"maintenance_" + j2item.replace('@','').replace(' ','').replace('.','').replace('-','').replace('\'','') + "_html"}}.entrypoints=https
Expand Down
1 change: 1 addition & 0 deletions services/maintenance-page/template.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ PUBLIC_NETWORK=${PUBLIC_NETWORK}
MONITORED_NETWORK=${MONITORED_NETWORK}
REPO_CONFIG_LOCATION=${REPO_CONFIG_LOCATION}
MAINTENANCE_PAGES_TRAEFIK_PRIORITY=${MAINTENANCE_PAGES_TRAEFIK_PRIORITY}
VENDOR_MANUAL_SUBDOMAIN_PREFIX=${VENDOR_MANUAL_SUBDOMAIN_PREFIX}
1 change: 1 addition & 0 deletions services/vendors/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose.yml
6 changes: 6 additions & 0 deletions services/vendors/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ up-local: up

# Helpers -------------------------------------------------

.PHONY: docker-compose.yml
docker-compose.yml: .venv .env
@$(call jinja, docker-compose.yml.j2, docker-compose.yml.unlinted) && \
$(_yq) docker-compose.yml.unlinted > docker-compose.yml; \
rm docker-compose.yml.unlinted >/dev/null 2>&1;

.PHONY: ${TEMP_COMPOSE}
${TEMP_COMPOSE}: docker-compose.yml .env
${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ services:
manual:
image: ${VENDOR_MANUAL_IMAGE}
init: true
{%- raw %}
hostname: "{{.Node.Hostname}}-{{.Task.Slot}}"
{%- endraw %}
deploy:
replicas: ${VENDOR_MANUAL_REPLICAS}
placement:
Expand All @@ -28,7 +30,7 @@ services:
- traefik.http.services.vendor_manual.loadbalancer.server.port=${VENDOR_MANUAL_PORT}
- traefik.http.routers.vendor_manual.entrypoints=https
- traefik.http.routers.vendor_manual.tls=true
- traefik.http.routers.vendor_manual.rule=Host(`${VENDOR_MANUAL_DOMAIN}`)
- traefik.http.routers.vendor_manual.rule={{ generate_vendors_manual_traefik_rule(VENDOR_MANUAL_PRODUCTS, VENDOR_MANUAL_SUBDOMAIN_PREFIX) }}
- traefik.http.routers.vendor_manual.middlewares=ops_gzip@swarm, authenticated_platform_user@swarm
networks:
- public
Expand Down
11 changes: 11 additions & 0 deletions services/vendors/j2cli_customization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def _generate_vendors_manual_traefik_rule(domains: str, subdomain_prefix: str) -> str:
domain_list = domains.strip().strip(",").split(",")
domains = [f"{subdomain_prefix}.{domain}" for domain in domain_list]
return " || ".join(f"Host(`{d}`)" for d in domains)


def j2_environment(env):
env.globals.update(
generate_vendors_manual_traefik_rule=_generate_vendors_manual_traefik_rule
)
return env
3 changes: 2 additions & 1 deletion services/vendors/template.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VENDOR_MANUAL_IMAGE=${VENDOR_MANUAL_IMAGE}
VENDOR_MANUAL_REPLICAS=${VENDOR_MANUAL_REPLICAS}
VENDOR_MANUAL_DOMAIN=${VENDOR_MANUAL_DOMAIN}
VENDOR_MANUAL_SUBDOMAIN_PREFIX=${VENDOR_MANUAL_SUBDOMAIN_PREFIX}
VENDOR_MANUAL_PRODUCTS=${VENDOR_MANUAL_PRODUCTS}
VENDOR_MANUAL_PORT=${VENDOR_MANUAL_PORT}
PUBLIC_NETWORK=${PUBLIC_NETWORK}

0 comments on commit c0e11cd

Please sign in to comment.