AdmitHub / meteor-buildpack-horse

Heroku buildpack for Meteor v1.0+. The horse one.
MIT License
641 stars 586 forks source link

Add support for review apps #185

Closed tomscholz closed 6 years ago

tomscholz commented 6 years ago

Context Heroku provides a feature for pipelines that is called "review apps". This feature allows you to automatically create dynos based on GitHub pull requests. To enable this feature you need to create a app.json config file in the root of your project. Mine currently looks like this:

{
  "name": "webapp",
  "scripts": {
  },
  "env": {
    "METEOR_SETTINGS": {
      "required": true
    },
    "MONGODB_URI": {
      "required": true
    }
  },
  "formation": {
  },
  "addons": [
    "mongolab"
  ],
  "buildpacks": [
    {
      "url": "https://github.com/AdmitHub/meteor-buildpack-horse.git"
    }
  ]
}

The problem When you enable this feature for your pipeline, the review app dyno isn't able to set the ROOT_URL env var, although all review apps have the HEROKU_APP_NAME config var set, still I get the following error:

-----> Node.js app detected
FATAL: ROOT_URL is not defined.
 !     Push rejected, failed to compile Node.js app.
 !     Push failed

Could it be that this script isn't fired in the beginning and rather at the end? https://github.com/AdmitHub/meteor-buildpack-horse/blob/80eaadd412871891ec12aed40be0b3c426cd1762/extra/root_url.sh#L1-L11

yourcelf commented 6 years ago

There are two stages where meteor requires ROOT_URL to be defined: (1) during compilation, where we build the meteor slug on heroku, and (2) during execution, when the compiled meteor app runs.

Because it needs to be in those two places with two environments, we read or set ROOT_URL in two places: (1) here for compilation, and (2) in the root_url.sh extra for the running app. root_url.sh is indeed sourced at the end; but its job is to write a .profile.d/ entry for the running app to use, not for the compile script's benefit.

The place where the buildpack is failing is in phase (1) -- while trying to compile the app. It looks like neither ROOT_URL nor HEROKU_APP_NAME are within the compile script's environment when it runs, so it fails here.

Something you might try: fork the buildpack and uncomment set -x at the top of the compile script to enable verbose bash debugging before the environment variables are loaded. While you can set the BUILDPACK_VERBOSE env var to enable verbose debugging, that only kicks in after env vars have been parsed. So to debug an issue with loading environment variables into the compile script, you'll need to fork the buildpack and enable that at the top.

This might help point locate the missing HEROKU_APP_NAME -- there could be some issue with how we load in environment variables (which follows Heroku's recommendation) and how Heroku exposes HEROKU_APP_NAME to review apps during the build stage.

tomscholz commented 6 years ago

Woah! :) Thanks for the quick and detailed reply! I've just found out a way to get this working. It is actually pretty easy. All you have to do is to specify HEROKU_APP_NAME as a required config var and Heroku will set those config vars to the new application name. Thanks again for the very detailed and useful instructions how to debug :)

  "env": {
    "HEROKU_APP_NAME": {
      "required": true
    },
}