gpt4 book ai didi

node.js - 如何使用 HTTP API 从 gcr.io Docker Registry 列出图像和标签?

转载 作者:搜寻专家 更新时间:2023-10-31 22:38:08 24 4
gpt4 key购买 nike

我正在尝试从 Node.js 中的 Google Container Registry (gcr.io) 获取可用图像及其标签的列表。

我首先使用 google-auto-auth 获取范围为 https://www.googleapis.com/auth/devstorage.read_write 的 token ,我将该令​​牌交换为 gcr.io token ,如下所示:

axios.get('https://gcr.io/v2/token?service=gcr.io', {
auth: {
username: '_token',
password: token // token I got from `google-auto-auth`
}
})

然后我尝试使用它来调用 v2/_catalog 端点:

axios.get('https://gcr.io/v2/_catalog', {
headers: {
Authorization: `Bearer ${gcrToken}`
}
})

我收到以下错误:

{ 
errors: [ { code: 'DENIED', message: 'Failed to retrieve projects.' } ]
}

很公平,它必须需要我的项目 ID,但我应该在哪里提供它?

只是为了看看我能否让其他任何东西工作,我尝试了:

axios.get('https://gcr.io/v2/my-project-id/my-image/tags/list', {
headers: {
Authorization: `Bearer ${gcrToken}`
}
})

我得到以下回复:

{ 
errors: [
{
code: 'NAME_INVALID',
message: 'Requested repository does not match bearer token resource: my-project-id/my-image'
}
]
}

如何从 gcr.io 读取图像信息?

最佳答案

在与 GCR 的 Jon Johnson 进行了广泛的沟通后,我们终于找出了问题所在。如果您赞成这个答案,请也赞成 Jon 的答案,他竭尽全力解决了这个问题。

在撰写本文时,其中大部分内容尚未记录。

  • 需要使用 registry:catalog:*范围。
  • 我的图片被推送到us.gcr.io ,并且他们将它们视为单独的注册表——我认为它们是镜像。
  • 服务帐户必须有 Project Viewer在 Google Cloud IAM 中担任角色。
  • 您可以使用 GCR token 以及 Google Cloud token 。然而,虽然 GCR token 不能与 Basic base64(_token:<token>) 一起使用,谷歌云 token 可以。

获取 GCR token

// Updated host
axios.get('https://us.gcr.io/v2/token?service=gcr.io', {
params: {
service: 'us.gcr.io',
scope: `registry:catalog:*`
},
auth: {
username: '_token',
password: token // token I got from `google-auto-auth`
},
})

使用 token 列出存储库

const client = axios.create({
baseURL: `https://us.gcr.io/v2`,
headers: {
Authorization: `Bearer ${token}`
}
})

client.get('/_catalog').then((response) => {
console.log(response.data.repositories)
})

关于node.js - 如何使用 HTTP API 从 gcr.io Docker Registry 列出图像和标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44783736/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com