Merge pull request #1887 from nextcloud/enh/490/multiarch-images

get multiarch repodigest
This commit is contained in:
Simon L 2023-02-01 23:38:58 +01:00 committed by GitHub
commit c4107d1098
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,29 +26,31 @@ 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' // 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 { try {
$authTokenRequest = $this->guzzleClient->request( $request = $this->guzzleClient->request(
'GET', 'GET',
'https://auth.docker.io/token?service=registry.docker.io&scope=repository:' . $name . ':pull' 'https://hub.docker.com/v2/repositories/' . $name . '/tags?page_size=128'
); );
$body = $authTokenRequest->getBody()->getContents(); $body = $request->getBody()->getContents();
$decodedBody = json_decode($body, true); $decodedBody = json_decode($body, true);
if(isset($decodedBody['token'])) {
$authToken = $decodedBody['token']; if (isset($decodedBody['results'])) {
$manifestRequest = $this->guzzleClient->request( $arch = php_uname('m') === 'x86_64' ? 'amd64' : 'arm64';
'GET', foreach($decodedBody['results'] as $values) {
'https://registry-1.docker.io/v2/'.$name.'/manifests/' . $tag, if (isset($values['name'])
[ && $values['name'] === $tag
'headers' => [ && isset($values['images'])
'Accept' => 'application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.index.v1+json', && is_array($values['images'])) {
'Authorization' => 'Bearer ' . $authToken, foreach ($values['images'] as $images) {
], if (isset($images['architecture'])
] && $images['architecture'] === $arch
); && isset($images['digest'])
$responseHeaders = $manifestRequest->getHeader('docker-content-digest'); && is_string($images['digest'])) {
if(count($responseHeaders) === 1) { $latestVersion = $images['digest'];
$latestVersion = $responseHeaders[0]; apcu_add($cacheKey, $latestVersion, 600);
apcu_add($cacheKey, $latestVersion, 600); return $latestVersion;
return $latestVersion; }
}
}
} }
} }