Skip to content

Commit

Permalink
hack: turn docker-login resilient to bad json
Browse files Browse the repository at this point in the history
previously, we'd only guard against the case where the DOCKER_CONFIG
(usually ~/.docker/config.json) file is either not present or is
0-sized, but the best is to actually make sure that we have there is
good for appending an auth section to the registry we want to add
credentials for.

by optimistically performing a `jq '.'` we can move on to create an
empty `{}` (valid json) whether the file exists or not, as well as
whether the file contains a valid json or not.

Signed-off-by: Ciro S. Costa <ciroscosta@vmware.com>
  • Loading branch information
Ciro S. Costa committed Sep 22, 2021
1 parent 272f32b commit 35a2020
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hack/docker-login.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ update_or_create_docker_config() {

readonly qry='.auths["%s"] = {"auth": "%s"}'

test -s $config_file || echo '{}' >$config_file
local current_content=$(jq '.' $config_file)
if [[ "$current_content" == "" ]]; then
echo '{}' >$config_file
fi

cat $config_file | jq "$(printf "$qry" $server $token)" >$config_file
}

Expand Down

0 comments on commit 35a2020

Please sign in to comment.