Skip to content

Conversation

@mexitek
Copy link

@mexitek mexitek commented Jan 10, 2013

VCAP_SERVICES environment variable is essential to continuous integration and deployment strategies. af tunnel command is extremely useful for local development. It allows for our code to be versioned locally and for our dev db to be kept in appfog for syncing purposes.

The only key missing is allowing our app to grab database credentials from VCAP_SERVICES environment variable locally. CLI tools can not write environment variables for all user on any given machine. Environment variables created by af command line tool will only be available to af and not our app. This pull request writes the VCAP_SERVICES data to a file locally, allowing our app to look for it IF the environment variable does not exist.

PHP Example

# Check for AppFogs ENV variable
if( getenv("VCAP_SERVICES") ) {
    $json = getenv("VCAP_SERVICES");
} 
# Check for local file, placed by: af tunnel
else if( file_exists("/etc/af_vcap_services") ) {
    $json = file_get_contents("/etc/af_vcap_services");
} 
# No DB credentials
else {
    throw new Exception("No Database Information Available.", 1);
}

# Decode JSON and gather DB Info
$services_json = json_decode($json,true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"];

This works for me, not sure if it might work for others. Might need some adjusting.

non-sudo
sudo

@scbenjamin
Copy link

Great addition, +1 for this, would be extremely helpful with local development.

@malthejorgensen
Copy link

I actually did almost exactly this in my own setup, so +1 from here.
Not sure I wanna place it in /etc though – I placed it in the project folder – but somewhere is definitely better than nowhere!

@paulopatto
Copy link

Great 👍 🆙

@drummerboof
Copy link

Is there any movement on this? It would be really handy.

@mexitek
Copy link
Author

mexitek commented Mar 26, 2014

Not sure AF took the changes. But this issue has the appropriate changes on
it. You can take in those changes locally.

On Tuesday, March 25, 2014, drummerboof [email protected] wrote:

Is there any movement on this - it would be really handy.

Reply to this email directly or view it on GitHubhttps://github.com//pull/26#issuecomment-38638831
.

Arlo Carreon http://arlocarreon.com
Web Developer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants