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'];
Need glue code
// platform_parameters.php
// Configure the database.
if (isset($_ENV['PLATFORM_RELATIONSHIPS'])) {
$dbRelationshipName = 'database';
$relationships = json_decode(base64_decode($_ENV['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 (isset($_ENV['PLATFORM_PROJECT_ENTROPY'])) {
$container->setParameter('kernel.secret', $_ENV['PLATFORM_PROJECT_ENTROPY']);
}
// Set the DATABASE_URL for Doctrine, if necessary.
if (!isset($_ENV['DATABASE_URL'])) {
if (isset($_ENV['PLATFORM_RELATIONSHIPS'])) {
$dbRelationshipName = 'database';
$relationships = json_decode(base64_decode($_ENV['PLATFORM_RELATIONSHIPS']),true);
foreach ($relationships[$dbRelationshipName] as $endpoint) {
if (!empty($endpoint['query']['is_master'])) {
$dbUrl = sprintf("%s://%s:%s@%s:%s/%s?charset=utf8mb4&serverVersion=10.2",
$endpoint['scheme'], $endpoint['username'], $endpoint['password'],
$endpoint['host'], $endpoint['port'],
$endpoint['path']);
break;
}
$_ENV['DATABASE_URL'] = $dbUrl;
}
}
else {
// Hack the Doctrine URL to be syntactically valid in a build hook, even
// though it shouldn't be used.
$dbUrl = sprintf("%s://%s:%s@%s:%s/%s?charset=utf8mb4&serverVersion=10.2",
'mysql', '', '', 'localhost', 3306, '');
$_ENV['DATABASE_URL'] = $dbUrl;
}
}
// Set the application secret if it's not already set.
if (!isset($_ENV['APP_SECRET']) && isset($_ENV['PLATFORM_PROJECT_ENTROPY'])) {
$_ENV['APP_SECRET'] = $_ENV['PLATFORM_PROJECT_ENTROPY'];
}
parameters:
app.connection.port: '%env(int:DATABASE_PORT)%'
parameters:
project_dir: '/foo/bar'
env(DB): 'sqlite://%%project_dir%%/var/data.db'
db_dsn: '%env(resolve:DB)%'
parameters:
env(SOME_VALUE): 'NWE3OWExYzg2NmVmZWY5Y2ExODAwZjk3MWQ2ODlmM2U='
app.some_value: '%env(base64:SOME_VALUE)%'
env(NUM_ITEMS): 'App\\Entity\\BlogPost::NUM_ITEMS'
app.num_items: '%env(constant:NUM_ITEMS)%'
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