Skip to content

Instantly share code, notes, and snippets.

@akovalyov
Last active August 29, 2015 14:21
Show Gist options
  • Save akovalyov/ff2cff0ff1899d18f1ee to your computer and use it in GitHub Desktop.
Save akovalyov/ff2cff0ff1899d18f1ee to your computer and use it in GitHub Desktop.
Symfony2 console with docker
#!/usr/bin/env php
<?php
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
set_time_limit(0);
const DOCKER_CONTAINER_NAME = 'app_phpfpm_1';
require_once __DIR__ . '/bootstrap.php.cache';
require_once __DIR__ . '/AppKernel.php';
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
$input = new ArgvInput();
if (null !== shell_exec('which docker') && true === (Boolean)shell_exec(sprintf('docker inspect -f {{.State.Running}} %s', DOCKER_CONTAINER_NAME))) {
echo "\033[01;33m Docker container found. Launching the command inside one \033[0m" . PHP_EOL;
echo shell_exec(sprintf('docker exec -i -t %s php app/console %s 2>&1', DOCKER_CONTAINER_NAME, $input->__toString()));
return;
}
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment