From 5a959e9b076c86292cd0231d26a3ce680d3563f9 Mon Sep 17 00:00:00 2001 From: Simon L Date: Thu, 2 Feb 2023 18:26:44 +0100 Subject: [PATCH] Revert "get multiarch repodigest" Signed-off-by: Simon L --- php/src/Docker/DockerHubManager.php | 42 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/php/src/Docker/DockerHubManager.php b/php/src/Docker/DockerHubManager.php index 7e022e2e..09612750 100644 --- a/php/src/Docker/DockerHubManager.php +++ b/php/src/Docker/DockerHubManager.php @@ -26,31 +26,29 @@ class DockerHubManager // If one of the links below should ever become outdated, we can still upgrade the mastercontainer via the webinterface manually by opening '/api/docker/getwatchtower' try { - $request = $this->guzzleClient->request( + $authTokenRequest = $this->guzzleClient->request( 'GET', - 'https://hub.docker.com/v2/repositories/' . $name . '/tags?page_size=128' + 'https://auth.docker.io/token?service=registry.docker.io&scope=repository:' . $name . ':pull' ); - $body = $request->getBody()->getContents(); + $body = $authTokenRequest->getBody()->getContents(); $decodedBody = json_decode($body, true); - - if (isset($decodedBody['results'])) { - $arch = php_uname('m') === 'x86_64' ? 'amd64' : 'arm64'; - foreach($decodedBody['results'] as $values) { - if (isset($values['name']) - && $values['name'] === $tag - && isset($values['images']) - && is_array($values['images'])) { - foreach ($values['images'] as $images) { - if (isset($images['architecture']) - && $images['architecture'] === $arch - && isset($images['digest']) - && is_string($images['digest'])) { - $latestVersion = $images['digest']; - apcu_add($cacheKey, $latestVersion, 600); - return $latestVersion; - } - } - } + if(isset($decodedBody['token'])) { + $authToken = $decodedBody['token']; + $manifestRequest = $this->guzzleClient->request( + 'GET', + 'https://registry-1.docker.io/v2/'.$name.'/manifests/' . $tag, + [ + 'headers' => [ + 'Accept' => 'application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.index.v1+json', + 'Authorization' => 'Bearer ' . $authToken, + ], + ] + ); + $responseHeaders = $manifestRequest->getHeader('docker-content-digest'); + if(count($responseHeaders) === 1) { + $latestVersion = $responseHeaders[0]; + apcu_add($cacheKey, $latestVersion, 600); + return $latestVersion; } }