From a7a54db7261606fb552aa5553987db4a3dfcbec9 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 23 Jun 2019 06:00:47 -0700 Subject: [PATCH 1/3] docker-compose: Restructure for some finer control Allow enabling/disabling at top of file Allow no port to be exposed for any service --- docker-compose.jsonnet | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/docker-compose.jsonnet b/docker-compose.jsonnet index 3bda66d..c0df90d 100644 --- a/docker-compose.jsonnet +++ b/docker-compose.jsonnet @@ -11,6 +11,16 @@ // you're actually running, and must manually re-pull to get an updated copy. image_tag:: "latest", + // For each service, whether to deploy that service. + enabled: { + downloader: true, + restreamer: true, + backfiller: true, + cutter: false, + sheetsync: false, + thrimshim: false, + }, + // Twitch channel to capture channel:: "desertbus", @@ -77,7 +87,7 @@ services: { - downloader: { + [if $.enabled.downloader then "downloader"]: { image: "quay.io/ekimekim/wubloader-downloader:%s" % $.image_tag, // Args for the downloader: set channel and qualities command: [ @@ -92,10 +102,10 @@ restart: "on-failure", // Expose on the configured host port by mapping that port to the default // port for downloader, which is 8001. - ports: ["%s:8001" % $.ports.downloader] + [if "downloader" in $.ports then "ports"]: ["%s:8001" % $.ports.downloader] }, - restreamer: { + [if $.enabled.restreamer then "restreamer"]: { image: "quay.io/ekimekim/wubloader-restreamer:%s" % $.image_tag, // Mount the segments directory at /mnt volumes: ["%s:/mnt" % $.segments_path], @@ -103,14 +113,14 @@ restart: "on-failure", // Expose on the configured host port by mapping that port to the default // port for restreamer, which is 8000. - ports: ["%s:8000" % $.ports.restreamer], + [if "restreamer" in $.ports then "ports"]: ["%s:8000" % $.ports.restreamer], command: [ "--base-dir", "/mnt", "--backdoor-port", std.toString($.backdoor_port), ], }, - backfiller: { + [if $.enabled.backfiller then "backfiller"]: { image: "quay.io/ekimekim/wubloader-backfiller:%s" % $.image_tag, // Args for the backfiller: set channel and qualities command: [ @@ -126,10 +136,10 @@ restart: "on-failure", // Expose on the configured host port by mapping that port to the default // port for backfiller, which is 8002. - ports: ["%s:8002" % $.ports.backfiller] + [if "backfiller" in $.ports then "ports"]: ["%s:8002" % $.ports.backfiller] }, - cutter: { + [if $.enabled.cutter then "cutter"]: { image: "quay.io/ekimekim/wubloader-cutter:%s" % $.image_tag, // Args for the cutter: DB and google creds command: [ @@ -148,10 +158,10 @@ restart: "on-failure", // Expose on the configured host port by mapping that port to the default // port for cutter, which is 8003. - ports: ["%s:8003" % $.ports.cutter] + [if "cutter" in $.ports then "ports"]: ["%s:8003" % $.ports.cutter] }, - thrimshim: { + [if $.enabled.thrimshim then "thrimshim"]: { image: "quay.io/ekimekim/wubloader-thrimshim:%s" % $.image_tag, // Args for the thrimshim: set channel and qualities command: [ @@ -164,10 +174,10 @@ restart: "on-failure", // Expose on the configured host port by mapping that port to the default // port for thrimshim, which is 8004. - ports: ["%s:8004" % $.ports.thrimshim] + [if "thrimshim" in $.ports then "ports"]: ["%s:8004" % $.ports.thrimshim] }, - sheetsync: { + [if $.enabled.sheetsync then "sheetsync"]: { image: "quay.io/ekimekim/wubloader-sheetsync:%s" % $.image_tag, // Args for the sheetsync command: [ @@ -186,7 +196,7 @@ restart: "on-failure", // Expose on the configured host port by mapping that port to the default // port for sheetsync, which is 8005. - ports: ["%s:8005" % $.ports.sheetsync] + [if "sheetsync" in $.ports then "ports"]: ["%s:8005" % $.ports.sheetsync] }, }, From 63eb324ba526faca608c3ec18332e50fb8391523 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 23 Jun 2019 06:06:00 -0700 Subject: [PATCH 2/3] Add nginx service that provides a frontend to all the other services This allows us to run all the different services and expose all their metrics, all on one port. --- build | 2 +- docker-compose.jsonnet | 12 ++++++++++-- nginx/Dockerfile | 3 +++ nginx/nginx.conf | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 nginx/Dockerfile create mode 100644 nginx/nginx.conf diff --git a/build b/build index e231e7d..bf29601 100755 --- a/build +++ b/build @@ -8,7 +8,7 @@ set -eu # Pass PUSH=true to also push the resulting images, or PUSH=latest to push them as :latest tag # The different images we can build -COMPONENTS=(downloader restreamer backfiller thrimshim cutter sheetsync) +COMPONENTS=(downloader restreamer backfiller thrimshim cutter sheetsync nginx) # Define push if not already defined PUSH=${PUSH:-} diff --git a/docker-compose.jsonnet b/docker-compose.jsonnet index c0df90d..4482946 100644 --- a/docker-compose.jsonnet +++ b/docker-compose.jsonnet @@ -19,6 +19,7 @@ cutter: false, sheetsync: false, thrimshim: false, + nginx: true, }, // Twitch channel to capture @@ -34,12 +35,13 @@ // The host's port to expose each service on. // Only the restreamer needs to be externally accessible - the others are just for monitoring. ports:: { - restreamer: 8080, - thrimshim: 8081, + restreamer: 8000, + thrimshim: 8004, downloader: 8001, backfiller: 8002, cutter: 8003, sheetsync: 8005, + nginx: 80, }, // The local port within each container to bind the backdoor server on. @@ -199,6 +201,12 @@ [if "sheetsync" in $.ports then "ports"]: ["%s:8005" % $.ports.sheetsync] }, + [if $.enabled.nginx then "nginx"]: { + image: "quay.io/ekimekim/wubloader-nginx:%s" % image_tag, + restart: "on-failure", + [if "nginx" in $.ports then "ports"]: ["%s:80" % $.ports.nginx], + }, + }, } diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..6a6a9ff --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,3 @@ +# nginx container contains config that exposes all the various services metrics +FROM nginx:latest +ADD nginx/nginx.conf /etc/nginx/nginx.conf diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..c442cd1 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,37 @@ + +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; + } + } +} From 6071a2f18d8e8431b30a19b01bfdbcd373e3828d Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 23 Jun 2019 06:17:05 -0700 Subject: [PATCH 3/3] docker_compose: Add a local postgres instance as an optional service The node hosting the database can then easily run it as part of the stack. --- docker-compose.jsonnet | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/docker-compose.jsonnet b/docker-compose.jsonnet index 4482946..eea2b09 100644 --- a/docker-compose.jsonnet +++ b/docker-compose.jsonnet @@ -12,14 +12,15 @@ image_tag:: "latest", // For each service, whether to deploy that service. - enabled: { + enabled:: { downloader: true, restreamer: true, backfiller: true, - cutter: false, - sheetsync: false, - thrimshim: false, + cutter: true, + sheetsync: true, + thrimshim: true, nginx: true, + postgres: true, }, // Twitch channel to capture @@ -32,6 +33,9 @@ // On OSX you need to change this to /private/var/lib/wubloader segments_path:: "/var/lib/wubloader/", + // Local path to save database to. Full path must already exist. Cannot contain ':'. + database_path:: "/var/lib/wubloader_postgres/", + // The host's port to expose each service on. // Only the restreamer needs to be externally accessible - the others are just for monitoring. ports:: { @@ -42,6 +46,7 @@ cutter: 8003, sheetsync: 8005, nginx: 80, + postgres: 5432, }, // The local port within each container to bind the backdoor server on. @@ -53,11 +58,12 @@ "http://wubloader.codegunner.com/" ], - // Connection args for the database + // Connection args for the database. + // If database is defined in this config, host and port should be postgres:5432. db_args:: { user: "postgres", password: "postgres", - host: "localhost", + host: "postgres", port: 5432, dbname: "wubloader", }, @@ -202,11 +208,22 @@ }, [if $.enabled.nginx then "nginx"]: { - image: "quay.io/ekimekim/wubloader-nginx:%s" % image_tag, + image: "quay.io/ekimekim/wubloader-nginx:%s" % $.image_tag, restart: "on-failure", [if "nginx" in $.ports then "ports"]: ["%s:80" % $.ports.nginx], }, + [if $.enabled.postgres then "postgres"]: { + image: "postgres:latest", + restart: "on-failure", + [if "postgres" in $.ports then "ports"]: ["%s:5432" % $.ports.postgres], + environment: { + POSTGRES_USER: $.db_args.user, + POSTGRES_PASSWORD: $.db_args.password, + POSTGRES_DB: $.db_args.dbname, + }, + }, + }, }