From 78a9a4e5254017db95af2acf69c6465284298336 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Tue, 1 Jan 2019 14:16:20 -0800 Subject: [PATCH] Set up a docker compose file to run all images For ease-of-use, we use a jsonnet file to generate the yaml. Jsonnet is a language for generating JSON documents. In this case it's useful to us because it lets us have comments, references to settings defined at the top, and some basic logic like converting qualities from a list of strings to a comma-seperated string. To avoid requiring jsonnet to be installed, we use the official jsonnet docker image in the generate script. --- .gitignore | 2 +- README.md | 4 +++ docker-compose.jsonnet | 60 +++++++++++++++++++++++++++++++++++++++++ generate-docker-compose | 14 ++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 docker-compose.jsonnet create mode 100755 generate-docker-compose diff --git a/.gitignore b/.gitignore index 5b6b072..1120be9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -config.yaml +docker-compose.yml diff --git a/README.md b/README.md index 6ffcffe..d8d5d15 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,7 @@ but a brief overview of the components: All components are built as docker images. Components which access the disk expect a shared directory mounted at `/mnt`. + +A docker-compose file is provided to run all components. See `docker-compose.jsonnet` +to set configuration options, then generate the compose file with `./generate-docker-compose`. +Then run `docker-compose up`. diff --git a/docker-compose.jsonnet b/docker-compose.jsonnet new file mode 100644 index 0000000..a58044a --- /dev/null +++ b/docker-compose.jsonnet @@ -0,0 +1,60 @@ +// This is a jsonnet file, it generates a docker-compose.yml file. +// To generate, run "make docker-compose.yml". + +{ + + // These are the important top-level settings. + // Change these to configure the services. + + // Image tag (application version) to use. + // Note: "latest" is not reccomended in production, as you can't be sure what version + // you're actually running, and must manually re-pull to get an updated copy. + image_tag:: "latest", + + // Twitch channel to capture + channel:: "desertbus", + + // Stream qualities to capture in addition to source. + qualities:: ["480p"], + + // Local path to save segments to. Full path must already exist. Cannot contain ':'. + segments_path:: "/var/lib/wubloader/", + + // The host's port to expose the restreamer on. + restreamer_port:: 8080, + + + // Now for the actual docker-compose config + + // docker-compose version + version: "3", + + services: { + + downloader: { + image: "quay.io/ekimekim/wubloader-downloader:%s" % $.image_tag, + // Args for the downloader: set channel and qualities + command: [ + $.channel, + "--qualities", std.join(",", $.qualities), + ], + // Mount the segments directory at /mnt + volumes: ["%s:/mnt" % $.segments_path], + // If the application crashes, restart it. + restart: "on-failure", + }, + + restreamer: { + image: "quay.io/ekimekim/wubloader-restreamer:%s" % $.image_tag, + // Mount the segments directory at /mnt + volumes: ["%s:/mnt" % $.segments_path], + // If the application crashes, restart it. + 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" % $.restreamer_port], + }, + + }, + +} diff --git a/generate-docker-compose b/generate-docker-compose new file mode 100755 index 0000000..8b00bb9 --- /dev/null +++ b/generate-docker-compose @@ -0,0 +1,14 @@ +#!/bin/bash + +set -eu + +# We generate first, and capture the output, to avoid overwriting the file on error. +# To avoid jsonnet needing to exist locally, we run it in a container. +output=$(docker run -i sparkprime/jsonnet - < docker-compose.jsonnet) + +{ + echo "# DO NOT EDIT THIS FILE!" + echo "# This file is generated from docker-compose.jsonnet" + echo "# It can be generated by running ./generate-docker-compose" + echo "$output" +} > docker-compose.yml