← Back to Guides
Profile image for Paul Burt
Published 19th December 2024

Deploy GrowthBook on Northflank

This guide will show you how to deploy GrowthBook with Northflank. GrowthBook’s public docker image growthbook/growthbook:latest will be used for the deployment. You have the option to deploy to Northflank Cloud and your own cloud (BYOC).

What is GrowthBook? Why use it?

GrowthBook is the most popular open-source platform for feature flagging and A/B testing experimentation. Think of it as a way to de-risk new feature rollouts by limiting exposure of new features to a subset of real users. GrowthBook includes a visual editor for your pages, auto-generates SQL queries for analyzing data, and stores your data in whatever data storage you prefer.

Since GrowthBook controls the essential functionality of your website, it’s also an ideal app to deploy on your own cloud. Read more about why you might want to do that in the BYOC section.

GrowthBook gives non-coding roles the power to make site changes themselves. It includes a visual editor for your existing web pages. When it is time to analyse the impact of a feature, it also provides a flexible report-building solution.

The other main benefit of GrowthBook is it keeps you in control of your data. All reports are exportable as Jupyter notebooks, and any report’s SQL query can be modified or copied. You choose where you store your data. This means you can use Snowflake or nearly any other data warehouse solution as your source of truth.

Northflank simplifies the deployment of GrowthBook. Many of the values of the deployment will automatically fill in from the Dockerfile. Installing a database as an addon is also easy to do in a few clicks.

Deploy GrowthBook on Northflank Cloud

This guide will show you how to deploy GrowthBook on Northflank with a MongoDB database addon, a deployment service for the GrowthBook docker image, and a secret group for securely managing connection details.

To start, you need to sign up or sign in to your Northflank account.

Create a project

A project is a namespace for resources. It allows your resources to communicate securely with each other. You can deploy to different regions, to Northflank's managed cloud, or bring your own cloud provider (BYOC).

  1. Click the create new button at the top of the page, and click to create a new project

  2. Fill in a name and region, and then submit

    The page for creating a new project on Northflank. Choose a region and a name.

Set up MongoDB

Next, you need to create a MongoDB addon. Think of addons as a managed database service on Northflank. Tasks like upgrades, backups, and disaster recovery are configurable in just a few clicks.

  1. On the top navigation click the addons option and on the next page click the create new addon button. Select MongoDB and choose a name and version for the database.
Note: You might want to consider choosing a more powerful compute option, if this is intended for production. Both compute and storage may be scaled after your initial deployment.
  1. Click the create addon button at the bottom of the page

  2. On the left hand navigation click connection details. On the upper right of the page click link to secret groups and follow the prompt.

  3. Choose a name, and then scroll down to the section named linked addons. Click show addons and choose the configure button next to your MongoDB instance

  4. From the list of environment variables click on MONGO_SRV. On the row below it click the add button next to aliases. Name the alias MONGODB_URI.

  5. Click create secret group

    Deploy a MongoDB database addon on Northflank.

Deploy GrowthBook

Next, you need to deploy the GrowthBook container as a service. In Northflank, a service is just a shorthand for similar phrases like microservice, deployment, or workload. Deployment services can deploy an image built on Northflank or from an external container registry like in this example. If you want to build from your own Git repository, click here to see those docs.

  1. At the top of the page click the create new button and choose service

  2. From the top row of three options, click deploy a docker Image. Give your service a name and in the deployment section click external image. Since GrowthBook is hosted publicly on DockerHub you can make the image path growthbook/growthbook:latest.

  3. To improve maintainability you should rename the ports. Scroll down to the Networking section and rename port 3000 to app. If port 3100 is set as TCP, change it to HTTP. Click the box Publicly expose this port to the internet and rename it to api.

  4. At the bottom of the page click the Create service button

    Create a new service for the GrowthBook docker image on Northflank.

    Set ports for the service on Northflank.

Environment variables and secrets

You’re on the final steps! Next, you need to set a few environment variables. This is often where programs store configuration values or secrets such as API keys. Secret groups on Northflank can also automatically link to your addon's connection details to your application. Since these values often contain sensitive information, Northflank securely encrypts and injects these at runtime in order to improve security.

The values are taken from GrowthBook’s Git repo and their docs. This guide includes everything you need to get up and running, but you have these links in case you want to look more closely at the values.

  1. Set environment variables by going to secrets and select your secret group. In the upper right of the table of values, click the env option.

  2. Copy and paste the following values into the free text field that appears.

    ```
    APP_ORIGIN="https://ReplaceThisWithTheAppURL:443"
    API_HOST="https://ReplaceThisWithTheApiURL:443"
    NODE_ENV="production"
    JWT_SECRET="ReplaceThisWithaSecureGeneratedKey"
    ENCRYPTION_KEY="ReplaceThisWithaSecureGeneratedKey"
    CORS_ORIGIN_REGEX=".*"
    ```
    You’ll notice in this script that a few of these values need to be added by you. Thankfully, everything you need to do that should be on your current project.
  3. In the upper right of the table, you should see a button with a key icon that says Generate secret values. Use this to create values for JWT_SECRET and ENCRYPTION_KEY. A length of 256 or more is recommended.

  4. Similarly, on the top navigation bar locate the Services link and open it in a new tab. Select your service. In the upper right of the page you should find URLs that look like api-projectname-r4ss2gd9bzvt.code.run. Copy the URL beginning with app for APP_ORIGIN and the api URL for API_HOST.

  5. For both URLs, prepend https:// at the beginning. Append :443 at the end. This ensures GrowthBook runs with TLS enabled.

  6. Click Update Configuration to save your changes to the secret group.

    Generate secure secret values on Northflank.

