Skip to content

Commit

Permalink
Merge pull request #250 from john681611/cache-failover
Browse files Browse the repository at this point in the history
Allow Build to continue if cache pull fails
  • Loading branch information
vito authored Jan 12, 2019
2 parents 2be5a4d + 85f3fdb commit fb024bb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
4 changes: 2 additions & 2 deletions assets/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -206,5 +206,5 @@ docker_pull() {
done

printf "\n${RED}Failed to pull image %s.${NC}" "$1"
exit 1
return 1
}
5 changes: 3 additions & 2 deletions assets/out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/bin/docker
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 34 additions & 1 deletion tests/out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,39 @@ 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": "broken-repo",
},
"params": map[string]interface{}{
"build": "/docker-image-resource/tests/fixtures/build",
"cache": "true",
},
})

Expect(session.Err).ToNot(gbytes.Say(dockerarg(`--cache-from`)))
Expect(session.Err).To(gbytes.Say(dockerarg(`broken-repo:latest`)))
Expect(session.Err).To(gbytes.Say(dockerarg(`build`)))

})
});

Context("when cache_from images are specified", func() {
BeforeEach(func() {
os.Mkdir("/tmp/cache_from_1", os.ModeDir)
Expand All @@ -564,7 +597,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"},
Expand Down

0 comments on commit fb024bb

Please sign in to comment.