diff --git a/docker-compose.jsonnet b/docker-compose.jsonnet index eea2b09..444ed04 100644 --- a/docker-compose.jsonnet +++ b/docker-compose.jsonnet @@ -208,9 +208,25 @@ }, [if $.enabled.nginx then "nginx"]: { + # mapping of services to internal ports for nginx to forward + local forward_ports = { + restreamer: 8000, + downloader: 8001, + backfiller: 8002, + cutter: 8003, + thrimshim: 8004, + sheetsync: 8005, + }, image: "quay.io/ekimekim/wubloader-nginx:%s" % $.image_tag, restart: "on-failure", [if "nginx" in $.ports then "ports"]: ["%s:80" % $.ports.nginx], + environment: { + SERVICES: std.join("\n", [ + "%s %s" % [service, forward_ports[service]] + for service in std.objectFields(forward_ports) + if service in $.enabled && $.enabled[service] + ]), + }, }, [if $.enabled.postgres then "postgres"]: { diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 6a6a9ff..7a12782 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,3 +1,4 @@ # nginx container contains config that exposes all the various services metrics FROM nginx:latest -ADD nginx/nginx.conf /etc/nginx/nginx.conf +ADD nginx/generate-config / +ENTRYPOINT ["/bin/sh", "-c", "/generate-config && nginx -g \"daemon off;\""] diff --git a/nginx/generate-config b/nginx/generate-config new file mode 100755 index 0000000..b837428 --- /dev/null +++ b/nginx/generate-config @@ -0,0 +1,35 @@ +#!/bin/bash + +# This script expects a mapping of services and ports in the SERVICES env var, +# with one line per service containing "NAME PORT". + +generate_location() { + # generate_location PATH URL + echo -e "\t\tlocation $1 { proxy_pass $2; }" +} + +LOCATIONS=$( + echo "$SERVICES" | while read name port; do + # restreamer is the catch-all + [ "$name" == "restreamer" ] && generate_location / "http://restreamer:$port" + # thrimshim takes any calls to thrimshim/ + [ "$name" == "thrimshim" ] && generate_location /thrimshim "http://thrimshim:$port" + # all services have metrics under /metrics/SERVICE + generate_location "/metrics/$name" "http://$name:$port/metrics" + done +) + +cat > /etc/nginx/nginx.conf <