Merge pull request #58 from ekimekim/mike/nginx-dns-hack

Fix nginx when some services are disabled
pull/61/head
Mike Lang 6 years ago committed by GitHub
commit 51efeb1f12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -208,9 +208,25 @@
}, },
[if $.enabled.nginx then "nginx"]: { [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, image: "quay.io/ekimekim/wubloader-nginx:%s" % $.image_tag,
restart: "on-failure", restart: "on-failure",
[if "nginx" in $.ports then "ports"]: ["%s:80" % $.ports.nginx], [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"]: { [if $.enabled.postgres then "postgres"]: {

@ -1,3 +1,4 @@
# nginx container contains config that exposes all the various services metrics # nginx container contains config that exposes all the various services metrics
FROM nginx:latest 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;\""]

@ -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 <<EOF
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
$LOCATIONS
}
}
EOF

@ -1,37 +0,0 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
location / {
proxy_pass http://restreamer:8000;
}
location /thrimshim {
proxy_pass http://thrimshim:8004;
}
# Restreamer metrics would be available regardless, this is just for consistency
location /metrics/restreamer {
proxy_pass http://restreamer:8000/metrics;
}
location /metrics/downloader {
proxy_pass http://downloader:8001/metrics;
}
location /metrics/backfiller {
proxy_pass http://backfiller:8002/metrics;
}
location /metrics/cutter {
proxy_pass http://cutter:8003/metrics;
}
location /metrics/thrimshim {
proxy_pass http://thrimshim:8004/metrics;
}
location /metrics/sheetsync {
proxy_pass http://sheetsync:8005/metrics;
}
}
}
Loading…
Cancel
Save