42 lines
1.7 KiB
JavaScript
42 lines
1.7 KiB
JavaScript
async function test() {
|
|
console.log('1. Getting Docker Hub auth token...');
|
|
const authRes = await fetch('https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/nginx:pull');
|
|
const { token } = await authRes.json();
|
|
console.log('Got token:', token.substring(0, 20) + '...');
|
|
|
|
console.log('2. Getting nginx:alpine manifest list...');
|
|
const manRes = await fetch('https://registry-1.docker.io/v2/library/nginx/manifests/alpine', {
|
|
headers: {
|
|
'Authorization': 'Bearer ' + token,
|
|
'Accept': 'application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.index.v1+json'
|
|
}
|
|
});
|
|
const manData = await manRes.json();
|
|
console.log('Media type:', manRes.headers.get('content-type'));
|
|
|
|
let amd64Digest;
|
|
if (manData.manifests) {
|
|
const amd64 = manData.manifests.find(m => m.platform?.architecture === 'amd64' && m.platform?.os === 'linux');
|
|
amd64Digest = amd64.digest;
|
|
console.log('Found linux/amd64 manifest digest:', amd64Digest);
|
|
} else {
|
|
amd64Digest = 'alpine';
|
|
}
|
|
|
|
console.log('3. Fetching linux/amd64 manifest...');
|
|
const archManRes = await fetch(`https://registry-1.docker.io/v2/library/nginx/manifests/${amd64Digest}`, {
|
|
headers: {
|
|
'Authorization': 'Bearer ' + token,
|
|
'Accept': 'application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json'
|
|
}
|
|
});
|
|
const archMan = await archManRes.json();
|
|
console.log('Config descriptor:', archMan.config);
|
|
console.log('Layers count:', archMan.layers.length);
|
|
for (const l of archMan.layers) {
|
|
console.log(' Layer:', l.digest, '| Size:', l.size);
|
|
}
|
|
}
|
|
|
|
test().catch(console.error);
|