/** * {@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} */ 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) { $userInteraction = $context->getUserInteraction(); $userInteraction->writeTitle('Checking PHP SSH2 extension'); if (!$this->sshExtensionInstalled()) { $userInteraction->write('PHP SSH2 extension is required.'); $defaultPhpVersion = $this->guessSsh2PhpPackage(); $question = new Question(sprintf('Which homebrew package do you want to install (default "%s") ? ("n" for nothing)', $defaultPhpVersion), $defaultPhpVersion); $package = $userInteraction->ask($question); if ($package == 'n') { $userInteraction->write('Skipping PHP SSH2 extension installation, do it yourself.'); } else { $processRunner = $context->getProcessRunner(); // Check if the package is known if (!$this->hasHomebrewPackage($processRunner, $package)) { $userInteraction->write(sprintf('Package "%s" not found, tapping default PHP brews', $package)); $processRunner->run(new Process('brew tap homebrew/dupes')); $processRunner->run(new Process('brew tap homebrew/versions')); $processRunner->run(new Process('brew tap homebrew/homebrew-php')); } $processRunner->run(new Process('brew install ' . $package)); } $userInteraction->write('Please re-run this installation script to have enabled PHP-SSH2 extension'); exit(1); } }
/** * {@inheritdoc} */ public function run(InstallContext $context) { $processRunner = $context->getProcessRunner(); $userInteraction = $context->getUserInteraction(); $versionCommand = $this->getVersionCommand(); $versionProcess = new Process($versionCommand); $processRunner->run($versionProcess, false); if ($versionProcess->isSuccessful()) { $userInteraction->write(sprintf('"%s" is already installed', $this->getName())); } else { $installCommand = $this->getInstallCommand(); $installProcess = new Process($installCommand); $userInteraction->write(sprintf('Installing "%s"', $this->getName())); $processRunner->run($installProcess); $userInteraction->write(sprintf('"%s" successfully installed', $this->getName())); } }
/** * {@inheritdoc} */ public function run(InstallContext $context) { $userInteraction = $context->getUserInteraction(); $userInteraction->writeTitle('Configure DNS resolution for Docker containers'); // Configure virtual machine $sshClient = new SshClient(); $this->sshExec = $sshClient->getExec(); if (!$this->hasDockerExtraArgs()) { $this->sshExec->run('echo EXTRA_ARGS=\\"-H unix:///var/run/docker.sock --bip=172.17.42.1/16 --dns=172.17.42.1\\" | sudo tee -a /var/lib/boot2docker/profile'); } if (!$this->dnsDockerIsInStartupConfiguration()) { $bootScript = 'sleep 5' . PHP_EOL . 'docker start dnsdock || docker run -d -v /var/run/docker.sock:/var/run/docker.sock --name dnsdock -p 172.17.42.1:53:53/udp tonistiigi/dnsdock' . PHP_EOL; $this->sshExec->run('echo "' . $bootScript . '" | sudo tee -a /var/lib/boot2docker/bootlocal.sh'); } // Configure host machine resolution $processRunner = $context->getProcessRunner(); $processRunner->run(new Process('sudo mkdir -p /etc/resolver')); $processRunner->run(new Process('echo "nameserver 172.17.42.1" | sudo tee /etc/resolver/docker')); // Restart dinghy $userInteraction->writeTitle('Restarting Dinghy'); $processRunner->run(new Process('dinghy restart')); }