Improved exit code logic for functions.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Stanislav Nikitin 2023-01-01 22:52:55 +05:00
parent b689e41696
commit 7242d4004b
No known key found for this signature in database
GPG Key ID: 9A63857413C83B4A

View File

@ -56,6 +56,9 @@ function get_image() {
# Check if layers for requested architecture should be fetched.
if docker manifest inspect "${REMOTE_IMAGE}-${arch}" &> /dev/null; then
echo -e "\t* Layers for ${arch} architecture for this image exist at registry we mirror to!"
# This means that no mirrorring for arch-specific image is required.
return 2
fi
echo -ne "\t* Getting ${arch} layers... "
@ -108,9 +111,11 @@ function mirror() {
# We presumes that amd64 image should always be available.
if ! get_image "${image}" "amd64"; then
exitcode=$?
echo "! Image mirroring failed! Cannot obtain amd64 image!"
return 1
return ${exitcode}
fi
get_image "${image}" "arm64"
@ -121,7 +126,7 @@ function mirror() {
function push_multiarch_image() {
local image=$1
if ! docker push -f "${REMOTE_IMAGE}"-amd64 &> /tmp/push-amd64; then
if ! docker push "${REMOTE_IMAGE}"-amd64 &> /tmp/push-amd64; then
echo -e "\t! amd64 image push failed!"
echo -e "\nLogs:\n\n" && cat /tmp/push-amd64 && echo -e "\n"
@ -129,7 +134,7 @@ function push_multiarch_image() {
echo -e "\t* amd64 image pushed"
fi
if ! docker push -f ="${REMOTE_IMAGE}"-arm64 &> /tmp/push-arm64; then
if ! docker push "${REMOTE_IMAGE}"-arm64 &> /tmp/push-arm64; then
echo -e "\t! arm64 image push failed!"
echo -e "\nLogs:\n\n" && cat /tmp/push-arm64 && echo -e "\n"
@ -167,8 +172,13 @@ collect_images
for package in "${WHAT_TO_MIRROR[@]}"; do
if ! mirror "${package}"; then
echo "! Failed to mirror package ${package}!"
exitcode=$?
echo "! Failed to mirror package ${package}! Exit code: ${exitcode} (1 is fatal)."
# Shit happens only for exitcode 1.
if [ ${exitcode} -eq 1 ]; then
exit 1
fi
fi
done