【问题标题】:Is it possible to push an image to AWS ECR using Google CloudBuild?是否可以使用 Google CloudBuild 将图像推送到 AWS ECR?
【发布时间】:2021-03-28 18:57:17
【问题描述】:

以下 sn-p (Node/Typescript) 利用 Google 的 CloudBuild API (v1) 构建容器并推送到 Google 的 Container Registry (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]
    }
})```

【问题讨论】:

  • 按照Pushing a Docker image中的步骤,看看你发现了什么问题。
  • 澄清一下,我希望使用 Google 的 CloudBuild 进程本身将映像推送到 AWS 注册表

标签: google-cloud-build amazon-ecr


【解决方案1】:

是的,您可以通过设置自定义步骤来执行此操作。

为此,您可以使用 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]
    }
})```


【讨论】:

    猜你喜欢
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 2020-02-13
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    相关资源
    最近更新 更多