From 714ecc9b2c29c4cdd352f60c58944047a2d561e0 Mon Sep 17 00:00:00 2001 From: Jake Oehler Morrison Date: Tue, 8 Sep 2015 13:27:42 -0700 Subject: [PATCH 1/6] with containerStats and containerLogs --- src/Client.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/Client.php b/src/Client.php index e0288b8..8a08316 100644 --- a/src/Client.php +++ b/src/Client.php @@ -516,6 +516,58 @@ public function containerCopyStream($container, $config) ); } + /** + * Retrieve container resource usage stats + * + * @param string $container container ID + * @param boolean $stream + * @return Promise Promise + * @link https://docs.docker.com/reference/api/docker_remote_api_v1.20/#get-container-stats-based-on-resource-usage + */ + public function containerStats($container, $stream = false) + { + return $this->browser->get( + $this->browser->resolve( + '/containers/{container}/stats{?stream}', + array( + 'container' => $container, + 'stream' => $stream ? 1 : 0 + ) + ) + )->then(array($this->parser, 'expectJson')); + } + + /** + * Retrieve container logs + * + * @param string $container container ID + * @param boolean $follow Return stream + * @param boolean $stdout Show stdout log. + * @param boolean $stderr Show stderr log. + * @param integer $since UNIX timestamp to filter logs. Specifying a timestamp will only output log-entries since that timestamp. + * @param boolean $timestamps Include timestamps + * @param integer $tail Output specified number of lines at the end of logs + * @return Promise Promise + * @link https://docs.docker.com/reference/api/docker_remote_api_v1.20/#get-container-logs + */ + public function containerLogs($container, $follow = false, $stdout = true, $stderr = true, $since = 0, $timestamps = false, $tail = 'all') + { + return $this->browser->get( + $this->browser->resolve( + '/containers/{container}/logs{?follow,stdout,stderr,since,timestamps,tail}', + array( + 'container' => $container, + 'follow' => $this->boolArg($follow), + 'stdout' => $this->boolArg($stdout), + 'stderr' => $this->boolArg($stderr), + 'since' => $since, + 'timestamps' => $this->boolArg($timestamps), + 'tail' => $tail, + ) + ) + )->then(array($this->parser, 'expectPlain')); + } + /** * List images * From 99f1d77fc9d78c6dc51f7fd1629447b65a0418c6 Mon Sep 17 00:00:00 2001 From: Jake Oehler Morrison Date: Tue, 8 Sep 2015 13:33:33 -0700 Subject: [PATCH 2/6] doc fixes --- src/Client.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Client.php b/src/Client.php index 8a08316..8a0a92b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -519,8 +519,8 @@ public function containerCopyStream($container, $config) /** * Retrieve container resource usage stats * - * @param string $container container ID - * @param boolean $stream + * @param string $container container ID + * @param boolean $stream return stream * @return Promise Promise * @link https://docs.docker.com/reference/api/docker_remote_api_v1.20/#get-container-stats-based-on-resource-usage */ @@ -541,12 +541,12 @@ public function containerStats($container, $stream = false) * Retrieve container logs * * @param string $container container ID - * @param boolean $follow Return stream - * @param boolean $stdout Show stdout log. - * @param boolean $stderr Show stderr log. + * @param boolean $follow return stream + * @param boolean $stdout show stdout log. + * @param boolean $stderr show stderr log. * @param integer $since UNIX timestamp to filter logs. Specifying a timestamp will only output log-entries since that timestamp. - * @param boolean $timestamps Include timestamps - * @param integer $tail Output specified number of lines at the end of logs + * @param boolean $timestamps include timestamps + * @param integer $tail output specified number of lines at the end of logs * @return Promise Promise * @link https://docs.docker.com/reference/api/docker_remote_api_v1.20/#get-container-logs */ @@ -567,7 +567,7 @@ public function containerLogs($container, $follow = false, $stdout = true, $stde ) )->then(array($this->parser, 'expectPlain')); } - + /** * List images * From 79be78e262e2763c44527b4409457d28f0deee74 Mon Sep 17 00:00:00 2001 From: Jake Oehler Morrison Date: Tue, 8 Sep 2015 13:34:24 -0700 Subject: [PATCH 3/6] removing extra comma --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 8a0a92b..356ecf0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -562,7 +562,7 @@ public function containerLogs($container, $follow = false, $stdout = true, $stde 'stderr' => $this->boolArg($stderr), 'since' => $since, 'timestamps' => $this->boolArg($timestamps), - 'tail' => $tail, + 'tail' => $tail ) ) )->then(array($this->parser, 'expectPlain')); From effc1cd38e7e35a5e968c8408863d18ee2ec1255 Mon Sep 17 00:00:00 2001 From: Jake Oehler Morrison Date: Wed, 9 Sep 2015 15:53:59 -0700 Subject: [PATCH 4/6] stats with big ints overflow --- src/Io/ResponseParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Io/ResponseParser.php b/src/Io/ResponseParser.php index 529ce2b..89d4351 100644 --- a/src/Io/ResponseParser.php +++ b/src/Io/ResponseParser.php @@ -17,7 +17,7 @@ public function expectJson(Response $response) { // application/json - return json_decode((string)$response->getBody(), true); + return json_decode((string)$response->getBody(), true, 512, JSON_BIGINT_AS_STRING); } public function expectEmpty(Response $response) From aeb8e0918d55e8086ca7384844bcb8b93d9c7f20 Mon Sep 17 00:00:00 2001 From: Jacob Morrison Date: Wed, 9 Sep 2015 16:43:21 -0700 Subject: [PATCH 5/6] still have to suppress errors --- src/Io/ResponseParser.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Io/ResponseParser.php b/src/Io/ResponseParser.php index 89d4351..d24a3c1 100644 --- a/src/Io/ResponseParser.php +++ b/src/Io/ResponseParser.php @@ -16,8 +16,7 @@ public function expectPlain(Response $response) public function expectJson(Response $response) { // application/json - - return json_decode((string)$response->getBody(), true, 512, JSON_BIGINT_AS_STRING); + return @json_decode((string)$response->getBody(), true, 512, JSON_BIGINT_AS_STRING); } public function expectEmpty(Response $response) From f596df1190cc84a76a00a761585e0760e707c09e Mon Sep 17 00:00:00 2001 From: Jake Oehler Morrison Date: Tue, 17 Nov 2015 15:58:44 -0800 Subject: [PATCH 6/6] Update composer.json --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 3f12402..40d5578 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ "keywords": ["Docker", "container", "ReactPHP", "async"], "homepage": "https://github.com/clue/php-docker-react", "license": "MIT", + "version": "0.2.1", "authors": [ { "name": "Christian Lück",