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

feat: no need to pull cache_from image #201

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
24 changes: 4 additions & 20 deletions src/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,12 @@ parse_tags_to_docker_arg() {
DOCKER_TAGS_ARG="$(eval echo $docker_arg)"
}

pull_images_from_cache() {
local cache
cache="$(eval echo $PARAM_CACHE_FROM)"

echo "$cache" | sed -n 1'p' | tr ',' '\n' | while read -r image; do
echo "Pulling ${image}";
docker pull ${image} || true
done
}

if ! parse_tags_to_docker_arg; then
echo "Unable to parse provided tags."
echo "Check your \"tag\" parameter or refer to the docs and try again: https://circleci.com/developer/orbs/orb/circleci/docker."
exit 1
fi

if [ -n "$PARAM_CACHE_FROM" ]; then
if ! pull_images_from_cache; then
echo "Unable to pull images from the cache."
echo "Check your \"cache_from\" parameter or refer to the docs and try again: https://circleci.com/developer/orbs/orb/circleci/docker."
exit 1
fi
fi

build_args=(
"--file=$PARAM_DOCKERFILE_PATH/$PARAM_DOCKERFILE_NAME"
)
Expand All @@ -62,15 +44,17 @@ if [ -n "$EXTRA_BUILD_ARGS" ]; then
fi

if [ -n "$PARAM_CACHE_FROM" ]; then
build_args+=("--cache-from=$PARAM_CACHE_FROM")
cache_from=$(eval echo $PARAM_CACHE_FROM)

build_args+=("--cache-from=$cache_from")
fi

if [ -n "$PARAM_CACHE_TO" ]; then
cache_to="$(eval echo $PARAM_CACHE_TO)"

docker buildx create --name cache --use
docker buildx use cache
build_args+=("--cache-to=$cache_to" --load)
build_args+=("--cache-to=$cache_to")
fi

# The context must be the last argument.
Expand Down