Skip to content

Commit

Permalink
Merge pull request #332 from summittech-ca/summit/feature/buildkit
Browse files Browse the repository at this point in the history
Fix broken interaction of BUILDKIT and docker ecr_login plugin
  • Loading branch information
taylorsilva authored Apr 6, 2021
2 parents 6468b14 + 688f576 commit b15016d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion assets/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ log_in() {
echo "${password}" | docker login -u "${username}" --password-stdin ${registry}
else
mkdir -p ~/.docker
echo '{"credsStore":"ecr-login"}' >> ~/.docker/config.json
touch ~/.docker/config.json
# This ensures the resulting JSON object remains syntactically valid
echo "$(cat ~/.docker/config.json){\"credsStore\":\"ecr-login\"}" | jq -s add > ~/.docker/config.json
fi
}

Expand Down
9 changes: 6 additions & 3 deletions assets/out
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ max_concurrent_uploads=$(jq -r '.source.max_concurrent_uploads // 3' < $payload)
export AWS_ACCESS_KEY_ID=$(jq -r '.source.aws_access_key_id // ""' < $payload)
export AWS_SECRET_ACCESS_KEY=$(jq -r '.source.aws_secret_access_key // ""' < $payload)
export AWS_SESSION_TOKEN=$(jq -r '.source.aws_session_token // ""' < $payload)
export DOCKER_BUILDKIT=$(jq -r '.source.docker_buildkit // 0' < $payload)

if private_registry "${repository}" ; then
registry="$(extract_registry "${repository}")"
Expand Down Expand Up @@ -104,7 +103,7 @@ cache=$(jq -r '.params.cache' < $payload)
cache_tag=$(jq -r ".params.cache_tag // \"${tag_name}\"" < $payload)
cache_from=$(jq -r '.params.cache_from // empty' < $payload)
dockerfile=$(jq -r ".params.dockerfile // \"${build}/Dockerfile\"" < $payload)

export DOCKER_BUILDKIT=$(jq -r '.params.docker_buildkit // 0' < $payload)
load_file=$(jq -r '.params.load_file // ""' < $payload)
load_repository=$(jq -r '.params.load_repository // ""' < $payload)
load_tag=$(jq -r '.params.load_tag // "latest"' < $payload)
Expand Down Expand Up @@ -245,7 +244,11 @@ elif [ -n "$build" ]; then
done
fi

docker build -t "${repository}:${tag_name}" "${target[@]}" "${expanded_build_args[@]}" "${expanded_labels[@]}" -f "$dockerfile" $cache_from "$build"
# NOTE: deactivate amazon-ecr-credential-helper so that builds go through with the DOCKER_BUILDKIT set
cat <<< "$(jq 'del(.credsStore)' ~/.docker/config.json)" > ~/.docker/config.json
docker build -t "${repository}:${tag_name}" "${target[@]}" "${expanded_build_args[@]}" "${expanded_labels[@]}" "${ssh_args[@]}" -f "$dockerfile" $cache_from "$build"
log_in "$username" "$password" "$registry" # This restores the credsStore: ecr-login to config.json if needed

elif [ -n "$load_file" ]; then
if [ -n "$load_repository" ]; then
docker load -i "$load_file"
Expand Down

0 comments on commit b15016d

Please sign in to comment.