Improved exit code logic for functions.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b689e41696
commit
7242d4004b
20
mirror.sh
20
mirror.sh
@ -56,6 +56,9 @@ function get_image() {
|
|||||||
# Check if layers for requested architecture should be fetched.
|
# Check if layers for requested architecture should be fetched.
|
||||||
if docker manifest inspect "${REMOTE_IMAGE}-${arch}" &> /dev/null; then
|
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!"
|
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
|
fi
|
||||||
|
|
||||||
echo -ne "\t* Getting ${arch} layers... "
|
echo -ne "\t* Getting ${arch} layers... "
|
||||||
@ -108,9 +111,11 @@ function mirror() {
|
|||||||
|
|
||||||
# We presumes that amd64 image should always be available.
|
# We presumes that amd64 image should always be available.
|
||||||
if ! get_image "${image}" "amd64"; then
|
if ! get_image "${image}" "amd64"; then
|
||||||
|
exitcode=$?
|
||||||
|
|
||||||
echo "! Image mirroring failed! Cannot obtain amd64 image!"
|
echo "! Image mirroring failed! Cannot obtain amd64 image!"
|
||||||
|
|
||||||
return 1
|
return ${exitcode}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
get_image "${image}" "arm64"
|
get_image "${image}" "arm64"
|
||||||
@ -121,7 +126,7 @@ function mirror() {
|
|||||||
function push_multiarch_image() {
|
function push_multiarch_image() {
|
||||||
local image=$1
|
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 "\t! amd64 image push failed!"
|
||||||
|
|
||||||
echo -e "\nLogs:\n\n" && cat /tmp/push-amd64 && echo -e "\n"
|
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"
|
echo -e "\t* amd64 image pushed"
|
||||||
fi
|
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 "\t! arm64 image push failed!"
|
||||||
|
|
||||||
echo -e "\nLogs:\n\n" && cat /tmp/push-arm64 && echo -e "\n"
|
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
|
for package in "${WHAT_TO_MIRROR[@]}"; do
|
||||||
if ! mirror "${package}"; then
|
if ! mirror "${package}"; then
|
||||||
echo "! Failed to mirror package ${package}!"
|
exitcode=$?
|
||||||
|
|
||||||
exit 1
|
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
|
fi
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user