Skip to content

Server configuration

Ivy Feraco edited this page Apr 2, 2020 · 1 revision

Right now for our server we are using Google Cloud Compute instances.

The goal of configuring the instance with docker and settings files is to not have everything tightly coupled with Google, in case we need to change providers.

Because of this we have decided to go with an Ubuntu 14.04 instance rather than the docker optimized container os of Google. This way we can use the same OS image on AWS or another cloud service if we need to.

Also the docker image had no capabilities other than nginx, so a good separation of services.

Table of Contents

Elements of the system

Server instance

Troubleshooting
Making changes to the server

Elements of the system

  • OS Ubuntu 14.04
  • A startup script startup.sh
  • Dockerfile for the nginx-rtmp server and nginx config file
  • Dockerfile for the stunnel service and config files

The scripts are under source control in our git repo here

nginx-rtmp

The server is a container based on a docker file.

We first used a Dockerfile based on https://hub.docker.com/r/tiangolo/nginx-rtmp
Now we are using a Dockerfile based on https://hub.docker.com/r/alfg/nginx-rtmp

The reason for this is the alfg Dockerfile builds nginx with a flag to enable debug logs (it also has ffmeg encoding installed). The nginx-rtmp container is a bit stripped down though, without bash.

It also has the ability to use environment vars to substitute sensitive info like stream keys. https://github.com/alfg/docker-nginx-rtmp#environment-variables

Right now we are not taking advantage of the env variables but there is an issue open.
The radio_nginx.config.template is just a template with vars for keys that we manually replace right now before uploading to google cloud.

stunnel

We are using stunnel since facebook requires the rtmps protocol for streaming, and nginx-rtmp does not support that as of now. We use docker to create a network skynet to allow the streaming container to talk to the stunnel service [over 19350] (https://github.com/unjust/radio_molecula/blob/master/server/startup.sh#L56)

Server instance

From google cloud we have a template instance-template-ubuntu-1404-solid, which is the Ubuntu instance that uses startup.sh.

The startup script:

  1. installs docker
  2. creates a docker network (called skynet) for the stunnel and nginx-rtmp containers to communicate
  3. build/run a container from the stunnel image
  4. build/run a container from the nginx-rtmp image

All of these resources are grabbed by the instance from our google cloud bucket

As was said all of these scripts are under source control in our git repo here

Starting an instance

  1. Make sure the config bucket (radiomolecula-nginx-config) on Google Storage has all necessary elements.
  • startup.sh is in the bucket
  • folders stunnel-service and nginx-rtmp-service with a Dockerfile for each service
  • each service folder should have associated config files It should mirror whats inside our repo server folder
  1. Create instance from instance-template-ubuntu-1404-solid with region southamerica-east1 (Sao Paulo)

Behind the scenes

Our template uses the metadata field startup-script-url and sets it to the startup.sh gs://radiomolecula-nginx-config/startup.sh More about startup scripts

The startup script

  1. downloads the Docker images and configs and saves them on the instance at stores them at /radio_config.
  2. installs docker
  3. creates a docker network (called skynet) for the stunnel and nginx-rtmp containers to communicate
  4. build/run a container from the stunnel image
  5. builds the image radiomolecula-image based on nginx-rtmp but with our own nginx config
  6. runs the container radiomolecula-server

SSH into instance

You can use the SSH button on the instances list, or install gcloud compute api https://cloud.google.com/compute/docs/instances/connecting-to-instance

and gcloud compute ssh --project [PROJECT_ID] --zone [ZONE] [INSTANCE_NAME]

Example:

gcloud compute ssh --project nonameradio --zone southamerica-east1-b   instance-template-ubuntu-1404-solid-

Troubleshooting

Go here for more about troubleshooting

Making changes

To make changes to the Dockerfiles or configs in https://github.com/unjust/radio_molecula/tree/master/server, first cut a development branch.

In order to test your changes on an instance, you need to upload the changed files to the google cloud bucket.

To not overwrite what is there, you can rename the files in the bucket that you need to replace - you can use a .bak suffix for example to be clear - then after your tests delete your files and rename the originals. Everything should be already saved in our git repo, but this is to be safe.

stunnel service is pretty solid and shouldn't need to be changed.

Changes to radio_nginx.conf.template should be well tested.
Note that this is a template since the keys to fb and yt account streams are placeholders. So you need to replace these with the real keys before you upload them to google.

Do not commit the files with keys on github.