How to expose Openshift enviroment variables on a json

I have installed node-push-server. The configuration is loaded from a json like this:

{
    "webPort": 8000,

    "mongodbUrl": "mongodb://username:password@localhost/database",

    "gcm": {
        "apiKey": "YOUR_API_KEY_HERE"
    },

    "apn": {
        "connection": {
            "gateway": "gateway.sandbox.push.apple.com",
            "cert": "/path/to/cert.pem",
            "key": "/path/to/key.pem"
        },
        "feedback": {
            "address": "feedback.sandbox.push.apple.com",
            "cert": "/path/to/cert.pem",
            "key": "/path/to/key.pem",
            "interval": 43200,
            "batchFeedback": true
        }
    }
}

How can I set the enviroment variables for my application in this json file?

Upvotes: 0

Views: 386

Answers (2)

ʀɣαɳĵ
ʀɣαɳĵ

Reputation: 1980

Config files can be awkward because including them in your source repo isn't always a good move.

OpenShift deployments are mostly git push-driven, so there are several options for helping you correctly resolve your configs on the server.

Configuring your service using ENV vars is the most common approach, but since this one requires a flat file, you'll need to find a way to update the file with the correct values.

If you know what keys and values are needed, you should be able to write a script that updates the example json, or merges two json objects to produce a flat config file including the strings node-pushserver will expect.

It looks like mongodbUrl, webPort, (and domain?) would need to be populated with OpenShift-provided values (when available). config-multipaas might be able to help with that.

I would probably implement the config bootstrapping / merging work as a build step, allowing you to prep the config file and start node-pushserver in it's usual way

Upvotes: 1

JP_
JP_

Reputation: 1666

I don't think it's possible. You should be able to change all these settings in the code though. For example in node you can do: process.env.OPENSHIFT_VARIABLENAME to read an environment variable.

Example for MongoDB connection string from docs:

//provide a sensible default for local development
mongodb_connection_string = 'mongodb://127.0.0.1:27017/' + db_name;

//take advantage of openshift env vars when available:
if(process.env.OPENSHIFT_MONGODB_DB_URL){
    mongodb_connection_string = process.env.OPENSHIFT_MONGODB_DB_URL + db_name;
}

As an alternative, there is a quick and easy deployable gear called AeroGear Push that might serve your needs.

Upvotes: 2

Related Questions