Introduction
Nightscout is an open source cloud application used by people with diabetes to visualize, store, and share the data from their Continuous Glucose Monitoring sensors in real-time. It can also send push notifications and trigger webhooks through integrations such as IFTTT.
Fedora CoreOS is a minimal operating system made for running containers. It can be configured to automatically fetch security updates and newer container images.
This guide helps you deploy Nightscout to the platform of your choice with CoreOS.
Choose a platform
CoreOS has scripts to help you install on:
- Bare Metal
- directly in RAM
- Alibaba Cloud
- AWS
- Azure
- DigitalOcean
- Exoscale
- GCP
- Hyper-V
- IBM Cloud
- KubeVirt
- libvirt
- OpenStack
- Nutanix
- QEMU
- Raspberry Pi 4
- VirtualBox
- VMware
- Vultr
I’m using the libvirt platform instructions but choose your platform from the dropdown list under Provisioning Machines in Getting Started with Fedora CoreOS.
System Configuration
CoreOS’s system configuration is bootstrapped from a single machine readable Ignition file, produced from a human readable Butane configuration file.
Download the latest version of Butane from their releases page on GitHub or go through Getting Started with Butane to see the various ways you can acquire Butane.
To bootstrap your own Nightscout instance use the template below but minimally replace the highlighted CHANGEMEs.
nightscout.bu
variant: fcos
version: 1.5.0
passwd:
users:
- name: core
ssh_authorized_keys:
- ssh-rsa CHANGEME
storage:
files:
- path: /etc/containers/systemd/mongodb.container
contents:
inline: |
[Unit]
Description=mongodb
After=network-online.target
Wants=network-online.target
[Container]
Image=docker.io/mongo:4
Network=host
Volume=mongodb:/data/db
[Install]
WantedBy=multi-user.target
- path: /etc/containers/systemd/nightscout.container
contents:
inline: |
[Unit]
Description=nightscout
After=network-online.target mongodb.service
Wants=network-online.target
[Container]
Image=docker.io/nightscout/cgm-remote-monitor:latest
Environment=TZ=America/Los_Angeles
Environment=INSECURE_USE_HTTP=true
Environment=SECURE_HSTS_HEADER=false
Environment=HOSTNAME=0.0.0.0
Environment=MONGO_CONNECTION=mongodb://localhost:27017/nightscout
Environment=API_SECRET=CHANGEME
Environment=AUTH_DEFAULT_ROLES=readable
Environment=DISPLAY_UNITS=mg/dl
Network=host
[Install]
WantedBy=multi-user.target
Let’s go over each CHANGEME:
- ssh-rsa CHANGEME
Your ssh public key so that you can log in.
Environment=API_SECRET=CHANGEME
The password to make changes in Nightscout.
Persistent storage
Nightscout persists it’s data to a MongoDB database. You might want to format a partition that MongoDB will use before attaching it to the virtual machine. Check out CoreOS’s Configuring Storage to see the various ways to set this up, or keep following below if you also use LVM.
I use LVM to manage storage for my libvirt VMs. These are the few optional steps I took to prepare the filesystem but please DON’T continue unless you understand what is happening.
lvcreate -L 30G MyVolGroup -n CoreOsVol
mkfs.xfs /dev/MyVolGroup/CoreOsVol
blkid /dev/MyVolGroup/CoreOsVol
The last command will return the UUID of the block device. Use it to replace the last CHANGEME in this more complete nightscout template.
Deploy!
Once you’ve finished writing your butane config, translate it to the system readable ignition file with:
butane --pretty --strict nightscout.bu > nightscout.ign
I modified this libvirt launch script to suite my system:
deploy.sh:
#!/bin/bash
IGNITION_CONFIG="/srv/coreos/nightscout.ign"
IMAGE="/srv/coreos/fedora-coreos-38.qcow2"
VM_NAME="nightscout"
VCPUS="4"
RAM_MB="4000"
STREAM="stable"
DISK_GB="12"
virt-install --connect="qemu:///system" --name="${VM_NAME}" --vcpus="${VCPUS}" --memory="${RAM_MB}" \
--os-variant="fedora-coreos-$STREAM" --import --graphics=none --autostart \
--disk="size=${DISK_GB},backing_store=${IMAGE}" \
--network bridge=virbr0 \
--qemu-commandline="-fw_cfg name=opt/com.coreos/config,file=${IGNITION_CONFIG}"
Save as deploy.sh, execute, and enjoy!
Afterthoughts
I hope this has helped you deploy Nightscout with CoreOS! Because your chosen platform is probably different than mine, I intentionally left out some steps. The biggest value add should be the nightscout.bu template I created. There is a ton of documentation elsewhere for deploying to specific platforms.
For a more complete nightscout.bu, check out my other gist. It contains an additional nightscout-settings.json
file that gets imported through the IMPORT_CONFIG
env var. This was the only way I was able to load the maker module key and get IFTTT working. Upon IFTTT receiving an urgent low event, it will turn on a Wyze light.