/** * Execute docker compose run * * @param string $containerName Container name * @param CommandBuilderInterface $command Command * * @return int|null|void */ protected function executeDockerComposeRun($containerName, CommandBuilderInterface $command) { // Search updir for docker-compose.yml $path = $this->getDockerPath(); if (!empty($path)) { // Switch to directory of docker-compose.yml PhpUtility::chdir($path); $this->output->writeln('<info>Executing "' . $command->getCommand() . '" in docker container "' . $containerName . '" ...</info>'); $dockerCommand = new CommandBuilder('docker-compose', 'run --rm %s', array($containerName)); $dockerCommand->append($command, false); $dockerCommand->executeInteractive(); } else { $this->output->writeln('<p-error>No docker-compose.yml found in tree</p-error>'); return 1; } return 0; }
/** * Elevate process (exec sudo with same parameters) * * @param InputInterface $input Input instance * @param OutputInterface $output Output instance * * @return int|null|void */ protected function elevateProcess(InputInterface $input, OutputInterface $output) { if (!$this->getApplication()->isRunningAsRoot()) { // Process is not running as root, trying to elevate to root $output->writeln('<comment>Elevating process using sudo...</comment>'); try { $commandMyself = new FullSelfCommandBuilder(); $commandSudo = new CommandBuilder('sudo'); $commandSudo->append($commandMyself, false); $commandSudo->executeInteractive(); } catch (\Exception $e) { // do not display exception here because it's a child process } throw new \CliTools\Exception\StopException(0); } else { // running as root } }