Ejemplo n.º 1
0
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $ret = 0;
     $paramList = $this->getFullParameterList();
     $container = $this->getApplication()->getConfigValue('docker', 'container');
     $cliMethod = $this->getApplication()->getConfigValue('docker', 'climethod');
     switch ($cliMethod) {
         ###########################
         # with Docker exec (faster, complex)
         ###########################
         case 'docker-exec':
             $cliScript = $this->getDockerEnv($container, 'CLI_SCRIPT');
             $cliUser = $this->getDockerEnv($container, 'CLI_USER');
             if (empty($cliScript)) {
                 $output->writeln('<p-error>Docker container "' . $container . '" doesn\'t have environment variable "CLI_SCRIPT"</p-error>');
                 return 1;
             }
             // Create remote cli command
             $command = new RemoteCommandBuilder();
             $command->parse($cliScript)->addArgumentList($paramList);
             if (!empty($cliUser)) {
                 // sudo wrapping as cli user
                 $commandSudo = new RemoteCommandBuilder('sudo', '-H -E -u %s', array($cliUser));
                 $commandSudo->append($command, false);
                 $command = $commandSudo;
             }
             $this->executeDockerExec($container, $command);
             break;
             ###########################
             # with docker-compose run (simple, slower, requires entrypoint modification)
             ###########################
         ###########################
         # with docker-compose run (simple, slower, requires entrypoint modification)
         ###########################
         case 'dockercompose-run':
             $command = new RemoteCommandBuilder('cli');
             $command->addArgumentList($paramList);
             $ret = $this->executeDockerComposeRun($container, $command);
             break;
         default:
             $output->writeln('<p-error>CliMethod "' . $cliMethod . '" not defined</p-error>');
             $ret = 1;
             break;
     }
     return $ret;
 }
Ejemplo n.º 2
0
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getApplication()->getConfigValue('docker', 'container');
     if ($input->getArgument('container')) {
         $container = $input->getArgument('container');
     }
     if ($input->getOption('user')) {
         // User user by option
         $cliUser = $input->getOption('user');
     } else {
         // Use docker env
         $cliUser = $this->getDockerEnv($container, 'CLI_USER');
     }
     $this->setTerminalTitle('docker', 'shell', $container);
     $command = new RemoteCommandBuilder('bash');
     if (!empty($cliUser)) {
         // sudo wrapping as cli user
         $commandSudo = new RemoteCommandBuilder('sudo', '-H -E -u %s', array($cliUser));
         $commandSudo->append($command, false);
         $command = $commandSudo;
     }
     $ret = $this->executeDockerExec($container, $command);
     return $ret;
 }