如何解决是否可以使用 Google CloudBuild 将映像推送到 AWS ECR?
以下代码段 (Node/Typescript) 利用 Google 的 CloudBuild API (v1) 构建容器并推送到 Google 的容器注册表 (GCR)。如果可能,让 CloudBuild 将映像推送到 AWS ECR 而不是 GCR 的正确方法是什么?
import { cloudbuild_v1 } from "googleapis";
[...]
const manifestLocation = `gs://${manifestFile.bucket}/${manifestFile.fullpath}`;
const buildDestination = `gcr.io/${GOOGLE_PROJECT_ID}/xxx:yyy`;
const result = await builds.create({
projectId: GOOGLE_PROJECT_ID,requestBody: {
steps: [
{
name: 'gcr.io/cloud-builders/gcs-fetcher',args: [
'--type=Manifest',`--location=${manifestLocation}`
]
},{
name: 'docker',args: ['build','-t',buildDestination,'.'],}
],images: [buildDestination]
}
})```
解决方法
是的,您可以通过设置自定义步骤来执行此操作。
为此,您可以使用 docker 映像执行构建并将其推送到 AWS ECR。
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build','-t','<AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/<IMAGE_NAME>','.' ]
Here 是关于如何使用 cludbuild 的指南,对您很有用。
基本上在您的用例中,您可以像这样将目的地的值更改为 AWS ECR URL:
import { cloudbuild_v1 } from "googleapis";
[...]
const manifestLocation = `gs://${manifestFile.bucket}/${manifestFile.fullpath}`;
const buildDestination = `<AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/<IMAGE_NAME>`;
const result = await builds.create({
projectId: GOOGLE_PROJECT_ID,requestBody: {
steps: [
{
name: 'gcr.io/cloud-builders/gcs-fetcher',args: [
'--type=Manifest',`--location=${manifestLocation}`
]
},{
name: 'docker',args: ['build',buildDestination,'.'],}
],images: [buildDestination]
}
})```
Answer
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。