Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function prepareJob(Job $job)
 {
     $origin = $job->getParameters()['origin'];
     $target = $this->buildPath . DIRECTORY_SEPARATOR . $job->getDirectory();
     $build = $job->getParameters()['build'];
     // First mirroring target
     $this->filesystem->mirror($origin, $target, null, array('delete' => true, 'override' => true));
     // Second override target with build dir
     $this->filesystem->mirror($build, $target, null, array('delete' => false, 'override' => true));
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function prepareJob(Job $job)
 {
     $parameters = $job->getParameters();
     $origin = $parameters['origin'];
     $target = $this->buildPath . DIRECTORY_SEPARATOR . $job->getDirectory();
     // First mirroring target
     $this->filesystem->mirror($origin, $target, null, array('delete' => true, 'override' => true));
     // Create dockerfile
     $this->builder->setTemplateName(sprintf("%s/Dockerfile-%s.twig", $parameters['language'], $parameters['version']));
     $this->builder->setVariables($parameters);
     $this->builder->setOutputName('Dockerfile');
     $this->builder->writeOnDisk($target);
 }
Пример #3
0
 /**
  * Stop services for a Job and reinit volumes
  *
  * @param Job $build
  * @param int $timeout
  *
  * @throws \Docker\Exception\UnexpectedStatusCodeException
  */
 public function stop(Job $build, $timeout = 10)
 {
     foreach ($build->getServices() as $service) {
         if ($service->getContainer()) {
             try {
                 $this->docker->getContainerManager()->stop($service->getContainer(), $timeout);
             } catch (UnexpectedStatusCodeException $e) {
                 if ($e->getCode() != "304") {
                     throw $e;
                 }
             }
             $this->docker->getContainerManager()->remove($service->getContainer(), true);
         }
     }
 }
Пример #4
0
 /**
  * Stop services for a Job and reinit volumes
  *
  * @param Job $job     The job to stop services
  * @param int $timeout Timeout to wait before killing the service
  */
 public function stop(Job $job, $timeout = 10)
 {
     foreach ($job->getServices() as $service) {
         if ($service->getContainer()) {
             try {
                 $this->docker->getContainerManager()->stop($service->getContainer(), ['t' => $timeout]);
             } catch (ClientErrorException $e) {
                 if ($e->getResponse()->getStatusCode() != 304) {
                     throw $e;
                 }
             }
             $this->docker->getContainerManager()->remove($service->getContainer(), ['v' => true, 'force' => true]);
             $service->setContainer(null);
         }
     }
 }
Пример #5
0
 /**
  * Run a build (it's suppose the image exist in docker
  *
  * @param Job $job Build to run
  * @param string|array $command Command to use when run the build (null, by default, will use the command registered to the image)
  *
  * @return integer The exit code of the command run inside (0 = success, otherwise it has failed)
  */
 public function run(Job $job, $command)
 {
     if (is_string($command)) {
         $command = ['/bin/bash', '-c', $command];
     }
     $image = $this->docker->getImageManager()->find($job->getName());
     $hostConfig = new HostConfig();
     $config = new ContainerConfig();
     $config->setCmd($command);
     $config->setImage($image->getId());
     $config->setHostConfig($hostConfig);
     $config->setLabels(new \ArrayObject(['com.jolici.container=true']));
     $config->setAttachStderr(true);
     $config->setAttachStdout(true);
     $links = [];
     foreach ($job->getServices() as $service) {
         if ($service->getContainer()) {
             $serviceContainer = $this->docker->getContainerManager()->find($service->getContainer());
             $links[] = sprintf('%s:%s', $serviceContainer->getName(), $service->getName());
         }
     }
     $hostConfig->setLinks($links);
     $containerCreateResult = $this->docker->getContainerManager()->create($config);
     $attachStream = $this->docker->getContainerManager()->attach($containerCreateResult->getId(), ['stream' => true, 'stdout' => true, 'stderr' => true], ContainerManager::FETCH_STREAM);
     $attachStream->onStdout($this->logger->getRunStdoutCallback());
     $attachStream->onStderr($this->logger->getRunStderrCallback());
     $this->docker->getContainerManager()->start($containerCreateResult->getId());
     $attachStream->wait();
     $containerWait = $this->docker->getContainerManager()->wait($containerCreateResult->getId());
     return $containerWait->getStatusCode();
 }
Пример #6
0
 /**
  * Run a build (it's suppose the image exist in docker
  *
  * @param Job $build Build to run
  * @param string|array $command Command to use when run the build (null, by default, will use the command registered to the image)
  *
  * @return integer The exit code of the command run inside (0 = success, otherwise it has failed)
  */
 public function run(Job $build, $command = null)
 {
     $image = $this->docker->getImageManager()->find($build->getRepository(), $build->getTag());
     $config = array('HostConfig' => array('Links' => array()));
     foreach ($build->getServices() as $service) {
         if ($service->getContainer()) {
             $config['HostConfig']['Links'][] = sprintf('%s:%s', $service->getContainer()->getRuntimeInformations()['Name'], $service->getName());
         }
     }
     $container = new DockerContainer($config);
     if (is_string($command)) {
         $command = array('/bin/bash', '-c', $command);
     }
     if (is_array($command)) {
         $container->setCmd($command);
     }
     $container->setImage($image);
     $this->docker->getContainerManager()->run($container, $this->logger->getRunCallback(), array(), false, $this->timeout);
     return $container->getExitCode();
 }