Example #1
0
 public function generate($pattern)
 {
     $url = $pattern;
     $url = str_replace('%color%', $this->randomElmt('colors'), $url);
     $url = str_replace('%animal%', $this->randomElmt('animals'), $url);
     $url = str_replace('%date%', date($this->config->get('[config][date_format]')), $url);
     return $url;
 }
 public function getDatabaseParams()
 {
     $dbParams = $this->config->get('[database]');
     if ($dbParams['driver'] == 'pdo_sqlite' && !isset($dbParams['path'])) {
         $dbParams['path'] = $this->config->get('[directories][data_dir]') . '/data.db';
     }
     return $dbParams;
 }
Example #3
0
 /**
  * @group config
  */
 public function testConfigGet()
 {
     $gruverFixture = __DIR__ . '/../Data/gruver-fixture.yml';
     $composeFixture = __DIR__ . '/../Data/docker-compose-fixture.yml';
     $sut = new GruverConfig($gruverFixture, $composeFixture);
     $this->assertEquals($_SERVER['PWD'], $sut->get('[application][directory]'));
     $this->assertEquals(array('*****@*****.**'), $sut->get('[config][email_notifications]'));
     $this->assertEquals(array('*****@*****.**'), $sut->get('[config][email_notifications]'));
 }
Example #4
0
 /**
  * @return ProcessVersion
  */
 public function getVersion()
 {
     $process = new Process($this->config->get('[binaries][docker_binary]') . ' --version');
     $process->run();
     $version = preg_match('/version ([0-9]+).([0-9]+).([0-9]+)/', trim($process->getOutput()), $matches);
     if ($version) {
         $major = $matches[1];
         $minor = $matches[2];
         $patch = $matches[3];
         return new ProcessVersion($major, $minor, $patch);
     }
 }
Example #5
0
 public function updateConfig()
 {
     $projectRepository = $this->em->getRepository('Mindgruve\\Gruver\\Entity\\Project');
     $serviceRepository = $this->em->getRepository('Mindgruve\\Gruver\\Entity\\Service');
     $services = array();
     $projects = $projectRepository->findAll();
     foreach ($projects as $project) {
         $projectServices = $serviceRepository->findAll($project);
         foreach ($projectServices as $projectService) {
             $services[] = $projectService;
         }
     }
     $liveServices = array();
     $stagingServices = array();
     $allServices = array();
     foreach ($services as $service) {
         $currentRelease = $service->getCurrentRelease();
         $releases = $service->getReleases();
         foreach ($releases as $release) {
             /**
              * @var \Mindgruve\Gruver\Entity\Release $release
              */
             $item = array('service_id' => $service->getId(), 'release_id' => $release->getId(), 'release_uuid' => $release->getUuid(), 'hosts' => $service->getPublicHosts(), 'haproxy_backend' => $service->getHAProxyBackend(), 'ip' => $release->getContainerIp(), 'port' => $release->getContainerPort(), 'status' => 'staging');
             if ($release == $currentRelease) {
                 $liveServices[] = $item;
             } else {
                 $stagingServices[] = $item;
             }
             $allServices[] = $item;
         }
     }
     $cfg = $this->twig->render('haproxy.cfg.twig', array('all_services' => $allServices, 'live_services' => $liveServices, 'staging_services' => $stagingServices));
     $haproxyConfigFile = $this->config->get('[config][haproxy_cfg]');
     if (!$haproxyConfigFile || !file_exists($haproxyConfigFile)) {
         throw new \Exception('HAProxy Config File Missing');
     }
     $fp = fopen($haproxyConfigFile, 'w');
     fwrite($fp, $cfg);
     /**
      * Execute Update Config
      * @todo put into container
      * @todo test before switching config
      * @doto backup config before switching
      */
     $haproxyReloadCmd = $this->config->get('[config][haproxy_reload]');
     if (!$haproxyReloadCmd) {
         throw new \Exception('Reload Command Missing.');
     }
     exec($haproxyReloadCmd);
 }
 /**
  * @param $serviceName
  * @param bool $detached
  *
  * @return string
  */
 public function getRunCommand($serviceName, $uuid, $detached = true, $servicePorts = true)
 {
     $releaseDir = $this->config->get('[directories][releases_dir]');
     $releaseFile = $releaseDir . $uuid . '.yml';
     if (!file_exists($releaseFile)) {
         $contents = $this->twig->render('docker-compose.yml.twig', array('project_name' => $this->env->getProjectName(), 'service_name' => $this->env->getServiceName(), 'release' => $this->env->getRelease(), 'uuid' => $uuid));
         file_put_contents($releaseFile, $contents);
         $this->files[] = $releaseFile;
     }
     $cmd = $this->config->get('[binaries][docker_compose_binary]');
     $cmd = $this->env->buildExport() . ' ' . $cmd;
     foreach ($this->files as $file) {
         $cmd .= ' -f ' . $file;
     }
     $cmd .= ' run';
     if ($detached) {
         $cmd = $cmd . ' -d';
     }
     if ($servicePorts) {
         $cmd = $cmd . ' --service-ports';
     }
     if ($serviceName) {
         $cmd = $cmd . ' ' . $serviceName;
     }
     return $cmd;
 }
Example #7
0
 public function __construct(GruverConfig $config, OutputInterface $output)
 {
     $this->defaultLogDirectory = $config->get('[directories][logging_dir]');
     $this->output = $output;
     $adapterConfigs = $config->get('[logging][adapters]');
     foreach ($adapterConfigs as $key => $loggingConfig) {
         if (isset($loggingConfig['type']) && $loggingConfig['type'] == 'stream' && !isset($loggingConfig['path'])) {
             $adapterConfigs[$key]['path'] = $config->get('[directories][logging_dir]') . '/' . $key . '.log';
         }
     }
     $logger = new Logger('default');
     foreach ($adapterConfigs as $adapterConfig) {
         $this->addAdapter($logger, $adapterConfig, $this->defaultLogDirectory . '/default.log');
     }
     $logger->pushHandler(new ConsoleOutputHandler($this->output));
     $this->logger = $logger;
 }
Example #8
0
 public function dispatchPostCleanup()
 {
     $shellCommands = $this->config->get('[events][post_cleanup]');
     if (!is_array($shellCommands)) {
         return;
     }
     foreach ($shellCommands as $shellCommand) {
         if ($shellCommand) {
             $this->runProcess($shellCommand);
         }
     }
 }