Пример #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;
 }
Пример #2
0
 /**
  * Build complex task
  *
  * @param array $task Task configuration
  *
  * @return CommandBuilder|CommandBuilderInterface
  */
 protected function buildComplexTask(array $task)
 {
     if (empty($task['type'])) {
         $task['type'] = 'local';
     }
     if (empty($task['command'])) {
         throw new \RuntimeException('Task command is empty');
     }
     // Process task type
     switch ($task['type']) {
         case 'remote':
             // Remote command
             $command = new RemoteCommandBuilder();
             $command->parse($task['command']);
             $command = $this->wrapRemoteCommand($command);
             break;
         case 'local':
             // Local command
             $command = new CommandBuilder();
             $command->parse($task['command']);
             break;
         default:
             throw new \RuntimeException('Unknown task type');
             break;
     }
     return $command;
 }