Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic API key and MongoDB password generation #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ All information, thought, and code described here is intended for informational
## Nightscout on Docker
This repository will contain all the configuration files for running Nightscout on a Docker environment. Docker enables the end-user to easily deploy and manage the Nightscout stack on top of a cloud-providers such as SoftLayer, Azure, Digital-Ocean, Amazon Web Services or a private server (Bring Your Own Node).

[![Docker Registry](http://dockeri.co/image/nightscout/cgm-remote-monitor-development)](https://registry.hub.docker.com/u/nightscout/cgm-remote-monitor-development/)
[Docker Hub - Nightscout](https://registry.hub.docker.com/u/nightscout/cgm-remote-monitor-development/)

## Getting started using Docker

Expand All @@ -17,9 +17,9 @@ This repository will contain all the configuration files for running Nightscout

An easy way to deploy and maintain your Docker environment is using Tutum. Tutum provides an user friendly interface for managing the Docker environment running on the cloud provider, which can either be [Amazon Web Services (AWS)](http://aws.amazon.com/), [Digital Ocean (DO)](https://www.digitalocean.com/), [SoftLayer](http://www.softlayer.com/) or [Microsoft Azure](http://azure.microsoft.com/). For this tutorial also provides steps to confugure [Amazone Web Services](cloudprovider/aws.md) and [Digital Ocean](cloudprovider/do.md) which are both quite easy to configure. You will require at least one of the services.

To stack configuration is written in a [Docker Compose](https://docs.docker.com/compose/) (which is the successor of [Fig](http://www.fig.sh/)) compatible language. Please do not forget to change the `API_SECRET` and the MongDB password in `MONGO_CONNECTION` and `MONGODB_PASS` in the environment variables.
The stack configuration is written in a [Docker Compose](https://docs.docker.com/compose/) (which is the successor of [Fig](http://www.fig.sh/)) compatible language. Please do not forget to change the `API_SECRET` and the MongDB password in `MONGO_CONNECTION` and `MONGODB_PASS` in the environment variables.

Currently this deploys the [development branch of the project](https://github.com/fokko/cgm-remote-monitor) as it is not yet wired with the nightscout repository. But this will possibly fixed in the foreseeable future as a collaborator will configure it on the Nightscout repository. Every time a commit is pushed on the branch, the [Docker-hub](https://registry.hub.docker.com/u/fokkodriesprong/cgm-remote-monitor/) will build a new version of the image using a hook on the Github repository.
Currently this deploys the [development branch of the project](https://github.com/fokko/cgm-remote-monitor) as it is not yet wired with the nightscout repository. This will possibly fixed in the foreseeable future as a collaborator will configure it on the Nightscout repository. Every time a commit is pushed on the branch, the [Docker-hub](https://registry.hub.docker.com/u/fokkodriesprong/cgm-remote-monitor/) will build a new version of the image using a hook on the Github repository.

Hit the button to deploy the stack as defined in `docker-compose.yml`.

Expand All @@ -45,12 +45,16 @@ If you have any idea's, don't hesitate to contact me.

### Deploying the stack using Docker compose.

To stack configuration is written in a [Docker Compose](https://docs.docker.com/compose/) (which is the successor of [Fig](http://www.fig.sh/)). Deploying is quick and easy:
** Note: ** This requires Docker Compose 1.5 or greater. Ensure you're running an up-to-date version before running these commands.

To stack configuration is written in a [Docker Compose](https://docs.docker.com/compose/) (which is the successor of [Fig](http://www.fig.sh/)). Unique passwords and API keyss are generated by running the `envgen.sh script`. Deploying is quick and easy:

```bash
git clone https://github.com/nightscout/nightscout-docker.git
cd nightscout-docker
. ./envgen.sh
docker-compose up
```
The API key and MongoDB passwords are automatically generated. Simply scroll to the top of the log output and you will be able to see a copy of them. If you want to use your own, edit the docker-compose.yml file and replace the `${MONGODB_PASS}` and `${NIGHTSCOUT_APIKEY}` with your own values.

All images will be pulled from the registry and started by Docker.
All images will be pulled from the registry and started by Docker.
25 changes: 17 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
##### NOTE #######
# This docker compose file requires docker compose 1.5 to be installed
# before calling docker-compose, ensure you've ready the Readme file first

broker:
image: 'prologic/mosquitto:latest'
ports:
- '1883:1883'
database:
image: 'tutum/mongodb:latest'
environment:
- MONGODB_PASS={{** CHANGE ME **}}
ports:
- '27017:27017'
- MONGODB_PASS:${MONGODB_PASS}

# Uncomment if you want to expose the MongoDB port directly
# If you're using the API interface (highly recommended) then you can
# safely leave this commented out
# ports:
# - '27017:27017'

nightscout:
image: 'nightscout/cgm-remote-monitor-development:latest'
environment:
- API_SECRET={{** CHANGE ME **}}
- 'MONGO_CONNECTION=mongodb://admin:{{** CHANGE ME **}}@database/admin'
- 'MQTT_MONITOR=mqtt://{{** CHANGE ME **}}@broker'
- PORT=1337
- API_SECRET:${NIGHTSCOUT_APIKEY}
- 'MONGO_CONNECTION=mongodb://admin:${MONGODB_PASS}@database/admin'
- 'MQTT_MONITOR=mqtt://${MQTT_USER}@broker'
- PORT:1337
links:
- broker
- database
ports:
- '1337:1337'
- '1337:1337'
22 changes: 22 additions & 0 deletions envgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# This script generates a unique password for the API Key, the MongoDB password and MQTT Username
# To use it, ensure you use . ./envgen.sh (noting the first dot) to set the variables for the current shell
# Then, simply run docker-compose up
echo ""
echo ""
echo "Generating API key and MongoDB password..."
echo "========================================================================================"

# Generate passwords
export NIGHTSCOUT_APIKEY=`docker run --rm timbutler/simplepass 12 1`
export MONGODB_PASS=`docker run --rm timbutler/simplepass 12 1`
export MQTT_USER=`docker run --rm timbutler/simplepass 8 1`

# Print to the screen for reference
echo "Nightscout API key: $NIGHTSCOUT_APIKEY"
echo "MongoDB Admin Password: $MONGODB_PASS"
echo "MQTT User: $MQTT_USER"
echo "========================================================================================"
echo ""
echo "Now you can run "docker-compose up" to build and start the Docker containers"
echo ""