/** * @param string $command * * @return bool Did the command succeed? */ protected function testCommand($command) { try { $this->processRunner->run($command); } catch (ProcessFailedException $e) { return false; } return true; }
/** * {@inheritdoc} */ public function findByName($name) { $rawOutput = $this->processRunner->run('docker-compose ps -q ' . $name)->getOutput(); $ids = $this->parseOutput($rawOutput); if (count($ids) == 0) { throw new \RuntimeException(sprintf('No container named "%s" found', $name)); } return current($ids); }
/** * {@inheritdoc} */ public function run() { if ($this->processRunner->run($this->getVersionCommand(), false)->isSuccessful()) { $this->userInteraction->write(sprintf('"%s" is already installed', $this->getName())); } else { $this->userInteraction->write(sprintf('Installing "%s"', $this->getName())); $this->processRunner->run($this->getInstallCommand()); $this->userInteraction->write(sprintf('"%s" successfully installed', $this->getName())); } }
private function changeDinghyDnsResolverNamespace() { $process = new Process('dinghy version'); $this->processRunner->run($process); $dinghyVersionOutput = $process->getOutput(); $dinghyVersion = substr(trim($dinghyVersionOutput), strlen('Dinghy ')); $dnsMasqConfiguration = '/usr/local/Cellar/dinghy/' . $dinghyVersion . '/cli/dinghy/dnsmasq.rb'; $process = new Process('sed -i \'\' \'s/docker/zzz-dinghy/\' ' . $dnsMasqConfiguration); $this->processRunner->run($process); }
/** * {@inheritdoc} */ public function run() { $this->userInteraction->writeTitle("Pulling image aacebedo/dnsdock"); $this->userInteraction->write("Check docker machine is running"); if (!$this->machine->isRunning()) { $this->userInteraction->write("Starting machine"); $this->machine->start(); } $this->userInteraction->write("Setting environment variables"); $this->processRunner->run($this->machine->getEnvironmentDeclaration()); $this->userInteraction->write("Pulling image aacebedo/dnsdock, this could take a while when run for the first time"); $this->processRunner->run('docker pull aacebedo/dnsdock:latest-amd64'); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('service') !== null) { $service = $input->getOption('service'); } else { try { $service = $this->config->getCurrentService(); } catch (NotWithinServiceException $e) { $service = $this->askForTheService($input, $output); } } $command = implode(' ', $input->getArgument('service_command')); $this->processRunner->run("docker-compose run {$service} {$command}"); }
/** * {@inheritdoc} */ public function create() { try { $this->processRunner->run('docker-machine create --driver virtualbox ' . $this->name); } catch (ProcessFailedException $e) { throw new MachineException($e->getMessage(), $e->getCode(), $e); } }
/** * @param $package */ protected function installHomebrewPackage($package) { // Check if the package is known if (!$this->hasHomebrewPackage($package)) { $this->userInteraction->write(sprintf('Package "%s" not found, tapping default PHP brews', $package)); $this->processRunner->run('brew tap homebrew/dupes'); $this->processRunner->run('brew tap homebrew/versions'); $this->processRunner->run('brew tap homebrew/homebrew-php'); } $this->processRunner->run('brew install ' . $package); }
private function getDockerComposePath(ProcessRunner $processRunner) { $output = $processRunner->run(new Process('which docker-compose'))->getOutput(); return trim($output); }
/** * Resolve the network interface name for the given IP. * * @param string $machineIp * * @return string */ private function resolveNetworkInterface($machineIp) { $process = $this->processRunner->run('ifconfig `route get ' . $machineIp . ' | grep "interface: " | sed "s/[^:]*: \\(.*\\)/\\1/"` | head -n 1 | sed "s/\\([^:]*\\): .*/\\1/"'); $interface = $process->getOutput(); return trim($interface); }
private function hasDockerOptions() { return $this->processRunner->run('grep "^DOCKER_OPTS" /etc/default/docker', false)->isSuccessful(); }
/** * @param string $targetPath * @param string $fileContents */ private function writeAsRoot($targetPath, $fileContents) { $temporaryFile = tempnam(sys_get_temp_dir(), 'hostFile'); file_put_contents($temporaryFile, $fileContents); $this->processRunner->run(sprintf('sudo cp %s %s', $temporaryFile, $targetPath)); }
private function configureHostMachineResolution() { $this->processRunner->run('sudo mkdir -p /etc/resolver'); $this->processRunner->run('echo "nameserver 172.17.42.1" | sudo tee /etc/resolver/docker'); }
/** * @param ProcessRunner $processRunner * @param string $package * * @return bool */ private function hasHomebrewPackage(ProcessRunner $processRunner, $package) { return $processRunner->run(new Process('brew install --dry-run ' . $package), false)->isSuccessful(); }
private function isCurrentUserInDockerGroup() { return $this->processRunner->run('groups | grep docker', false)->isSuccessful(); }
/** * {@inheritdoc} */ public function has(EnvironmentVariable $environmentVariable) { $process = $this->processRunner->run(new Process('grep DOCKER_HOST ' . $this->file), false); $result = $process->getOutput(); return !empty($result); }
/** * Get boot2docker version. * * @throws ProcessFailedException * @return string */ public function getVersion() { $process = $this->processRunner->run(new Process('boot2docker version')); return $process->getOutput(); }
/** * @return bool */ public function isRunning() { $process = $this->processRunner->run(new Process('dinghy status')); $output = $process->getOutput(); return strpos($output, 'VM: running') !== false; }
private function isUsingDnsDockDnsServer() { return $this->processRunner->run('grep "' . DnsDock::IP . '" /etc/resolv.conf', false)->isSuccessful(); }
/** * {@inheritdoc} */ public function build(Project $project, array $containers = []) { $composePath = $this->composeExecutableFinder->find(); $this->processRunner->run(implode(' ', [$composePath, 'build', implode(' ', $containers)])); $this->reset($project, $containers); }