是否可以使用 Google CloudBuild 将图像推送到 AWS ECR?

Is it possible to push an image to AWS ECR using Google CloudBuild?

以下代码段 (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', '-t', buildDestination, '.'],
            }
        ],
        images: [buildDestination]
    }
})```