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

Support cache_from directive in composefile 2.2+ #163

Merged
merged 1 commit into from Aug 12, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/shared.bash
Expand Up @@ -97,6 +97,14 @@ function build_image_override_file() {
"$(docker_compose_config_version)" "$@"
}

# Checks that a specific version of docker-compose supports cache_from
function docker_compose_supports_cache_from() {
local version="$1"
if [[ -z "$version" || "$version" == 1* || "$version" =~ ^(2|3)(\.[01])?$ ]] ; then
return 1
fi
}

# Build an docker-compose file that overrides the image for a specific
# docker-compose version and set of [ service, image, cache_from ] tuples
function build_image_override_file_with_version() {
Expand All @@ -118,9 +126,9 @@ function build_image_override_file_with_version() {
printf " image: %s\\n" "$2"

if [[ -n "$3" ]] ; then
if [[ -z "$version" || "$version" == 2* || "$version" == 3 || "$version" == 3.0* || "$version" == 3.1* ]]; then
if ! docker_compose_supports_cache_from "$version" ; then
echo "Unsupported Docker Compose config file version: $version"
echo "The 'cache_from' option can only be used with Compose file versions 3.2 and above."
echo "The 'cache_from' option can only be used with Compose file versions 2.2 or 3.2 and above."
echo "For more information on Docker Compose configuration file versions, see:"
echo "https://docs.docker.com/compose/compose-file/compose-versioning/#versioning"
exit 1
Expand Down
32 changes: 32 additions & 0 deletions tests/docker-compose-config.bats
Expand Up @@ -51,3 +51,35 @@ load '../lib/shared'
assert_success
assert_output "2.1"
}

@test "Whether docker-compose supports cache_from directive" {
run docker_compose_supports_cache_from ""
assert_failure

run docker_compose_supports_cache_from "1.0"
assert_failure

run docker_compose_supports_cache_from "2"
assert_failure

run docker_compose_supports_cache_from "2.1"
assert_failure

run docker_compose_supports_cache_from "2.2"
assert_success

run docker_compose_supports_cache_from "2.3"
assert_success

run docker_compose_supports_cache_from "3"
assert_failure

run docker_compose_supports_cache_from "3.1"
assert_failure

run docker_compose_supports_cache_from "3.2"
assert_success

run docker_compose_supports_cache_from "3.3"
assert_success
}