magician11
magician11

Reputation: 4624

Editing configuration files on OpenShift

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?

Upvotes: 0

Views: 979

Answers (1)

Chris
Chris

Reputation: 137108

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.

Upvotes: 1

Related Questions