Skip to content

Instantly share code, notes, and snippets.

@ianchesal
Last active August 13, 2023 13:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianchesal/5c96c566ab99b60c2c557711fa52a720 to your computer and use it in GitHub Desktop.
Save ianchesal/5c96c566ab99b60c2c557711fa52a720 to your computer and use it in GitHub Desktop.
Migrating NightScout site from Heroku to Render.com

Migrating NightScout from Heroku to Render.com

!!!! Attention !!!!

These are mostly my rough notes on the process I followed to migrate my NightScout site from Heroku to Render.

They have not been rigorously tested or attempted more than the one time I migrated.

I'm using NightScout with a Dexcom setup. I have no idea if these instructions will work for any other CGM setup.

This will deviate your fork of NightScout from the upstream fork and if you're uncomfortable with maintaining that delta you probably don't want to do any of this.

The instructions assume a fairly advanced amount of knowledge of how site hosting works on Heroku and Render.

The free plan might work. It might not work. I have enough things querying my NightScout site that I generate more than one request every 15 minutes. So the site should stay alive. If you don't think you incoming traffic will be high enough to keep the site alive, the $7/month plan will be enough to keep it lively in between your accesses.

I tried to keep the deviations from the master branch as minimal as possible to get this up and running in Render. This is going to complicate saying aligned with upstream for me so I wanted those complications minimal.

Prerequisites

  • You're already running your NightScout site on Heroku
  • You have your MonogoDB running in Atlas and not in Heroku
  • You have a Render account set up

Setup

We're mainly following the Render guide for migrating from Heroku.

  • Install the heroku CLI and then install the render migration plugin according to the instructions in the Render doc above
  • Make sure your fork of NightScout is current with upstream master branch
  • Clone your NightScout fork
  • Make a new branch from master: git checkout -b render-migration

Migration

Inside your git repo, at the top of the repo...

Login to Heroku:

heroku auth:login

Run the Render plugin to generate the docker files:

heroku render:import --app <app-name>

The <app-name> part here should be the name of your app in your Heroku account (for me it's cia-nightscout).

You'll get a notification about the Heroku PaperTrail plugin not being supported. That's fine. We'll re-set-up PaperTrail later. It's log aggregation and not a big concern to us here since Render does nice log aggregation for us already. But worth noting that PaperTrail is supported by Render -- it's just a little more manual to set it up than it is in Heroku.

You'll want to take note of all of those env vars that the plugin prints out. Those are secrets that didn't end up in the render.yaml file it created. You'll want those later to add into the Render interface as secrets.

You'll also want to delete the MONGODB_URI from the render.yaml file -- that's got your MonogDB credentials in it and shouldn't be in the file. Keep track of that variable though! You'll need it later when we setup the site!

I also took BRIDGE_USER_NAME out of render.yaml. That's the username used to log into the Dexcom bridge. Felt secret enough to me so I removed it too.

Here are all the env vars I had to keep aside for later:

API_SECRET
BRIDGE_PASSWORD
MAKER_KEY
# Actually don't need this one. It's empty in my setup b/c I'm a Dexcom user.
# MMCONNECT_PASSWORD
PAPERTRAIL_API_TOKEN
MONGODB_URI
BRIDGE_USER_NAME
AUTH_DEFAULT_ROLES

I just dumped them all into a .env file in my git repo for the time being. And I was careful to not check .env into git! I added the following to .gitignore to protect me from my own stupid here:

/.env

Check in your changes and new files and push your branch to your upstream fork of the NightScout repo on Github:

git add .gitignore Dockerfile.render render.yaml
git commit -m "Heroku to Render migration"
git push origin HEAD

Note: for the steps printed out by the heroku render plugin to work you need to connect your Render account to your Github account. You can do that from your account page in Render. There's a button to do that in the Profile section of the Account Settings page.

Note: You should put your Heroku NightScout site in Maintenance Mode at this point in time. For me, that means running:

heroku maintenance:on --app cia-nightscout

You should replace cia-nightscout with the name of your site in Heroku.

The Render heroku plugin gives you a URL to use with Render to connect up your repo and build your site there. That URL is apparently old. There is no type=iac type of site available on Render any more. Instead you should use the Web Service type from dashboard.render.com to start deploying your site on Render or click here: https://dashboard.render.com/select-repo?type=web

Enter the URL to your fork of the NightScout site in Github.

On the next page fill out your details:

  • Give you site a unique name (your site URL will be <whateveryouenterhere>.onrender.com)
  • For Environment you want to pick Docker
  • Pick a region. The default is fine.
  • Pick a branch. Here you want to use render-migration

See my note in the top of the gist for which plan to pick. You may be good with Free, but only you can figure that out. In any case, $7/month is a steal and worth it.

Under the Advanced section at the bottom of the site creation page there's an option to Add Environment Variables. You'll need to add each secret environment variable in your local .env file here, one at a time. I tried just dumping everything into a remote .env file but NightScout doesn't read it so you need to do it this way.

You can leave everything else at it's defaults here.

Hit that Create Web Service button and...watch it build.

You should be good to hit the .onrender.com URL and view your site.

I left my Heroku deploy around in maintenance mode for a while until I was certain the Render site was working well.

Connecting to PaperTrail

The Heroku build used Papertrial for logging which was pretty nice. You can't migrate your old PaperTrail API key to this site. It was specific to Heroku. So you need to make a new account on https://papertrail.com/ and get a new API. Then you can use the Settings screen on your Render site and configure log forwarding to PaperTrail there.

See the Render docs for how to do this: https://render.com/docs/log-streams#papertrail

You create the log stream in your Account settings, not in the App settings.

Going Forward

So the new render-migration branch in your repository is the one that matters now. If you need to sync to the NightScout upstream branch it's a little more complicated. I'd recommend:

  • Keeping your fork's master super clean
  • Rebase the remote NightScout master into your fork's master
  • Rebase your fork's master into your render-migration branch

Render will auto-deploy when you push changes up to render-master in your fork. You can turn that off in your Render site settings if you'd like to do deploys manually.

Updates

2021-04-16 -- Post Migration

Overall migration was successful. One thing: render.yaml doesn't seem to have placed any of the non-secret environment variables into my Docker container's environment. Not sure what's up there. I ended up just creating all the env vars in render.yaml as secret env vars. This persisted the site title, colour settings, etc. as before in Heroku.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment