Closed adamgins closed 7 years ago
Hi @adamgins are you trying to just view the credentials in that service credentials
section? If that is the intent you can click New Credentials
leave the defaults and it'll generate the VCAP for you to see there.
If you want to see the VCAP being used by your app, which you've binded this service. Go into your app's dashboard in Connections
section - you'll see the mongo db instance a View Credentials
button.
Note that what you see in the Service Credentials
section and the View Credential
section in the App's connection area will be the same values.
Thanks for the response.
I need to get the mongo URL programmatically that was generated when the service was created so my nodejs app can access this.
We're trying to setup the automatic set up for the market place, so a customer can deploy the nodejs app and a mongodb without having to manually configure anything.
It seems like when I create a mongodb instance from the console GUI it automatically instertd credentials. When I create via a cf command it doesn't.
Sent from my iPhone
On 10 Mar 2017, at 4:02 am, jcleong notifications@github.com wrote:
Hi @adamgins are you trying to just view the credentials in that service credentials section? If that is the intent you can click New Credentials leave the defaults and it'll generate the VCAP for you to see there.
If you want to see the VCAP being used by your app, which you've binded this service. Go into your app's dashboard in Connections section - you'll see the mongo db instance a View Credentials button.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Hi @adamgins - once you've 'bound' your mongodb service to your nodejs app via cf bind-service "${CF_APP}" "mongodb-${CF_APP}"
what this does is inject the service's mongo URL as a environment variable that your node app can access.
In this repo's sample code you can see them extract the mongo uri via https://github.com/IBM-Bluemix/compose-mongodb-helloworld-nodejs/blob/master/server.js#L67 , work backwards up a few lines and you can see they started extracting this from the env variable at https://github.com/IBM-Bluemix/compose-mongodb-helloworld-nodejs/blob/master/server.js#L40
@jcleong thanks heaps. Ok, cool I can see the mongourl in the VCAP settings.
For Meteor I need to get some of these settings into standard (Non VCAP) environment variables.
I can see I can set it with cf set-env appname variable_a 123
I can see the whole JSON object with cf env {application-name}
Any ideas if there's a script command to get the specific VCAP variable out for the mongoURL? ie <servicename>.credentials.url
? (ie easy to get at it in NodeJS)... but I'd like to get this in the pipeline with some script so I can do a cf set-env appname MONGO_URL <some how get the VCAP variable>
thanks again
I have cloned the code and cf pushed it to Bluemix and it runs. Now I want to run the Code on my local machine (node server.js) but using the Bluemix hosted DB - and here I am getting a list of errors. Any hints where to look at ? What do I have to change ?
What particular errors are you getting?
Have you copied the credentials into the local environment variables?
On 14 Mar 2017, at 08:34, René Baron notifications@github.com wrote:
I have cloned the code and cf pushed it to Bluemix and it runs. Now I want to run the Code on my local machine (node server.js) but using the Bluemix hosted DB - and here I am getting a list of errors. Any hints where to look at ? What do I have to change ?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
Your Quote: "Have you copied the credentials into the local environment variables?" No. How can I do this. Docs ? Links ? I know, it must be basics: However I have not found detailed infos about this.
https://www.ibm.com/watson/developercloud/doc/common/getting-started-variables.html https://www.ibm.com/watson/developercloud/doc/common/getting-started-variables.html
View VCAP_SERVICES in the Bluemix console for your service. Go to your local shell and export that as VCAP_SERVICES in your shell. Then run your application.
On Mar 14, 2017, at 10:58 AM, René Baron notifications@github.com wrote:
Your Quote: "Have you copied the credentials into the local environment variables?" No. How can I do this. Docs ? Links ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/IBM-Bluemix/compose-mongodb-helloworld-nodejs/issues/3#issuecomment-286387867, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEb7DuDOK7C1THkJhAPi-AlZJArXX3Eks5rlnLqgaJpZM4MXpdZ.
Any examples on how to work with json object in the shelll (I know how to do in nodejs but my shell script skills are weak), pls?
@adamgins sorry for the late reply - sounds like you found what you needed with the env credentials and are now onto parsing it?
Re: JSON & JQ I've personally found JQ to be very helpful for shell / json - check out https://stedolan.github.io/jq/ http://blog.librato.com/posts/jq-json
@jcleong thanks. Is jq installed in the bluemix shell or do I just install it using a shell command as part of the script?
@adamgins that i'm not sure and i'm leaning towards maybe not.
Do you mind explaining a bit again at a high level of what you are trying to do. I recall from the thread above that the normally injected env variables into your node js app isn't sufficient because you need another set of env vars set specifically for the meteor app, is that correct?
So it sounds like you're trying to read the original VCAP, parse the mongo uri string and then set new and specific env variables that work with your meteor app?
Where and how are you doing the intermediate steps to parse and set new env variables? Is this in a wrapper script that starts your node app? Is this in bluemix delivery build pipeline functionality?
It may be worthwhile to just try and see if it'll let you install the jq package as part of the process.
@jcleong yes thanks, on to the next step of setting non VCAP environment variables.
MeteorJS meteor.com requires environment variables for MONGO_URL, ROOT_URL, METEOR_SETTINGS to be set. So I need to extract that from the VCAP JSON result I'd get from calling cf env {application-name}
. So piping it to jq
would work and then call cf set-env appname MONGO_URL <whatever I get from jq>
Some additional details including my current script and `, but a slightly but related different problem I am facing http://stackoverflow.com/questions/42755522/bluemix-manual-deploy-of-nodejs-app-mongo-works-devops-pipeline-fails-using-s but you can see the manifest and script (slightly different to the start of this thread).
@adamgins you don't need to have jq if you're not doing a ton of parsing - i think, though possibly awkward, here is one solution to your problem:
cf env {application-name} | egrep -o 'mongodb://.*"' | rev | cut -c 2- | rev
You basically regex match the mongodb uri pattern and remove the extraneous " at the end
@jcleong thanks ... looks like I need a shell script refresher... it's been 20 years since I did awk
& grep
stuff... ha!
BTW, do you know if the Bluemix version of MongoDB support oplog tailing?
@jcleong I have the MONGO_URL working Thanks!!!
#!/bin/bash
cf create-service compose-for-mongodb Standard mongodbbuzzy01
cf push "${CF_APP}" --no-start
mongourl=$(sudo cf env ${CF_APP} | egrep -o 'mongodb://.*"' | rev | cut -c 2- | rev); sudo cf set-env ${CF_APP} MONGO_URL $mongourl
cf restage "${CF_APP}"
Now trying to get the Bluemix URL out :-/
I tried cf env buzzy7build | egrep '("uris": *)'
but as the actual uri of the service is on multiple lines, I guess this does not work.
edited... jq
not avail on bluemix
Looks like I need some sort of awk
command.
BTW< I posted as in StackOverflow too, as I know that's probably a better place for these questions. http://stackoverflow.com/questions/42881778/how-do-i-get-the-application-uris-from-a-bluemix-cloudfoundry-app-in-shell-scr
I got this sorted out as the http://stackoverflow.com/questions/42881778/how-do-i-get-the-application-uris-from-a-bluemix-cloudfoundry-app-in-shell-scr?noredirect=1#42881778 , so I'll close this for now. thanks for the help.
Hi, when I run
cf create-service compose-for-mongodb Standard some-service-id
it creates the services but the creds are blank.BTW, I was actually trying to do this in a Devops pipeline but I het the same issue when I just create the service from the command line:
BTW, I had dumbed down my manifest to:
Any ideas pls?