/** * {@inheritdoc} */ public function run(InstallContext $context) { $processRunner = $context->getProcessRunner(); $userInteraction = $context->getUserInteraction(); $userInteraction->writeTitle('Configure routing for direct Docker containers access'); $dinghy = new DinghyCli($processRunner); $dinghyIp = $dinghy->getIp(); try { $process = new Process(sprintf('sudo route -n add 172.17.0.0/16 %s', $dinghyIp)); $processRunner->run($process); } catch (ProcessFailedException $e) { if (strpos($e->getProcess()->getErrorOutput(), 'File exists') !== false) { $userInteraction->writeTitle('Routing already configured'); } else { throw $e; } } // Add permanent routing if (!file_exists('/Library/LaunchDaemons/com.docker.route.plist')) { $source = __DIR__ . '/fixtures/com.docker.route.plist'; $dockerRouteFileContents = file_get_contents($source); $dockerRouteFileContents = str_replace('__DINGLY_IP__', $dinghyIp, $dockerRouteFileContents); $temporaryFile = tempnam(sys_get_temp_dir(), 'DockerInstaller'); file_put_contents($temporaryFile, $dockerRouteFileContents); $processRunner->run(new Process(sprintf('sudo cp %s /Library/LaunchDaemons/com.docker.route.plist', $temporaryFile))); $processRunner->run(new Process('sudo launchctl load /Library/LaunchDaemons/com.docker.route.plist')); } }
/** * {@inheritdoc} */ public function run(InstallContext $context) { $this->userInteraction = $context->getUserInteraction(); $this->processRunner = $context->getProcessRunner(); $boot2docker = new Boot2DockerCli($this->processRunner); if ($boot2docker->isInstalled()) { $this->userInteraction->writeTitle('Boot2Docker seems to be installed, removing it.'); if (!$boot2docker->uninstall()) { $this->userInteraction->writeTitle('Something went wrong while uninstalling Boot2Docker, continuing anyway.'); } else { $this->userInteraction->writeTitle('Successfully uninstalled boot2docker'); } } $dinghy = new DinghyCli($context->getProcessRunner()); if (!$dinghy->isInstalled()) { $this->userInteraction->writeTitle('Installing Dinghy'); $this->installDinghy(); $this->userInteraction->writeTitle('Successfully installed Dinghy'); } else { $this->userInteraction->writeTitle('Dinghy already installed, skipping.'); } $this->changeDinghyDnsResolverNamespace(); $this->userInteraction->writeTitle('Starting up Dinghy'); if (!$dinghy->isRunning()) { $dinghy->start(); $this->userInteraction->writeTitle('Started Dinghy'); } else { $this->userInteraction->writeTitle('Dinghy already started'); } if (!$this->haveDinghyEnvironmentVariables()) { $this->userInteraction->writeTitle('Setting up dinghy environment variables'); $this->setupDinghyEnvironmentVariables(); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $userInteraction = new ConsoleUserInteraction($input, $output); $processRunner = new InteractiveProcessRunner($userInteraction); $dingly = new DinghyCli($processRunner); if ($dingly->isRunning()) { $dingly->stop(); } $dingly->start(); }