将本地构建的Docker镜像推送到Digital Ocean容器注册表。

huangapple go评论112阅读模式
英文:

Push locally built docker images to Digital Ocean Container Registry

问题

以下是翻译好的代码:

  1. package main
  2. import (
  3. "context"
  4. docker "docker.io/go-docker"
  5. "docker.io/go-docker/api/types"
  6. "encoding/base64"
  7. "encoding/json"
  8. "fmt"
  9. )
  10. var client docker.Client
  11. func main() {
  12. ctx := context.Background()
  13. var token = <digital_ocean_access_token>
  14. var creds = types.AuthConfig{
  15. Username: token,
  16. Password: token,
  17. ServerAddress: "registry.digitalocean.com/<registry>",
  18. }
  19. _, err = client.ImagePush(ctx,
  20. "registry.digitalocean.com/<registry>/<repo>:<tag>",
  21. types.ImagePushOptions{
  22. RegistryAuth: registryAuth(creds),
  23. })
  24. fmt.Println("stream ::::::::::::::::::::> ", err)
  25. }
  26. func registryAuth(creds types.AuthConfig) string {
  27. b, err := json.Marshal(&creds)
  28. if err != nil {
  29. panic(err)
  30. }
  31. return base64.StdEncoding.EncodeToString(b)
  32. }

我的当前代码如上所示:
我能够成功登录到注册表,但在推送注册表时出现了一些问题。
main() 函数显示了以下错误信息:

  1. stream ::::::::::::::::::::> error during connect: Post "/images/registry.digitalocean.com/<registry>/<repo>/push?tag=<tag>": unsupported protocol scheme ""
英文:
  1. package main
  2. import (
  3. &quot;context&quot;
  4. docker &quot;docker.io/go-docker&quot;
  5. &quot;docker.io/go-docker/api/types&quot;
  6. &quot;encoding/base64&quot;
  7. &quot;encoding/json&quot;
  8. &quot;fmt&quot;
  9. )
  10. var client docker.Client
  11. func main() {
  12. ctx := context.Background()
  13. var token = &lt;digital_ocean_access_token&gt;
  14. var creds = types.AuthConfig{
  15. Username: token,
  16. Password: token,
  17. ServerAddress: &quot;registry.digitalocean.com/&lt;registry&gt;&quot;,
  18. }
  19. _, err = client.ImagePush(ctx,
  20. &quot;registry.digitalocean.com/&lt;registry&gt;/&lt;repo&gt;:&lt;tag&gt;&quot;,
  21. types.ImagePushOptions{
  22. RegistryAuth: registryAuth(creds),
  23. })
  24. fmt.Println(&quot;stream :::::::::::::::::::::&gt; &quot;, err)
  25. }
  26. func registryAuth(creds types.AuthConfig) string {
  27. b, err := json.Marshal(&amp;creds)
  28. if err != nil {
  29. panic(err)
  30. }
  31. return base64.StdEncoding.EncodeToString(b)
  32. }

My current code is as above:
I am able to login successfully in the registry, but I am doing something wrong while pushing the registry
the main() call shows me this :

  1. stream :::::::::::::::::::::&gt; error during connect: Post &quot;/images/registry.digitalocean.com/&lt;registry&gt;/&lt;repo&gt;/push?tag=&lt;tag&gt;&quot;: unsupported protocol scheme &quot;&quot;

答案1

得分: 1

你正在使用的go-docker库已经过时了,你应该将其替换为更新的库https://pkg.go.dev/github.com/docker/docker
这将解决你的unsupported scheme issue问题。

英文:

The go-docker library you are using is outdated and you should replace that with newer library https://pkg.go.dev/github.com/docker/docker.
This will solve your unsupported scheme issue issue.

huangapple
  • 本文由 发表于 2021年10月25日 18:40:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/69706610.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定