Exemplo n.º 1
0
 public function testProjectName()
 {
     $this->assertEquals('phpunit', Platform::projectName());
     // Change values
     file_put_contents(Platform::rootDir() . '/' . Config::PLATFORM_CONFIG, '');
     Config::reset();
     $this->assertNull(Platform::projectName());
 }
Exemplo n.º 2
0
 /**
  * Builds the settings.local.php file.
  */
 public function __construct()
 {
     $this->projectName = Platform::projectName();
     $this->containerName = Compose::getContainerName(Platform::projectName(), 'mariadb');
     $this->string = "<?php\n\n";
     $this->setSalt();
     $this->dbFromLocal();
     $this->dbFromDocker();
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $process = Docker::inspect(['--format="{{ .State.Running }}"', 'nginx-proxy'], true);
     $url = 'http://' . Platform::projectName() . '.platform';
     if (trim($process->getOutput()) != 'true') {
         $port = Docker::getContainerPort(Compose::getContainerName(Platform::projectName(), 'nginx'), 80);
         $url .= ':' . $port;
     }
     $this->openUrl($url);
 }
 public function testAddExtras()
 {
     $config = new ComposeContainers(Platform::rootDir(), Platform::projectName());
     $config->addRedis();
     $config_converted = Yaml::parse($config->yaml());
     $this->assertCount(4, $config_converted);
     $config->addSolr();
     $config_converted = Yaml::parse($config->yaml());
     $this->assertCount(5, $config_converted);
 }
Exemplo n.º 5
0
    public function dbFromLocal()
    {
        $hostname = Compose::getContainerName(Platform::projectName(), 'mariadb');
        $name = Platform::projectName();
        $this->string .= <<<EOT
if (empty(\$_SERVER['PLATFORM_DOCKER'])) {
    \$cmd = "docker inspect --format='{{(index (index .NetworkSettings.Ports \\"3306/tcp\\") 0).HostPort}}' {$hostname}";
    \$port = trim(shell_exec(\$cmd));
    define('DB_HOST', "{$name}.platform:\$port");
}
EOT;
    }
Exemplo n.º 6
0
 public function copyConfigs()
 {
     // Copy configs
     foreach ($this->configsToCopy() as $fileName) {
         $this->fs->copy($this->resourcesDir . '/conf/' . $fileName, $this->projectPath . '/docker/conf/' . $fileName);
     }
     // Quick fix to make nginx PHP_IDE_CONFIG dynamic for now.
     $nginxConfFile = $this->projectPath . '/docker/conf/nginx.conf';
     $nginxConf = file_get_contents($nginxConfFile);
     $nginxConf = str_replace('{{ platform }}', Platform::projectName() . '.platform', $nginxConf);
     file_put_contents($nginxConfFile, $nginxConf);
     // stub in for Solr configs
     $finder = new Finder();
     $finder->in($this->resourcesDir . '/conf/solr')->files()->depth('< 1')->name('*');
     /** @var \SplFileInfo $file */
     foreach ($finder as $file) {
         $this->fs->copy($file->getPathname(), $this->projectPath . '/docker/conf/solr/' . $file->getFilename());
     }
 }
Exemplo n.º 7
0
    /**
     * Builds the settings.local.php file.
     */
    public function __construct()
    {
        $this->projectName = Platform::projectName();
        $this->containerName = Compose::getContainerName(Platform::projectName(), 'mariadb');
        /** @var DrupalStackHelper $drupalStack */
        $drupalStack = Toolstack::getStackByType('drupal');
        $this->version = $drupalStack->version(Platform::webDir());
        $this->string = "<?php\n\n";
        $this->setSalt();
        $this->dbFromLocal();
        $this->dbFromDocker();
        if ($this->version == DrupalStackHelper::DRUPAL8) {
            $this->string .= <<<EOT
// Configuration directories.
\$config_directories = array(
  CONFIG_ACTIVE_DIRECTORY => '../../../shared/config/active',
  CONFIG_STAGING_DIRECTORY => '../../../shared/config/staging',
);
EOT;
        }
    }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $containerName = null;
     $type = $input->getArgument('service');
     switch ($type) {
         case 'http':
             $containerName = Compose::getContainerName(Platform::projectName(), 'nginx');
             break;
         case 'php':
             $containerName = Compose::getContainerName(Platform::projectName(), 'phpfpm');
             break;
         case 'db':
             $containerName = Compose::getContainerName(Platform::projectName(), 'mariadb');
             break;
         case 'redis':
             $containerName = Compose::getContainerName(Platform::projectName(), 'redis');
             break;
         case 'solr':
             $containerName = Compose::getContainerName(Platform::projectName(), 'solr');
             break;
         default:
             $this->stdOut->writeln("<error>Invalid service type</error>");
             break;
     }
     $builder = ProcessBuilder::create(['docker', 'exec', '-it', $containerName, 'bash']);
     $process = $builder->getProcess();
     // Need to set tty true, ProccessHelper doesn't allow this setting.
     $process->setTty(true);
     try {
         $process->mustRun(null);
     } catch (ProcessFailedException $e) {
         $message = "The command failed with the exit code: " . $process->getExitCode();
         $message .= "\n\nFull command: " . $process->getCommandLine();
         throw new \Exception($message);
     }
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $processBuilder = ProcessBuilder::create(['drush', $input->getArgument('cmd'), '--root=' . Platform::webDir(), '--uri=' . Platform::projectName() . '.' . Platform::projectTld()]);
     passthru($processBuilder->getProcess()->getCommandLine());
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $port = Docker::getContainerPort(Compose::getContainerName(Platform::projectName(), 'nginx'), 80);
     $url = 'http://' . Platform::projectName() . '.platform:' . trim($port);
     $this->openUrl($url);
 }