Simple GrowthBook setup

Hey, there are a few people using TempusGameIt!  Hurrah!

But now that leads to the question of the logistics of how to deploy breaking changes to the API.  We use feature flags extensively at my work (where we refer to them as Knobs on the server-side).  I wanted to get the same functionality for my own project, but I definitely didn't want to write any code to do so.

After a cursory amount of research I settled on GrowthBook.  

GitHub - growthbook/growthbook: Open Source Feature Flagging and A/B ... 

The main factors in the selection were:

  • Open source
  • The main features--feature flags and experimentation--weren't locked behind a subscription tier 
  • Self-hosting support

The docs are okay on self-hosting, but I thought I'd write-up my super simple solution here.  Note this is for a ultra basic deployment.  I'm not using any of the file writing capabilities, email sending, or proxying.

The infra:

  • A small mongodb in Mongo Atlas
  • A small ubuntu droplet in DigitalOcean
  • A DNS A-type route in AWS's Route 53

The setup:

  1. Spin-up the ubuntu droplet.  Once it is up, ssh into and apt install docker.io docker-compose-v2
  2. Create a new empty mongodb server.
  3. Add a new user to mongodb and grant them dbAdmin and readWrite permissions to new database.  In a bit of a weird quirk, we're not creating the database yet.  We'll let GrowthBook handle it, but we'll make a note of the name we want to call it.  I chose "growthbook".
  4. Go to route 53 and add a route to the static IP of the droplet we created above.  For example growthbook.iheartsunnydays.com
  5. Now, ssh into the droplet.  If things are correctly setup you should be able to connect by using the name you used in the previous step (i.e. ssh root@growthbook.iheartsunnydays.com)
  6. Paste in the following into a file named docker-compose.yml 
    # docker-compose.yml
    version: "3"
    services:
    growthbook:
    image: "growthbook/growthbook:latest"
    ports:
    - "2011:3000"
    - "80:3100"
    environment:
    - NODE_ENV=production
    - MONGODB_URI=${GROWTHBOOK_DB_CONNECTION_STRING}
    - JWT_SECRET=${GROWTHBOOK_JWT_SECRET}
    - ENCRYPTION_KEY=${GROWTHBOOK_ENCRYPTION_KEY}
    - APP_ORIGIN=${GROWTHBOOK_APP_ORIGIN}
    - API_HOST=${GROWTHBOOK_API_HOST}
  7. Touch a new file called growthbook.env in the same location as the docker-compose file.  It should look like the following:
    export GROWTHBOOK_DB_CONNECTION_STRING="<the connection string to your mongodb"
    export GROWTHBOOK_JWT_SECRET="<a long string of random characters>"
    export GROWTHBOOK_ENCRYPTION_KEY="<a long string of random characters>"
    export GROWTHBOOK_APP_ORIGIN="http://<the route name you created above>:2011"
    export GROWTHBOOK_API_HOST="http://<the route name you created above>"
  8. Create a small shell script that pulls it all together (and don't forget to chmod +x it!).  This is a great start: source growthbook.env && docker compose pull && docker compose up -d
  9. Run the script and if you did everything correctly, you should be able to navigate to your new growth book site using http://<the route name you created above>:2011

A few points worth noting:

  • I used a random port for the webfront URL.  I would suggest not leaving up 3000 as this is default used by express and can open you up to random scanning from deviants
  • I set port 80 as the API port because I wanted to not have to worry about ports in my configuration.  Although everything should be in config files anyways and ports shouldn't matter.

So far I've just got it up and running.  I'm going to spend some more time with it soon hopefully.  With any luck I'll have some follow-up posts.

Comments

Popular posts from this blog

Enhanced logging in TempusGameIt

Ultima IV

Add Game Enhancements to TempusGameIt