简体   繁体   English

如何使用Golang SDK将Docker映像推入AWS ECR

[英]How to push docker image into aws ecr using golang sdk

I am trying to write a tool to automatically push docker image into aws ECR. 我正在尝试编写一个工具来自动将docker映像推入AWS ECR中。

I am trying to push a docker image into aws ECR using aws golang sdk. 我正在尝试使用AWS Golang SDK将Docker映像推入AWS ECR。 was trying to follow this documentation https://docs.aws.amazon.com/sdk-for-go/api/service/ecr/#ECR.PutImage 试图遵循此文档https://docs.aws.amazon.com/sdk-for-go/api/service/ecr/#ECR.PutImage

but no clue how to make ImageManifest object https://docs.aws.amazon.com/sdk-for-go/api/service/ecr/#PutImageInput Help is very much appreciated. 但是不知道如何制作ImageManifest对象https://docs.aws.amazon.com/sdk-for-go/api/service/ecr/#PutImageInput帮助非常感谢。

The documentation clearly says: 该文档明确指出:

This operation is used by the Amazon ECR proxy, and it is not intended for general use by customers for pulling and pushing images. 此操作由Amazon ECR代理使用,并不供客户一般用于拉和推图像。 In most cases, you should use the docker CLI to pull, tag, and push images. 在大多数情况下,您应该使用docker CLI来拉取,标记和推送图像。

Instead doing that way I will recommend you to use exec Go package and implement the exec commands directly in your build machine. 取而代之的是,我建议您使用exec Go软件包并直接在构建计算机中实现exec命令。

You can do something like this: 您可以执行以下操作:

package main

import (
    "fmt"
    "os"
    "os/exec"
)

func main() {
    name := "docker"
    args := []string{"push", "registry/name:tag"}
    cmd := exec.Command(name, args...)
    if err := cmd.Run(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
    fmt.Println("done")
}

I took this example from the this blog https://nathanleclaire.com/blog/2014/12/29/shelled-out-commands-in-golang/ 我从这个博客https://nathanleclaire.com/blog/2014/12/29/shelled-out-commands-in-golang/

I hope you can have this info useful 希望您能获得有用的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM