From 7000d0e5090f305bbc56bd1397ceb61996107232 Mon Sep 17 00:00:00 2001 From: Ming Xu Date: Wed, 17 Apr 2019 16:28:58 +0800 Subject: [PATCH 1/2] Make sure check won't fail if image tag not exist on registry server. Signed-off-by: Ming Xu --- cmd/check/main.go | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/cmd/check/main.go b/cmd/check/main.go index 247dc39..def151f 100644 --- a/cmd/check/main.go +++ b/cmd/check/main.go @@ -62,11 +62,15 @@ func main() { return } + var missingTag bool digest, err := image.Digest() if err != nil { - logrus.Errorf("failed get image digest: %s", err) - os.Exit(1) - return + missingTag = checkMissingManifest(err) + if !missingTag { + logrus.Errorf("failed to get cursor image digest: %s", err) + os.Exit(1) + return + } } response := CheckResponse{} @@ -93,15 +97,7 @@ func main() { var missingDigest bool _, err = digestImage.Digest() if err != nil { - if rErr, ok := err.(*remote.Error); ok { - for _, e := range rErr.Errors { - if e.Code == remote.ManifestUnknownErrorCode { - missingDigest = true - break - } - } - } - + missingDigest = checkMissingManifest(err) if !missingDigest { logrus.Errorf("failed to get cursor image digest: %s", err) os.Exit(1) @@ -114,9 +110,24 @@ func main() { } } - response = append(response, resource.Version{ - Digest: digest.String(), - }) + if !missingTag { + response = append(response, resource.Version{ + Digest: digest.String(), + }) + } json.NewEncoder(os.Stdout).Encode(response) } + +func checkMissingManifest(err error) bool { + var missing bool + if rErr, ok := err.(*remote.Error); ok { + for _, e := range rErr.Errors { + if e.Code == remote.ManifestUnknownErrorCode { + missing = true + break + } + } + } + return missing +} From 1b442b2793913c01c5091b664e5219e428e6b0aa Mon Sep 17 00:00:00 2001 From: Ming Xu Date: Fri, 10 May 2019 11:24:03 +0800 Subject: [PATCH 2/2] Add test case for check not exist image. Signed-off-by: Ming Xu --- check_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/check_test.go b/check_test.go index c7a97f1..9be1ba8 100644 --- a/check_test.go +++ b/check_test.go @@ -210,4 +210,36 @@ var _ = Describe("Check", func() { }) }) }) + + Context("when invoked with not exist image", func() { + BeforeEach(func() { + req.Source = resource.Source{ + Repository: "concourse/test-image-static", + RawTag: "not-exist-image", + } + req.Version = nil + }) + + It("returns empty digest", func() { + Expect(res).To(Equal([]resource.Version{})) + }) + + Context("against a private repo with credentials", func() { + BeforeEach(func() { + req.Source = resource.Source{ + Repository: dockerPrivateRepo, + RawTag: "not-exist-image", + + Username: dockerPrivateUsername, + Password: dockerPrivatePassword, + } + + checkDockerPrivateUserConfigured() + }) + + It("returns empty digest", func() { + Expect(res).To(Equal([]resource.Version{})) + }) + }) + }) })