From aa344fc94f0535b4f4879a9537c10da034b8c8cc Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Mon, 29 Nov 2021 13:16:19 +0200 Subject: [PATCH] wip: login to docker to avoid rate limiting --- .envrc.sample | 2 ++ pkg/client/registry.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/.envrc.sample b/.envrc.sample index fd5b5dea..4b1c26f6 100644 --- a/.envrc.sample +++ b/.envrc.sample @@ -4,3 +4,5 @@ go env -w GOPRIVATE=coopcloud.tech # export HCLOUD_TOKEN=$(pass show logins/hetzner/cicd/api_key) # export CAPSUL_TOKEN=... # export GITEA_TOKEN=... +# export DOCKER_USERNAME=... +# export DOCKER_PASSWORD=... diff --git a/pkg/client/registry.go b/pkg/client/registry.go index eac7ab11..8d27c66f 100644 --- a/pkg/client/registry.go +++ b/pkg/client/registry.go @@ -1,15 +1,20 @@ package client import ( + "context" "encoding/json" "fmt" "io/ioutil" "net/http" "strings" + "os" "coopcloud.tech/abra/pkg/web" "github.com/docker/distribution/reference" "github.com/hashicorp/go-retryablehttp" + dockerClient "github.com/docker/docker/client" + "github.com/docker/docker/api/types" + "github.com/sirupsen/logrus" ) type RawTag struct { @@ -84,6 +89,20 @@ func GetTagDigest(image reference.Named) (string, error) { return "", err } + dClient := dockerClient.Client{} + + username, username_ok := os.LookupEnv("DOCKER_USERNAME") + password, password_ok := os.LookupEnv("DOCKER_PASSWORD") + if username_ok && password_ok { + logrus.Debugf("docker login: %s, %s", username, password) + dClient.RegistryLogin(context.Background(), types.AuthConfig{ + Username: username, + Password: password, + ServerAddress: "docker.io", + }) + return "", nil + } + token, err := getRegv2Token(image) if err != nil { return "", err