Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #3
0
 /**
  * Create new mysqldump command
  *
  * @param null|string $database Database name
  *
  * @return RemoteCommandBuilder
  */
 protected function createLocalMySqlDumpCommand($database = null)
 {
     $command = new RemoteCommandBuilder('mysqldump');
     // Add username
     if (DatabaseConnection::getDbUsername()) {
         $command->addArgumentTemplate('-u%s', DatabaseConnection::getDbUsername());
     }
     // Add password
     if (DatabaseConnection::getDbPassword()) {
         $command->addArgumentTemplate('-p%s', DatabaseConnection::getDbPassword());
     }
     // Add hostname
     if (DatabaseConnection::getDbHostname()) {
         $command->addArgumentTemplate('-h%s', DatabaseConnection::getDbHostname());
     }
     // Add hostname
     if (DatabaseConnection::getDbPort()) {
         $command->addArgumentTemplate('-P%s', DatabaseConnection::getDbPort());
     }
     // Add custom options
     if ($this->contextConfig->exists('mysql.mysqldump.option')) {
         $command->addArgumentRaw($this->contextConfig->get('mysql.mysqldump.option'));
     }
     if ($database !== null) {
         $command->addArgument($database);
     }
     // Transfer compression
     switch ($this->contextConfig->get('mysql.compression')) {
         case 'bzip2':
             // Add pipe compressor (bzip2 compressed transfer via ssh)
             $command->addPipeCommand(new CommandBuilder('bzip2', '--compress --stdout'));
             break;
         case 'gzip':
             // Add pipe compressor (gzip compressed transfer via ssh)
             $command->addPipeCommand(new CommandBuilder('gzip', '--stdout'));
             break;
     }
     return $command;
 }