Skip to content

Commit

Permalink
Update go-containerregistry version (#1326)
Browse files Browse the repository at this point in the history
* Update go-containerregistry version

Newer version to support AR authentication; old version was not authenticating.

* Fix imports

Missing context

* Update gomega to recent version

* Fix missing HEAD handlers

These were added after the fork was made

* Incorporate check.go changes and in_test changes

Ref: concourse/registry-image-resource@e66e93e

* Use same context across AuthOptions

* Update context declaration

It needs to be initialized
  • Loading branch information
jjerger authored Jan 7, 2025
1 parent b266081 commit 238dde3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 96 deletions.
56 changes: 0 additions & 56 deletions container_images/registry-image-forked/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ var _ = Describe("Check", func() {

BeforeEach(func() {
registry.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand All @@ -129,10 +125,6 @@ var _ = Describe("Check", func() {
"Content-Length": LATEST_FAKE_HEADERS["Content-Length"],
}),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/fake-image/manifests/latest"),
ghttp.RespondWith(http.StatusOK, `{"fake":"manifest"}`, http.Header{
Expand Down Expand Up @@ -160,10 +152,6 @@ var _ = Describe("Check", func() {
registry = ghttp.NewTLSServer()

registry.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down Expand Up @@ -230,10 +218,6 @@ var _ = Describe("Check", func() {
registry = ghttp.NewServer()

registry.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down Expand Up @@ -264,10 +248,6 @@ var _ = Describe("Check", func() {
Context("which has the image", func() {
BeforeEach(func() {
mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand All @@ -293,10 +273,6 @@ var _ = Describe("Check", func() {
Context("which is missing the image", func() {
BeforeEach(func() {
mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down Expand Up @@ -404,10 +380,6 @@ var _ = Describe("Check", func() {
Context("which has the image", func() {
BeforeEach(func() {
mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down Expand Up @@ -438,10 +410,6 @@ var _ = Describe("Check", func() {
Context("which is missing the image", func() {
BeforeEach(func() {
mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down Expand Up @@ -544,10 +512,6 @@ var _ = Describe("Check", func() {
Context("which has the image", func() {
BeforeEach(func() {
mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand All @@ -556,10 +520,6 @@ var _ = Describe("Check", func() {
ghttp.VerifyRequest("HEAD", "/v2/library/fake-image/manifests/latest"),
ghttp.RespondWith(http.StatusOK, ``, LATEST_FAKE_HEADERS),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("HEAD", "/v2/library/fake-image/manifests/"+OLDER_FAKE_DIGEST),
ghttp.RespondWith(http.StatusOK, ``, OLDER_FAKE_HEADERS),
Expand All @@ -584,10 +544,6 @@ var _ = Describe("Check", func() {
Context("which is missing the image", func() {
BeforeEach(func() {
mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down Expand Up @@ -680,10 +636,6 @@ var _ = Describe("Check", func() {
Context("which has the image", func() {
BeforeEach(func() {
mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand All @@ -692,10 +644,6 @@ var _ = Describe("Check", func() {
ghttp.VerifyRequest("HEAD", "/v2/library/fake-image/manifests/latest"),
ghttp.RespondWith(http.StatusOK, ``, LATEST_FAKE_HEADERS),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("HEAD", "/v2/library/fake-image/manifests/"+req.Version.Digest),
ghttp.RespondWith(http.StatusNotFound, `{"errors":[{"code": "MANIFEST_UNKNOWN", "message": "ruh roh", "detail": "not here"}]}`),
Expand All @@ -717,10 +665,6 @@ var _ = Describe("Check", func() {
Context("which is missing the image", func() {
BeforeEach(func() {
mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down
7 changes: 7 additions & 0 deletions container_images/registry-image-forked/commands/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,20 @@ func headOrGet(ref name.Reference, imageOpts ...remote.Option) (v1.Hash, bool, e
if checkMissingManifest(err) {
return v1.Hash{}, false, nil
}
if (remoteDesc.Digest == v1.Hash{}) {
return v1.Hash{}, false, nil
}

return v1.Hash{}, false, err
}

return remoteDesc.Digest, true, nil
}

if (v1Desc.Digest == v1.Hash{}) {
return v1.Hash{}, false, nil
}

return v1Desc.Digest, true, nil
}

Expand Down
4 changes: 2 additions & 2 deletions container_images/registry-image-forked/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/concourse/go-archive v1.0.1
github.com/fatih/color v1.9.0
github.com/google/go-containerregistry v0.6.0
github.com/google/go-containerregistry v0.20.2
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.3
github.com/onsi/gomega v1.36.2
github.com/simonshyu/notary-gcr v0.0.0-20211109021545-380a129b0e83
github.com/sirupsen/logrus v1.8.1
github.com/vbauerster/mpb v3.4.0+incompatible
Expand Down
36 changes: 0 additions & 36 deletions container_images/registry-image-forked/in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,6 @@ var _ = Describe("In", func() {
),

// 429 following transport setup
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusTooManyRequests, "calm down"),
Expand All @@ -463,10 +459,6 @@ var _ = Describe("In", func() {
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/fake-image/manifests/"+digest.String()),
ghttp.RespondWith(http.StatusTooManyRequests, "calm down"),
Expand All @@ -477,10 +469,6 @@ var _ = Describe("In", func() {
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/fake-image/manifests/"+digest.String()),
ghttp.RespondWith(http.StatusOK, manifest),
Expand All @@ -495,10 +483,6 @@ var _ = Describe("In", func() {
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/fake-image/manifests/"+digest.String()),
ghttp.RespondWith(http.StatusOK, manifest),
Expand Down Expand Up @@ -549,10 +533,6 @@ var _ = Describe("In", func() {
Expect(err).ToNot(HaveOccurred())

registry.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down Expand Up @@ -635,10 +615,6 @@ var _ = Describe("In", func() {
Expect(err).ToNot(HaveOccurred())

registry.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down Expand Up @@ -717,10 +693,6 @@ var _ = Describe("In", func() {
Expect(err).ToNot(HaveOccurred())

mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down Expand Up @@ -784,10 +756,6 @@ var _ = Describe("In", func() {
req.Version.Digest = LATEST_STATIC_DIGEST

mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down Expand Up @@ -821,10 +789,6 @@ var _ = Describe("In", func() {
req.Version.Digest = latestDigest(req.Source.Repository)

mirror.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/"),
ghttp.RespondWith(http.StatusOK, `welcome to zombocom`),
Expand Down
17 changes: 17 additions & 0 deletions container_images/registry-image-forked/out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,15 @@ var _ = Describe("Out", func() {
})
}

registry.RouteToHandler("HEAD", "/v2/fake-image/manifests/some-tag", func(w http.ResponseWriter, r *http.Request) {
select {
case checkBlobRateLimits <- struct{}{}:
ghttp.RespondWith(http.StatusTooManyRequests, "check layer blob limited")(w, r)
default:
ghttp.RespondWith(http.StatusNotFound, "needs upload")(w, r)
}
})

registry.RouteToHandler("PUT", "/v2/fake-image/manifests/some-tag", func(w http.ResponseWriter, r *http.Request) {
select {
case updateManifestRateLimits <- struct{}{}:
Expand Down Expand Up @@ -531,6 +540,10 @@ var _ = Describe("Out", func() {
})
}

registry.RouteToHandler("HEAD", "/v2/fake-image/manifests/some-tag", func(w http.ResponseWriter, r *http.Request) {
ghttp.RespondWith(http.StatusNotFound, "needs upload")(w, r)
})

registry.RouteToHandler("PUT", "/v2/fake-image/manifests/some-tag", func(w http.ResponseWriter, r *http.Request) {
ghttp.RespondWith(http.StatusOK, "manifest updated")(w, r)
})
Expand Down Expand Up @@ -903,6 +916,10 @@ func (example SemverTagPushExample) Run() {
})

pushedTags := new(sync.Map)

registry.RouteToHandler("HEAD", regexp.MustCompile("/v2/test-image/manifests/.*"), func(w http.ResponseWriter, r *http.Request) {
ghttp.RespondWith(http.StatusNotFound, "needs upload")(w, r)
})
registry.RouteToHandler("PUT", regexp.MustCompile("/v2/test-image/manifests/.*"), func(w http.ResponseWriter, r *http.Request) {
tag := filepath.Base(r.URL.Path)

Expand Down
6 changes: 4 additions & 2 deletions container_images/registry-image-forked/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/base64"
Expand Down Expand Up @@ -152,6 +153,7 @@ func (source Source) Mirror() (Source, bool, error) {

// AuthOptions is
func (source Source) AuthOptions(repo name.Repository, scopeActions []string) ([]remote.Option, error) {
ctx := context.Background()
var auth authn.Authenticator
if source.Username != "" && source.Password != "" {
auth = &authn.Basic{
Expand All @@ -161,7 +163,7 @@ func (source Source) AuthOptions(repo name.Repository, scopeActions []string) ([
} else if source.Google {
logrus.Warnf("Forked registry image: will use Google default credentials")
var err error
if auth, err = google.NewEnvAuthenticator(); err != nil {
if auth, err = google.NewEnvAuthenticator(ctx); err != nil {
logrus.Errorf("failed to determine Google default credentials: %v.", err)
logrus.Warnf("Will use anonymous access.")
auth = authn.Anonymous
Expand Down Expand Up @@ -201,7 +203,7 @@ func (source Source) AuthOptions(repo name.Repository, scopeActions []string) ([
scopes[i] = repo.Scope(action)
}

rt, err := transport.New(repo.Registry, auth, tr, scopes)
rt, err := transport.NewWithContext(ctx, repo.Registry, auth, tr, scopes)
if err != nil {
return nil, fmt.Errorf("initialize transport: %w", err)
}
Expand Down

0 comments on commit 238dde3

Please sign in to comment.