0

I've written a Node.js application. I have a configuration file that includes usernames and passwords. I'm committing my code to both OpenShift and GitHub, so I remove the credentials before committing.

However, once I've committed to OpenShift, I need to edit the configuration file on the server and add the credentials for the app to work.

I ssh'd in and got confused by the folder structure.

For example, app-deployments app-root

What is the best way to go about this? I guess I could commit the configuration file with no credentials to GitHub, and commit that same configuration file with the credentials to OpenShift. Is there a best practice for doing this type of thing?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
magician11
  • 4,234
  • 6
  • 24
  • 39

1 Answers1

1

Like most Platform as a Service providers, OpenShift recommends managing configuration information using using environment variables:

OpenShift has a few environment variables to make it easy for your to configure your application to run properly. The following tables show the variables, some examples of what the value would be, and what you might use them for.

This way you can easily have different settings on your development box, integration box, production box, etc. For example, in development you might want to connect to a local database, but in production you might want to connect to a separate database server.

This also allows you to keep sensitive information like passwords and API keys out of your repository.

You can also set your own custom environment variables:

Environment variables can be used to store a variety of different values: application names, usernames, passwords, hostnames, and IP addresses. OpenShift platform provides several environment variables to make it easy but often there is a need to define custom environment variables on the server to keep sensitive information away from code repositories.

...

If the above provided environment variables do not satisfy your need, you can proceed to creating custom environment variables by using the rhc set-env command.

rhc set-env VARIABLE1=VALUE1 VARIABLE2=VALUE2 -a myapp --namespace domain

In your application code you can load variables from the environment and use them however you like. Node.js lets you read environment variables using process.env.ENV_VARIABLE.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Also how do I remove an environment variable if I misspelt it say? – magician11 Jul 03 '14 at 23:31
  • @magician11, try `rhc set-env VARIABLE1=` to clear `VARIABLE1`. – ChrisGPT was on strike Jul 04 '14 at 00:29
  • That cleared the variable value. But the variable itself is still in the env list. I guess it's not really that nb. Just trying to clean up. Thanks @Chris. – magician11 Jul 04 '14 at 04:05
  • 1
    @magician11, I'm surprised this was so hard to find. It [looks like `rhc unset VARIABLE1 -a app-name` will do it](http://books.google.ca/books?id=K6aSAwAAQBAJ&lpg=PA43&ots=1B24pTuVRy&dq=openshift%20remove%20environment%20variable&pg=PA43#v=onepage&q=openshift%20remove%20environment%20variable&f=false). (That's a deep link into Google Books; hopefully you can access it.) – ChrisGPT was on strike Jul 04 '14 at 12:17
  • 1
    Thanks @Chris. Actually it seems the command is rhc env-unset Maybe an update since the book? Thanks though.. led me in the right direction! – magician11 Jul 05 '14 at 14:27