heroku-buildpack-meteor icon indicating copy to clipboard operation
heroku-buildpack-meteor copied to clipboard

Heroku failing to find settings.json on launch

Open trustieee opened this issue 9 years ago • 10 comments

I've posted about this on stack overflow.

I've ensured config:set is METEOR_SETTINGS="$(cat settings.json)" and Heroku fails to find it at runtime.

Not sure if it's buildpack related, but basically Heroku is not finding my settings.json while following the steps laid out in the readme here.

trustieee avatar Jun 23 '15 14:06 trustieee

What is the value of METEOR_SETTINGS if you run heroku config?

It sounds like something about your shell configuration may mean the $() method of putting the output of the cat command into the heroku config:set command isn't working. The idea of that command from the README is that the value of the METEOR_SETTINGS env var on Heroku should end up being the text content of your settings.json file, not the literal string "$(cat settings.json)".

wfleming avatar Jun 23 '15 15:06 wfleming

Value of METEOR_SETTINGS is:

METEOR_SETTINGS: 'cat settings.json'

If that's not the recommended approach, what is a way to ensure that my app on Heroku grabs the contents of settings.json when ran? As right now the error Heroku spits out is:

Error: METEOR_SETTINGS are not valid JSON: 'cat settings.json'

trustieee avatar Jun 24 '15 15:06 trustieee

As far as I know, you can't set it up to pickup settings.json at run time, because the app running on your dyno has been compiled into a plain Node app. Current best practice I've seen suggested on other hosts (specifically modulus.io) is the same as in this buildpack's README: put the contents of the settings.json in an env var.

I would recommend either 1) figuring out why heroku config:add METEOR_SETTINGS="$(cat settings.json)" isn't doing the correct thing or 2) manually copying the contents of your settings.json file into the heroku command to set your environment for now.

Option 2 there is kind of a pain, and more of a temporary bandaid than a real fix.

For actually figuring out why the README command isn't working for you, what shell do you use, and what environment are you working in? When you run heroku config:set METEOR_SETTINGS="$(cat settings.json)" in your shell, what is the output?

wfleming avatar Jun 24 '15 16:06 wfleming

Running on Windows - but have access to commands like cat/ls/etc...

Setting config vars and restarting XXX... done, v22
METEOR_SETTINGS: $(cat settings.json)

So what really should happen is the output of cat settings.json should be fed into METEOR_SETTINGS at the time of running config:set.

trustieee avatar Jun 24 '15 16:06 trustieee

Ah, are you using PuTTY, or a different way of getting unix tools on Windows? Are you running these commands in PowerShell, or a bash shell, or something else?

Not knowing the specifics, you could try some variants of the $() command substitution syntax: it may be that your setup isn't running it because it doesn't know that syntax, or maybe because it's quoted. Some different variations that may work (without just copy-pasting file contents by hand):

  • heroku run config:set METEOR_SETTINGS="cat settings.json"
  • heroku run config:set METEOR_SETTINGS=$(cat settings.son)
  • heroku run config:set METEOR_SETTINGS=cat settings.json

wfleming avatar Jun 24 '15 17:06 wfleming

Getting closer - had to switch to powershell from "cmder". The output of the file is interpreted but the quotes are stripped around the json keys, which looks to be happening due to heroku and not powershell.

{   mode: prod,   public: {     initiativeLimit: 5   } }

This is the output when running:

heroku config:set METEOR_SETTINGS=$(cat settings.json)

However when running: $(cat settings.json) the output is correct and maintains the quotes from the file's json.

Looking further into this (hoping keeping the conversation here will help others on Windows who don't want to manually get the contents of the file, minify it, and set it each time)

trustieee avatar Jun 24 '15 17:06 trustieee

Even manually running:

heroku config:set METEOR_SETTINGS="{"foo":"bar"}"

... fails, as the quotes inside are stripped out. Need to instead manually escape each quote like this:

heroku config:set METEOR_SETTINGS="{\"foo\":\"bar\"}"

Fun times.

trustieee avatar Jun 24 '15 17:06 trustieee

Did you try the original form METEOR_SETTINGS="$(cat settings.json)" in powershell? Just curious.

Yeah, sorry it's such a pain: Window's command line stuff is not usually terribly pleasant, and I don't have much experience with it. You could write a ruby script to do the hard stuff for you, of course, which may be a useful thing to do if you expect to change settings often.

wfleming avatar Jun 24 '15 17:06 wfleming

  • Open git bash CLI of Windows.
  • heroku config:set METEOR_SETTINGS="$(cat settings.json)"
  • Enjoy :)

haotangio avatar Jul 26 '15 10:07 haotangio

@haotangio Very thanks man! Why it works only in git bash CLI?

egorgrushin avatar Aug 07 '16 21:08 egorgrushin