Platform.sh
Presented by Larry Garfield (@Crell)
implements Huggable
These are separate questions...
Someone else's hard drive
Abstracting away physical infrastructure
Disposable application design
Your application is disposable.
Your data is not.
You don't get an in-between option
Cleanly separate "Dev provided" and "user provided" files
Does config come from the developer or the user?
Git or Database?
Decide
getenv('foo');
$_ENV['foo'];
$_ENV['foo']['bar'];
Only ever use getenv()
Need glue code
// platform_parameters.php
// Configure the database.
if (getenv('PLATFORM_RELATIONSHIPS')) {
$dbRelationshipName = 'database';
$relationships = json_decode(base64_decode(getenv('PLATFORM_RELATIONSHIPS')), true);
foreach ($relationships[$dbRelationshipName] as $endpoint) {
if (!empty($endpoint['query']['is_master'])) {
$container->setParameter('database_driver', 'pdo_'.$endpoint['scheme']);
$container->setParameter('database_host', $endpoint['host']);
$container->setParameter('database_port', $endpoint['port']);
$container->setParameter('database_name', $endpoint['path']);
$container->setParameter('database_user', $endpoint['username']);
$container->setParameter('database_password', $endpoint['password']);
$container->setParameter('database_path', '');
break;
}
}
}
// Set a default unique secret, based on a project-specific entropy value.
if (getenv('PLATFORM_PROJECT_ENTROPY')) {
$container->setParameter('kernel.secret', getenv('PLATFORM_PROJECT_ENTROPY'));
}
composer require platformsh/symfonyflex-bridge
mapPlatformShEnvironment();
function mapPlatformShEnvironment() : void
{
if (!getenv('PLATFORM_APPLICATION')) {
return;
}
$secret = getenv('APP_SECRET') ?: getenv('PLATFORM_PROJECT_ENTROPY') ?: null;
setEnvVar('APP_SECRET', $secret);
$appEnv = getenv('APP_ENV') ?: 'prod';
setEnvVar('APP_ENV', $appEnv);
if (!getenv('DATABASE_URL')) {
mapPlatformShDatabase();
}
}
// ...
composer require platformsh/laravel-bridge
mapPlatformShEnvironment();
function mapPlatformShEnvironment() : void
{
if (!getenv('PLATFORM_APPLICATION')) {
return;
}
mapAppUrl();
$secret = getenv('APP_KEY') ?: getenv('PLATFORM_PROJECT_ENTROPY') ?: null;
setEnvVar('APP_KEY', $secret);
$secure_cookie = getenv('SESSION_SECURE_COOKIE') ?: 1;
setEnvVar('SESSION_SECURE_COOKIE', $secure_cookie);
if (getenv('PLATFORM_RELATIONSHIPS')) {
$relationships = json_decode(base64_decode(getenv('PLATFORM_RELATIONSHIPS'), true), true);
mapPlatformShDatabase('database', $relationships);
mapPlatformShRedisCache('rediscache', $relationships);
mapPlatformShRedisSession('redissession', $relationships);
}
}
// ...
composer.json
{
"autoload": {
"files": ["extra-bridge.php"]
}
}
Only works if your app reads env vars...
Use DotEnv
(PHP has several... because PHP)
Request::setTrustedHosts()
Constants?
Dependency inject your environment
Cloud
Always be able to
take your business elsewhere.
Use Free Software
Use replaceable services
Source: WordStream (2015)
Remember what they say when you assume
Director of Developer Experience Platform.sh
Continuous Deployment Cloud Hosting
Stalk us at @PlatformSH