Skip to content

v3 Cloud Native Buildpack - Flatten $VCAP_SERVICES into individual environment variables

License

Notifications You must be signed in to change notification settings

Qarik-Group/pancake-cnb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pancake Buildpack

This tiny buildpack does a simple thing for your application - it flattens the crazy $VCAP_SERVICES service instance credentials into many specific environment variables.

In the following example, in addition to $VCAP_SERVICES the application will also have variables starting with MYSQL_ for each credential (such as MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_URI, for credentials hostname, username, and uri):

Usage

rm -rf pancake-cnb_*
./scripts/package.sh
pack build phpapp --path integration/fixtures/phpapp \
  --buildpack pancake-cnb_* \
  --buildpack https://github.com/cloudfoundry/php-cnb/releases/download/v0.0.3/php-cnb-0.0.3.tgz \
  --buildpack https://github.com/cloudfoundry/httpd-cnb/releases/download/v0.0.2/httpd-cnb-0.0.2.tgz \
  --buildpack https://github.com/cloudfoundry/php-web-cnb/releases/download/v0.0.4/php-web-cnb-0.0.4.tgz \
  --env VCAP_APPLICATION={} \
  --env "VCAP_SERVICES=$(cat integration/fixtures/vcap_services/two-services.json)"

This will create a new image phpapp, which can be run:

docker run -d \
    --env VCAP_APPLICATION={} \
    --env "VCAP_SERVICES=$(cat integration/fixtures/vcap_services/two-services.json)" \
    -p 8080:8080 \
    --env PORT=8080 \
    phpap

The sample PHP app, showing env vars, is now running at http://localhost:8080.

To see the generated env vars within the running Docker container we need to run /lifecycle/launcher bash after entering the container:

$ docker ps
$ docker exec -ti <name or id> bash
# /lifecycle/launcher bash

About

v3 Cloud Native Buildpack - Flatten $VCAP_SERVICES into individual environment variables

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published