Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Build to continue if cache pull fails #250

Merged
merged 3 commits into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
vito marked this conversation as resolved.
Show resolved Hide resolved
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