I have a Cloud Foundry application hosted using Swisscom. One of the features I require from the application is that the user can set up a Cloud Foundry Service - Specifically the Swisscom Secrets-Store service. However, this is turning out to be a bit of a challenge.
Firstly, I used the cloudfoundry-cli NPM module to create the service from my application much like the example provided:
const cf = require('cloudfoundry-cli')
cf.provisionService({
name: 'mongoNo1',
type: 'compose-for-mongodb',
plan: 'Standard'
}, function(err) {
if (err) return console.log(err)
console.log('Service provisioned')
})
This worked fine when I was running my application locally because obviously I have the CF CLI installed on my computer. However, when I pushed the application to Swisscom and tried to create the service nothing happened as the CF CLI isn't installed on the application.
I have also checked out cf-nodejs-client which is suggested if you don't want to install the CF CLI by allowing you to pass your Cloud Foundry login details and API endpoint. However, I've checked the docs and it seems this NPM module doesn't allow you to create services. The documents show you can either getService, getServicePlans, getServices, or remove - No option to create.
Worst case scenario I thought I could SSH into the running application and install the CF CLI, but for that you need root access which is not possible.
My question is - Is it possible to install the CF CLI on the application when it is being pushed? Perhaps a buildpack which can install the CF CLI when the application is being pushed? I have checked the list of community buildpacks and this doesn't seem to exist and I wouldn't know where to start creating one. Otherwise, does anyone know how to create Cloud Foundry services from a Node application without the need of the CF CLI.
Is it possible to install the CF CLI on the application when it is being pushed?
One option would be to simply bundle the cf cli with your application. It's a static binary, so it's pretty easy to bundle with your app. The following should work.
mkdir bin/
then move your binary from step #1 to the bin/
folder..profile
file to the root of your application. In that file, put export PATH=$PATH:$HOME/bin
, which will put the bin/
directory from step #2 on the PATH (change bin
to whatever you named that folder).Now cf push
your app. This will include the binary. When it starts up, the .profile
script will execute and put the path to your cf
binary on the PATH. Thus you can run cf ...
commands in your container.
Hope that helps!