From 746b9cb04fa5ef234b23cd1b53b325d8a8056d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 18 Sep 2019 11:56:27 +0200 Subject: [PATCH 1/2] Remove deprecated HostConfig parameter from `containerStart()` The HostConfig was removed with Docker Engine API v1.24 (Docker v1.12) and has been deprecated since at least Docker v1.6. Pass the HostConfig to `containerCreate()` instead. --- src/Client.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index 03db7a1..b3e2408 100644 --- a/src/Client.php +++ b/src/Client.php @@ -531,20 +531,18 @@ public function containerResize($container, $w, $h) * Start the container id * * @param string $container container ID - * @param array $config (optional) start config (see link) * @return PromiseInterface Promise * @link https://docs.docker.com/engine/api/v1.40/#operation/ContainerStart */ - public function containerStart($container, $config = array()) + public function containerStart($container) { - return $this->postJson( + return $this->browser->post( $this->uri->expand( '/containers/{container}/start', array( 'container' => $container ) - ), - $config + ) )->then(array($this->parser, 'expectEmpty')); } From 376715e8fcebf8e3447f8ae91fe33c2a6bb9ffca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Thu, 19 Sep 2019 15:39:16 +0200 Subject: [PATCH 2/2] Remove deprecated `containerCopy()` and `containerCopyStream()` methods Use `containerArchive()` and `containerArchiveStream()` instead. --- README.md | 6 +-- src/Client.php | 87 +------------------------------------------- tests/ClientTest.php | 18 --------- 3 files changed, 5 insertions(+), 106 deletions(-) diff --git a/README.md b/README.md index 0cd087e..5763cc0 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ The following API endpoints resolve with a string in the [TAR file format](https ```php $client->containerExport($container); -$client->containerCopy($container, $config); +$client->containerArchive($container, $path); ``` Keep in mind that this means the whole string has to be kept in memory. @@ -257,14 +257,14 @@ a [`Stream`](https://github.com/reactphp/stream) instance instead: ```php $stream = $client->containerExportStream($image); -$stream = $client->containerCopyStream($image, $config); +$stream = $client->containerArchiveStream($container, $path); ``` Accessing individual files in the TAR file format string or stream is out of scope for this library. Several libraries are available, one that is known to work is [clue/reactphp-tar](https://github.com/clue/reactphp-tar). -See also the [copy example](examples/copy.php) and the [export example](examples/export.php). +See also the [archive example](examples/archive.php) and the [export example](examples/export.php). #### JSON streaming diff --git a/src/Client.php b/src/Client.php index b3e2408..39c2418 100644 --- a/src/Client.php +++ b/src/Client.php @@ -712,89 +712,6 @@ public function containerRemove($container, $v = false, $force = false) )->then(array($this->parser, 'expectEmpty')); } - /** - * [deprecated] Copy files or folders of container id - * - * This resolves with a string in the TAR file format containing all files - * specified in the given $path. - * - * Keep in mind that this means the whole string has to be kept in memory. - * For bigger containers it's usually a better idea to use a streaming approach, - * see containerCopyStream() for more details. - * - * Accessing individual files in the TAR file format string is out of scope - * for this library. Several libraries are available, one that is known to - * work is clue/reactphp-tar (see links). - * - * @param string $container container ID - * @param string $resource path to file or directory to copy - * @return PromiseInterface Promise tar stream - * @link https://docs.docker.com/engine/api/v1.22/#copy-files-or-folders-from-a-container - * @link https://github.com/clue/reactphp-tar - * @deprecated 0.3.0 Deprecated in Docker Engine API v1.20 (Docker v1.8) and removed in Docker Engine API v1.24 (Docker v1.12), use `containerArchive()` instead - * @see self::containerArchive() - * @see self::containerCopyStream() - */ - public function containerCopy($container, $path) - { - return $this->postJson( - $this->uri->expand( - '/containers/{container}/copy', - array( - 'container' => $container - ) - ), - array( - 'Resource' => $path - ) - )->then(array($this->parser, 'expectPlain')); - } - - /** - * [Deprecated] Copy files or folders of container id - * - * This returns a stream in the TAR file format containing all files - * specified in the given $path. - * - * This works for (any number of) files of arbitrary sizes as only small chunks have to - * be kept in memory. - * - * Accessing individual files in the TAR file format stream is out of scope - * for this library. Several libraries are available, one that is known to - * work is clue/reactphp-tar (see links). - * - * The resulting stream is a well-behaving readable stream that will emit - * the normal stream events. - * - * @param string $container container ID - * @param string $path path to file or directory to copy - * @return ReadableStreamInterface tar stream - * @link https://docs.docker.com/engine/api/v1.22/#copy-files-or-folders-from-a-container - * @link https://github.com/clue/reactphp-tar - * @deprecated 0.3.0 Deprecated in Docker Engine API v1.20 (Docker v1.8) and removed in Docker Engine API v1.24 (Docker v1.12), use `containerArchiveStream()` instead - * @see self::containerArchiveStream() - * @see self::containerCopy() - */ - public function containerCopyStream($container, $path) - { - return $this->streamingParser->parsePlainStream( - $this->browser->withOptions(array('streaming' => true))->post( - $this->uri->expand( - '/containers/{container}/copy', - array( - 'container' => $container - ) - ), - array( - 'Content-Type' => 'application/json' - ), - $this->json(array( - 'Resource' => $path - )) - ) - ); - } - /** * Get a tar archive of a resource in the filesystem of container id. * @@ -814,7 +731,7 @@ public function containerCopyStream($container, $path) * @return PromiseInterface Promise tar stream * @link https://docs.docker.com/engine/api/v1.40/#operation/ContainerArchive * @link https://github.com/clue/reactphp-tar - * @since 0.3.0 Available as of Docker Engine API v1.20 (Docker v1.8), use deprecated `containerCopy()` on legacy versions + * @since 0.3.0 Available as of Docker Engine API v1.20 (Docker v1.8) * @see self::containerArchiveStream() */ public function containerArchive($container, $path) @@ -851,7 +768,7 @@ public function containerArchive($container, $path) * @return ReadableStreamInterface tar stream * @link https://docs.docker.com/engine/api/v1.40/#operation/ContainerArchive * @link https://github.com/clue/reactphp-tar - * @since 0.3.0 Available as of Docker Engine API v1.20 (Docker v1.8), use deprecated `containerCopyStream()` on legacy versions + * @since 0.3.0 Available as of Docker Engine API v1.20 (Docker v1.8) * @see self::containerArchive() */ public function containerArchiveStream($container, $path) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 01cc09a..4115c5b 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -417,24 +417,6 @@ public function testContainerResize() $this->expectPromiseResolveWith('', $this->client->containerResize(123, 800, 600)); } - public function testContainerCopy() - { - $data = 'tar stream'; - $this->expectRequestFlow('post', '/containers/123/copy', $this->createResponse($data), 'expectPlain'); - - $this->expectPromiseResolveWith($data, $this->client->containerCopy('123', 'file.txt')); - } - - public function testContainerCopyStream() - { - $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); - - $this->expectRequest('post', '/containers/123/copy', $this->createResponse('')); - $this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream)); - - $this->assertSame($stream, $this->client->containerCopyStream('123', 'file.txt')); - } - public function testContainerArchive() { $data = 'tar stream';