Joli\JoliCi\Executor::run PHP Метод

run() публичный Метод

Run a build (it's suppose the image exist in docker
public run ( Joli\JoliCi\Job $job, string | array $command ) : integer
$job Joli\JoliCi\Job Build to run
$command string | array Command to use when run the build (null, by default, will use the command registered to the image)
Результат 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();
    }