/** * Build an image with docker * * @param \Docker\Context\ContextInterface $context Context to build * @param string $name Name of the wanted image * @param callable $callback A callback to be called for having log of build * @param boolean $quiet Quiet build (doest not output commands during build) * @param boolean $cache Use docker cache * @param boolean $rm Remove intermediate container during build */ public function build(ContextInterface $context, $name, callable $callback = null, $quiet = false, $cache = true, $rm = false) { $content = is_resource($context->read()) ? new Stream($context->read()) : $context->read(); $response = $this->httpClient->post(['/build{?data*}', ['data' => ['q' => (int) $quiet, 't' => $name, 'nocache' => (int) (!$cache), 'rm' => (int) $rm]]], ['headers' => array('Content-Type' => 'application/tar'), 'body' => $content, 'stream' => true]); if (null === $callback) { $callback = function () { }; } $stream = $response->getBody(); if ($stream instanceof StreamCallbackInterface) { $stream->readWithCallback($callback); } else { $callback($stream->__toString(), null); } }
/** * Build an image with docker * * @param \Docker\Context\ContextInterface $context Context to build * @param string $name Name of the wanted image * @param callable $callback A callback to be called for having log of build * @param boolean $quiet Quiet build (doest not output commands during build) * @param boolean $cache Use docker cache * @param boolean $rm Remove intermediate container during build * @param boolean $wait Whether to wait for build to finish * * @return \GuzzleHttp\Message\ResponseInterface */ public function build(ContextInterface $context, $name, callable $callback = null, $quiet = false, $cache = true, $rm = false, $wait = true) { if (null === $callback) { $callback = function () { }; } $content = is_resource($context->read()) ? new Stream($context->read()) : $context->read(); return $this->httpClient->post(['/build{?data*}', ['data' => ['q' => (int) $quiet, 't' => $name, 'nocache' => (int) (!$cache), 'rm' => (int) $rm]]], ['headers' => array('Content-Type' => 'application/tar'), 'body' => $content, 'stream' => true, 'callback' => $callback, 'wait' => $wait]); }