Setting environmental variables inside runners?

mocha
runner
nodejs
terminal

#1

Hello,
I want to set up the following environmental variables in my runner:

      "env": {
        "MYSQL_USER_NAME": "$C9_USER",
        "MYSQL_USER_PASS": "",
        "MYSQL_DB": "C9",
        "MYSQL_HOST": "$IP"
      },

So my full runner looks like:

{
  "cmd": [
    "mocha",
    "${debug?--debug-brk=5858}",
    "$file",
    "$args"
  ],
  "info": "mocha $file",
  "working_dir": "~/lending-club-folio-app",
  "env": {
    "MYSQL_USER_NAME": "$C9_USER",
    "MYSQL_USER_PASS": "",
    "MYSQL_DB": "C9",
    "MYSQL_HOST": "$IP"
  },
  "debugger": "v8",
  "debugport": 5858
}

I can’t seem to find documentation that helps with this. Any guidance would be great! (Was also looking for an environment related tag I could supply as well.)


#2

Bump…
I wonder if this is a bug?


#3

Are you trying to set up SQL? @esend7881


#4

MYSQL is already set up. I am just trying to set env variables.


#5

Currently env treats all variables as literal strings, so “$C9_USER” is not expanded
as a workaround you could use

MYSQL_USER_NAME": "\"$C9_USER\"",

or

{
  "script": [
    "export MYSQL_USER_NAME=$C9_USER",
    "export MYSQL_HOST=$IP",
    "mocha ${debug?--debug-brk=5858} \"$file\" $args"
  ],
  "info": "mocha $file",
  "working_dir": "~/lending-club-folio-app",
  "env": {
    "MYSQL_USER_PASS": "",
    "MYSQL_DB": "C9",
  },
  "debugger": "v8",
  "debugport": 5858
}

This seems a bit more complicated than putting everything into env so maybe we should change https://github.com/c9/c9.ide.run/blob/3f669210654575bcf7bd7e8fa0b30f203554ace3/run.js#L324 to quote with " instead of '


#6

EDIT: Nevermind - found a more recent edition buried further down … https://github.com/Aerogami/guides/wiki/Cloud9-workspace-setup-with-Rails-and-Postgresql

I’m not super versed at code-diving which way is valid now? The history shows a last commit of March 2016 (https://github.com/c9/c9.ide.run/commits/3f669210654575bcf7bd7e8fa0b30f203554ace3/run.js) as of April 7th, 2017 … so I’m assuming this post is still relevant? As I’m rather new, trying to make sure that this is solid information to debug setting my db env up to export to heroku…thus trying to confirm with you guys!

If I’m reading this right …

"production": { "MYPOSTSQL_USER_NAME": "SOME_USER", "MYPOSTSQL_USER_PASS": "SOME_PASS"}

Would work if I have the rest of the data in the database.yml?

Really I’m looking for the secure way to pass the user/pass for the database - is there a better way?

Thanks,

-M