Symfony and Docker gotcha #1
When mounting a Symfony 3 into a docker environment, make sure to not exclude the entire var folder in any way. Whether that’s through selective COPY / ADD commands, or the .dockerignore. Becuase if the {approot}/var folder is missing when running any composer command and composer then runs the post-cmd maintenance scripts, such as Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache or Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets, it will straight up spit out an error that says:
Could not open input file: app/console Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets handling the symfony-scripts event terminated with an exception [RuntimeException] An error occurred when executing the "'assets:install --symlink --relative '\''web'\'''" command: Could not open input file: app/console
On close inspection, you may miss that it’s attempting to call the console via app/console instead of bin/console. Why is this?
Because in those two particular maintenance scripts, they call a function that acquires the directory of the console.
$consoleDir = static::getConsoleDir($event, 'install assets');
Inside of getConsoleDir() it calls a function inside of a conditional that looks like this:
if (static::useNewDirectoryStructure($options)) {
This useNewDirectoryStructure() static call poses a very simple question, "does this app have a var folder?"
protected static function useNewDirectoryStructure(array $options) { return isset($options['symfony-var-dir']) && is_dir($options['symfony-var-dir']); }
And if the answer is no, as in the var folder is indeed missing, well, getConsoleDir() returns back the old Symfony2 "app" directory
protected static function getConsoleDir(Event $event, $actionName) { $options = static::getOptions($event); if (static::useNewDirectoryStructure($options)) { if (!static::hasDirectory($event, 'symfony-bin-dir', $options['symfony-bin-dir'], $actionName)) { return; } return $options['symfony-bin-dir']; } if (!static::hasDirectory($event, 'symfony-app-dir', $options['symfony-app-dir'], 'execute command')) { return; } // ALL ELSE FAILS, USE APP DIRECTORY LOL ~Kyle return $options['symfony-app-dir']; }
Sometimes, backwards compatibility can be a true nuisance. I wonder what this looks like for Symfony 4?













