From 1fb73d94ca28aeb804f89b1070d1cb36932c0300 Mon Sep 17 00:00:00 2001 From: john681611 Date: Fri, 7 Dec 2018 12:38:44 +0000 Subject: [PATCH 1/3] added ability for the cahce pull it fail and not break build Signed-off-by: john681611 --- assets/out | 2 +- tests/out_test.go | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/assets/out b/assets/out index 83b761fc..ef13c3ea 100755 --- a/assets/out +++ b/assets/out @@ -147,7 +147,7 @@ elif [ -n "$build" ]; then cache_from_args=() if [ "$cache" = "true" ]; then - docker_pull "${repository}:${cache_tag}" + docker_pull "${repository}:${cache_tag}" && cache_from_args+=("--cache-from ${repository}:${cache_tag}") fi diff --git a/tests/out_test.go b/tests/out_test.go index aa140d8c..4ef8bfb3 100644 --- a/tests/out_test.go +++ b/tests/out_test.go @@ -539,6 +539,38 @@ var _ = Describe("Out", func() { }) }) + Context("when cache is specified are specified", func() { + It("adds argument to cache_from", func() { + session := put(map[string]interface{}{ + "source": map[string]interface{}{ + "repository": "test", + }, + "params": map[string]interface{}{ + "build": "/docker-image-resource/tests/fixtures/build", + "cache": "true", + }, + }) + + Expect(session.Err).To(gbytes.Say(dockerarg(`--cache-from`))) + Expect(session.Err).To(gbytes.Say(dockerarg(`test:latest`))) + }) + + It("does not add cache_from if pull fails", func() { + session := put(map[string]interface{}{ + "source": map[string]interface{}{ + "repository": "test", + }, + "params": map[string]interface{}{ + "build": "/docker-image-resource/tests/fixtures/broken", + "cache": "true", + }, + }) + + Expect(session.Err).ToNot(gbytes.Say(dockerarg(`--cache-from`))) + Expect(session.Err).ToNot(gbytes.Say(dockerarg(`test:latest`))) + }) + }); + Context("when cache_from images are specified", func() { BeforeEach(func() { os.Mkdir("/tmp/cache_from_1", os.ModeDir) @@ -564,7 +596,7 @@ var _ = Describe("Out", func() { session := put(map[string]interface{}{ "source": map[string]interface{}{ "repository": "test", - }, + }, "params": map[string]interface{}{ "build": "/docker-image-resource/tests/fixtures/build", "cache_from": []string{"cache_from_1", "cache_from_2"}, From c738b40be072f860493b0b09325fc0c25f01334f Mon Sep 17 00:00:00 2001 From: john681611 Date: Fri, 11 Jan 2019 16:19:16 +0000 Subject: [PATCH 2/3] improve implementation. Signed-off-by: john681611 --- assets/out | 5 +++-- tests/fixtures/bin/docker | 4 ++++ tests/out_test.go | 9 +++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/assets/out b/assets/out index ef13c3ea..d4c0278a 100755 --- a/assets/out +++ b/assets/out @@ -147,8 +147,9 @@ elif [ -n "$build" ]; then cache_from_args=() if [ "$cache" = "true" ]; then - docker_pull "${repository}:${cache_tag}" && - cache_from_args+=("--cache-from ${repository}:${cache_tag}") + if docker_pull "${repository}:${cache_tag}"; then + cache_from_args+=("--cache-from ${repository}:${cache_tag}") + fi fi if [ -n "$cache_from" ]; then diff --git a/tests/fixtures/bin/docker b/tests/fixtures/bin/docker index 8e53c9a3..db02bd3f 100755 --- a/tests/fixtures/bin/docker +++ b/tests/fixtures/bin/docker @@ -14,3 +14,7 @@ fi if [ "$1" == "info" ] && [ -f /tmp/docker_failing ]; then exit 1 fi + +if [ "$1" == "pull" ] && [ "$2" == "broken-repo:latest" ]; then + exit 1 +fi diff --git a/tests/out_test.go b/tests/out_test.go index 4ef8bfb3..9346cb65 100644 --- a/tests/out_test.go +++ b/tests/out_test.go @@ -550,7 +550,6 @@ var _ = Describe("Out", func() { "cache": "true", }, }) - Expect(session.Err).To(gbytes.Say(dockerarg(`--cache-from`))) Expect(session.Err).To(gbytes.Say(dockerarg(`test:latest`))) }) @@ -558,16 +557,18 @@ var _ = Describe("Out", func() { It("does not add cache_from if pull fails", func() { session := put(map[string]interface{}{ "source": map[string]interface{}{ - "repository": "test", + "repository": "broken-repo", }, "params": map[string]interface{}{ - "build": "/docker-image-resource/tests/fixtures/broken", + "build": "/docker-image-resource/tests/fixtures/build", "cache": "true", }, }) Expect(session.Err).ToNot(gbytes.Say(dockerarg(`--cache-from`))) - Expect(session.Err).ToNot(gbytes.Say(dockerarg(`test:latest`))) + Expect(session.Err).ToNot(gbytes.Say(dockerarg(`broken-repo:latest`))) + Expect(session.Err).To(gbytes.Say(dockerarg(`build`))) + }) }); From 85f3fdb5b2169859cc0c947f433b3320091856d6 Mon Sep 17 00:00:00 2001 From: john681611 Date: Fri, 11 Jan 2019 17:07:42 +0000 Subject: [PATCH 3/3] fix exiting issue Signed-off-by: john681611 --- assets/common.sh | 4 ++-- tests/out_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/common.sh b/assets/common.sh index 5e6b1851..c866b37c 100644 --- a/assets/common.sh +++ b/assets/common.sh @@ -197,7 +197,7 @@ docker_pull() { if docker pull "$1"; then printf "\nSuccessfully pulled ${GREEN}%s${NC}.\n\n" "$1" - return + return 0 fi echo @@ -206,5 +206,5 @@ docker_pull() { done printf "\n${RED}Failed to pull image %s.${NC}" "$1" - exit 1 + return 1 } diff --git a/tests/out_test.go b/tests/out_test.go index 9346cb65..ebe9045c 100644 --- a/tests/out_test.go +++ b/tests/out_test.go @@ -566,7 +566,7 @@ var _ = Describe("Out", func() { }) Expect(session.Err).ToNot(gbytes.Say(dockerarg(`--cache-from`))) - Expect(session.Err).ToNot(gbytes.Say(dockerarg(`broken-repo:latest`))) + Expect(session.Err).To(gbytes.Say(dockerarg(`broken-repo:latest`))) Expect(session.Err).To(gbytes.Say(dockerarg(`build`))) })