I'm trying to get my app hosted by platform.sh, my problem is that I use SncRedisBundle, with this config:
#config.yml
imports:
- { resource: platformSh/parameters_platform.php } #platform.sh cloud provider configuration's
snc_redis:
clients:
doctrine:
type: predis
alias: doctrine
dsn: "%redis_url%&database=4"
doctrine:
metadata_cache:
client: doctrine
entity_manager: default # the name of your entity_manager connection
document_manager: default # the name of your document_manager connection
result_cache:
client: doctrine
entity_manager: [default] # you may specify multiple entity_managers
query_cache:
client: doctrine
entity_manager: default
second_level_cache:
client: doctrine
entity_manager: default
#platformSh/parameters_platform.php
$relationships = getenv("PLATFORM_RELATIONSHIPS");
var_dump('$relationships : ', $relationships, @$_ENV['PLATFORM_RELATIONSHIPS']);
if (!$relationships) {
return;
}
$relationships = json_decode(base64_decode($relationships), true);
foreach ($relationships['database'] as $endpoint) {
if (empty($endpoint['query']['is_master'])) {
continue;
}
$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', '');
}
if (!empty($relationships['redis'])) {
$redisConstructedDsn = 'redis://'.$relationships['redis'][0]['host'].$relationships['redis'][0]['port'].'?password=';
$container->setParameter('redis_url', $redisConstructedDsn);
var_dump('$redisConstructedDsn : ', $redisConstructedDsn);
} else {
var_dump('$relationships :', $relationships);
}
# Store session into /tmp.
ini_set('session.save_path', '/tmp/sessions');
When I push to platform.sh, their build process include a call to composer update, which end like this:
Generating optimized autoload files > Incenteev\ParameterHandler\ScriptHandler::buildParameters > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
string(17) "$relationships : "
bool(false)
NULL[Predis\Connection\ConnectionException]
php_network_getaddresses: getaddrinfo failed: Name or service not known [tcp://localhost&database=4:6379].
I contacted their support team, which told me this:
Hi,
May I know if you're trying to get PLATFORM_RELATIONSHIPS during the build phase?
That's not available since the build is environment agnostic.
If you need to connect DB / Redis / other services, please do so in deploy phase (i.e. Deploy Hook).
edit : the support has answered to me that the problem lie on this composer.json section:
"scripts": {
"symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-install-cmd": [
"@symfony-scripts"
],
"post-update-cmd": [
"@symfony-scripts"
],
"compile": [
"app/console assetic:dump"
]
},
for example, the "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache"
but also the "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets"
are causing Symfony to clear the cache which is do too soon (during the build phase where platform.sh don't provide the env. necessary for the linked redis and MySQL to wok...)
I don't know how to correct this, platform.sh want me to alter the composer.json file, but I find it strange & dangerous. How would you do?