diff --git a/Makefile b/Makefile index ec1899c19..ca5048a36 100644 --- a/Makefile +++ b/Makefile @@ -126,7 +126,7 @@ offsets: | $(OFFSETGEN) .PHONY: docker-offsets docker-offsets: - docker run --rm -v /tmp:/tmp -v /var/run/docker.sock:/var/run/docker.sock -v $(shell pwd):/app golang:1.22 /bin/sh -c "cd ../app && make offsets" + docker run -e DOCKER_USERNAME=$(DOCKER_USERNAME) -e DOCKER_PASSWORD=$(DOCKER_PASSWORD) --rm -v /tmp:/tmp -v /var/run/docker.sock:/var/run/docker.sock -v $(shell pwd):/app golang:1.22 /bin/sh -c "cd ../app && make offsets" .PHONY: update-licenses update-licenses: generate $(GOLICENSES) diff --git a/internal/tools/inspect/builder.go b/internal/tools/inspect/builder.go index 6452c4e83..e836e2ca4 100644 --- a/internal/tools/inspect/builder.go +++ b/internal/tools/inspect/builder.go @@ -6,15 +6,19 @@ package inspect import ( "bytes" "context" + "encoding/base64" + "encoding/json" "fmt" "io" "log/slog" + "os" "path/filepath" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/mount" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/client" "github.com/docker/docker/pkg/stdcopy" "github.com/hashicorp/go-version" @@ -112,7 +116,23 @@ func (b *builder) pullImage(ctx context.Context) error { return nil } - rc, err := b.cli.ImagePull(ctx, b.GoImage, image.PullOptions{}) + pullOpts := image.PullOptions{} + username := os.Getenv("DOCKER_USERNAME") + password := os.Getenv("DOCKER_PASSWORD") + if len(username) > 0 && len(password) > 0 { + authConfig := registry.AuthConfig{ + Username: username, + Password: password, + } + encodedJSON, err := json.Marshal(authConfig) + if err != nil { + panic(err) + } + authStr := base64.URLEncoding.EncodeToString(encodedJSON) + pullOpts.RegistryAuth = authStr + } + + rc, err := b.cli.ImagePull(ctx, b.GoImage, pullOpts) if err != nil { return err }