Are VCAP_APP_PORT, PORT, and VCAP_APP_HOST not set before bin/compile triggers?

229 views
Skip to first unread message

tony.m...@gmail.com

unread,
Sep 4, 2014, 9:22:23 PM9/4/14
to vcap...@cloudfoundry.org
Hi folks,

I'm creating a custom buildpack, but find VCAP_APP_PORT, PORT, and VCAP_APP_HOST environment variables are null during the bin/compile script execution - is this correct or just a bug in my BOSH-Lite v178 release?

Thanks.

Tao Deng

unread,
Sep 4, 2014, 10:13:38 PM9/4/14
to vcap...@cloudfoundry.org
VCAP_APP_PORT, PORT, VCAP_APP_HOST  are configured when starting app instance. Can you give more details why to use those environment variables in compilation phase?

Thanks, 

- Tao



--
You received this message because you are subscribed to the Google Groups "Cloud Foundry Developers" group.
To view this discussion on the web visit https://groups.google.com/a/cloudfoundry.org/d/msgid/vcap-dev/55604409-9fa8-433e-b579-dce7dbc4c174%40cloudfoundry.org.

To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

Tony McGuckin

unread,
Sep 5, 2014, 2:47:44 AM9/5/14
to vcap...@cloudfoundry.org, td...@pivotal.io
Thanks Tao,

Before I start a binary within the buildpack, I need to write the port, ip host values into a configuration file that the binary depends on.  If this is not possible in the compilation phase, can I still write into this configuration file in the release script before returning the release YAML, or should I be using a 'before_start' hook script?

Tony

Tao Deng

unread,
Sep 5, 2014, 3:39:59 AM9/5/14
to vcap...@cloudfoundry.org, Tony McGuckin
Since those environment variables are assigned at runtime, instead of writing them into configuration file(then reading from), it will be good to read environment variables in your app/buildpack directly. 

Thanks, 
- Tao

Daniel Mikusa

unread,
Sep 5, 2014, 10:00:16 AM9/5/14
to vcap...@cloudfoundry.org
On Fri, Sep 5, 2014 at 2:47 AM, Tony McGuckin <tony.m...@gmail.com> wrote:
Thanks Tao,

Before I start a binary within the buildpack, I need to write the port, ip host values into a configuration file that the binary depends on.  If this is not possible in the compilation phase, can I still write into this configuration file in the release script before returning the release YAML, or should I be using a 'before_start' hook script?

If possible, configure the application that you're starting to look directly at the environment variables.  If that's not possible (perhaps the application doesn't support it), you can modify the application's configuration before you start the application in the runtime environment.  For example, if you start your application with the command "app_ctl start" and you list this in the output from release, you can list "process-my-config-script && app_ctl start" in the output from release instead.

What I like to do is to put place holders in the configuration and then use a script to process the configuration and replace the place holders at runtime.  I use a custom script, but some people like to use erb.  Those are just examples though, you can use whatever you like.

Dan

 

Tony



On Friday, 5 September 2014 03:13:38 UTC+1, Tao Deng wrote:
VCAP_APP_PORT, PORT, VCAP_APP_HOST  are configured when starting app instance. Can you give more details why to use those environment variables in compilation phase?

Thanks, 

- Tao



On Fri, Sep 5, 2014 at 10:22 AM, <tony.m...@gmail.com> wrote:
Hi folks,

I'm creating a custom buildpack, but find VCAP_APP_PORT, PORT, and VCAP_APP_HOST environment variables are null during the bin/compile script execution - is this correct or just a bug in my BOSH-Lite v178 release?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Cloud Foundry Developers" group.
To view this discussion on the web visit https://groups.google.com/a/cloudfoundry.org/d/msgid/vcap-dev/55604409-9fa8-433e-b579-dce7dbc4c174%40cloudfoundry.org.

To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

--
You received this message because you are subscribed to the Google Groups "Cloud Foundry Developers" group.

Ben Hale

unread,
Sep 17, 2014, 3:35:32 AM9/17/14
to vcap...@cloudfoundry.org, dmi...@pivotal.io
Tony,

Sorry I'm so late to the party, but conferences have a tendency to get in the way.  The way to think about this is that staging only happens once, in a different environment, than your application will run in.  So if you run multiple instances of your application, the values for  $VCAP_APP_PORT, $PORT, and $VCAP_APP_HOST will vary between each instance.  Because they vary (3 instances will have 3 different $PORT values) there is no correct value to write out at staging time.  As Tao and Daniel mention there are a number of ways to pass those values into an application, but the preferred way is to reference the environment variable directly.  The Java Buildpack does this typically by setting a container-specifc system property or environment variable that references $PORT.  While it's not universal, most frameworks allow configuration via environment variable; in fact Java is one of the most environment variable-hostile ecosystems out there, and I don't believe that we've yet found a framework that doesn't allow this.


-Ben Hale
Cloud Foundry Java Experience
Reply all
Reply to author
Forward
0 new messages