Skip to content

Commit

Permalink
Fixes #22: add auth for crane commands
Browse files Browse the repository at this point in the history
Signed-off-by: Emin Aktas <emin.aktas@axon-networks.com>
  • Loading branch information
eminaktas committed Sep 4, 2024
1 parent 6f8ff3f commit c64cea4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,33 @@ if [[ "${DOCKER_AUDIT_IMAGE:-1}" == 1 ]]; then
fi


#################################################
# runs crane commands in a Docker container
# authenticates with the registry using env vars
# usage: crane_command <crane args>
#################################################
crane_command() {
docker run --rm -it \
-e DOCKER_REGISTRY="$DOCKER_REGISTRY" \
-e DOCKER_REGISTRY_USERNAME="$DOCKER_REGISTRY_USERNAME" \
-e DOCKER_REGISTRY_TOKEN="$DOCKER_REGISTRY_TOKEN" \
--entrypoint sh \
gcr.io/go-containerregistry/crane:debug -c "
crane auth login -u \$DOCKER_REGISTRY_USERNAME -p \$DOCKER_REGISTRY_TOKEN \$DOCKER_REGISTRY && crane $*"
}


#################################################
# push image with tags to remote docker image registry
#################################################
if [[ "${DOCKER_PUSH:-0}" == "1" ]]; then
docker run --network host --rm gcr.io/go-containerregistry/crane copy $local_registery/$image_name $docker_registry/$image_name
crane_command copy $local_registery/$image_name $docker_registry/$image_name

if [[ $graalvm_version != *dev* ]]; then
if [[ $java_major_version == "11" ]]; then
docker run --network host --rm gcr.io/go-containerregistry/crane copy $local_registery/$image_name $docker_registry/$image_repo:$graalvm_version-java$java_major_version # e.g. 22.3.2-java11
crane_command copy $local_registery/$image_name $docker_registry/$image_repo:$graalvm_version-java$java_major_version # e.g. 22.3.2-java11
else
docker run --network host --rm gcr.io/go-containerregistry/crane copy $local_registery/$image_name $docker_registry/$image_repo:$graalvm_version # e.g. 17.0.7
crane_command copy $local_registery/$image_name $docker_registry/$image_repo:$graalvm_version # e.g. 17.0.7
fi
fi
fi

0 comments on commit c64cea4

Please sign in to comment.