Restart to pick up changes

You should restart your service to pick up the secrets changes and then you can view your new GrowthBook app. Northflank's dashboard for your service gives you access to your application at the code.run domain provided by Northflank, which is displayed prominently in the header.

From here you can monitor the progress of builds, check the status of deployed containers, and scale, pause and restart your service. Access more configuration options and deployment information from the sidebar.

  1. To do so, navigate to your GrowthBook deployment under Services. Click the icon that looks like an arrow forming a circle. When you hover your mouse over the icon it should say Rollout restart.
  2. Wait for your service to fully restart. You can tell the redeploy is done, if the progress bar near the top right of the page is green in color.
  3. In the upper right of the page find the URL beginning with app and click the button to the right of it to open it.
To troubleshoot or inspect build and runtime containers, click on the build or deployment to view real-time logs and metrics, healthchecks, shell access. These tools are invaluable for diagnosing issues, maintaining uptime, and ensuring your service has the necessary resources to meet demand.

Create an infra-as-code template to deploy GrowthBook

What if you want to codify GrowthBook’s deployment? Then you need Northflank’s templates. Templates create dynamic and reproducible infrastructure as code (IaC) for any project.

You can use templates to quickly reproduce the same environment and deploy the same app into different clouds or regions with a single click.

  1. Create a new template

    1. Click the Create New button at the top of the page, and click on Template. Scroll down and click the button Get started with the visual editor.
    2. This should show you a page with two panes. The left is the visual representation of the template, and the right is a set of options for whichever node you have selected.
    3. On the project node, which should be already selected, set the name to growthbook for the project and a pick a deployment region. Click on Save node.
    4. The prior name is for the project that will be deployed when you run the template. You will also need to pick a name like GrowthBook for the template itself. The Name field for this is on the upper left of the page.
  2. From the right hand bar, click and drag Addon to the bottom of your template below the project node.

    1. Click MongoDB, set the name to mongo, and for the version choose latest
    2. Click Save node
  3. You want the database to be up and running before the service gets deployed. Let’s add a node to make the service wait. From the right-hand bar, click and drag await condition to the bottom of your template.

    1. In the options pane pick Addon for the resource kind, the database name mongo which you just created for resource. For the field Wait until… select resource is running.
    2. Click to save node
  4. From the right-hand bar, click and drag deployment service to the bottom of the visual editor.

    1. Set the service name to growthbook-svc, select external image, and set the docker image to growthbook/growthbook:latest.
    2. Scroll down to the networking section. For port 3000 set the name to app. For port 3100 change the protocol to HTTP and click the box to publicly expose this port to the internet. Finally, for port 3100 set the name to api.
  5. From the right-hand bar, click and drag Secrets group to the bottom of the template below the deployment.

    1. Give your secret group the name connection, and scroll down to the Secrets section. Click the Env option and copy and paste the following.
      APP_ORIGIN="https://${refs.growthbook-svc.ports.0.dns}:443"
      API_HOST="https://${refs.growthbook-svc.ports.1.dns}:443"
      NODE_ENV="production"
      JWT_SECRET="${fn.randomSecret(256, 'base64')}"
      ENCRYPTION_KEY="${fn.randomSecret(256, 'base64')}"
      CORS_ORIGIN_REGEX=".*"
    2. The next step is adding the connection string from the MongoDB Addon created in one of the previous steps. Scroll down to Linked Addons and click on your Addon.
    3. Click on MONGO_SRV. Under Aliases click the plus mark and enter MONGODB_URI. Click save node.
  6. The final step is to restart the deployment, so it can pick up the new environment variables in the secrets group. This is necessary since you made a secrets group with a reference to the deployment (like ${refs.growthbook-svc.ports.0.dns}). The deployment has to exist before that reference will have a value.

    1. From the right-hand bar, click and drag Run action below the secrets group node. Set Kind to service. Set Project to growthbook (which you set in the first step). Set Resource to growthbook-svc, which is the name you chose in step 2.
    2. Set Action to restart and click save node.
    3. Finally, click to save changes and click the Run button on the upper right of the template page. A new project named growthbook will be created, and as steps are successfully executed you will see them turn green. Once everything is green, you can explore your project.

Deploy GrowthBook to AWS, GCP, or Azure with BYOC

You can integrate your cloud account with Northflank to deploy into other cloud providers, such as GCP, AWS, or Azure. This will let you deploy Northflank-managed clusters into your chosen cloud provider and fine-tune your infrastructure and networking to suit your requirements.

You can deploy the same workloads and projects across any cloud provider, manually or using templates, without having to change a single configuration detail.

What's next?

Try exploring the GrowthBook’s docs for setting up your first test. Alternatively, you can learn more about adding a domain, which would solve the issue of the CORS_ORIGIN_REGEX needing to be a .* catch all. Or, you could read our docs for creating a release flow that includes ephemeral preview environments.

You can add pipelines and releases flows. These can automate your entire DevOps workflow from dev to prod. Set up ephemeral preview environments to automatically share your work with reviewers on your team.

Get production ready with Northflank through horizontal and vertical scaling. You have observability, metrics, and logs to explore for your project.

Deploy GrowthBook on Northflank for free

Northflank allows you to deploy your code and databases within minutes. Sign up for a Northflank account and create a free project to get started.

  • Deployment of Docker containers
  • Create your own stateful workloads
  • Persistent volumes
  • Observe & monitor with real-time metrics & logs
  • Low latency and high performance
  • Backup, restore and fork databases
Share this article with your network
X