Get devnulling docker output back and script "refactor".
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Stanislav Nikitin 2022-06-27 12:33:03 +05:00
parent b6197a045b
commit f88c396ee9
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550

View File

@ -7,6 +7,38 @@ DESTINATION_PROJECT=${DESTINATION_REGISTRY}/containers/mirror
USER=${REGISTRY_USER}
PASSWORD=${REGISTRY_PASSWORD}
function mirror() {
image=$1
image_name=$(echo "${image}" | cut -d":" -f 1)
image_version=$(echo "${image}" | cut -d":" -f 2)
echo -n "Mirroring ${image}... "
if ! docker pull "${image}" &> /dev/null; then
echo "PULL FAILED"
exit 1
fi
# shellcheck disable=SC1083
image_hash=$(docker images -a | grep "^${image_name}" | grep "${image_version}" | awk {' print $3 '})
echo -n "${image_hash} received, retag as '${DESTINATION_PROJECT}/${image}'... "
if ! docker tag "${image_hash}" "${DESTINATION_PROJECT}/${image}" &> /dev/null; then
echo "TAGGING FAILED"
exit 1
fi
echo -n "pushing... "
if ! docker push "${DESTINATION_PROJECT}/${image}" &> /dev/null; then
echo "FAILED"
exit 1
fi
echo "OK"
docker image rm "${image}" &> /dev/null
docker image rm "${DESTINATION_PROJECT}/${image}" &> /dev/null
}
# Starting Docker daemon.
/usr/local/bin/dockerd --data-root=/var/lib/docker &
@ -18,6 +50,7 @@ while true; do
fi
done
# Load shell files and execute them to get list of mirrorred images.
MIRROR_CONFIGS=$(ls ./images/*.sh)
# shellcheck disable=SC2068
for file in ${MIRROR_CONFIGS[@]}; do
@ -28,38 +61,6 @@ done
echo "Images to mirror: ${WHAT_TO_MIRROR[*]}"
function mirror() {
image=$1
image_name=$(echo "${image}" | cut -d":" -f 1)
image_version=$(echo "${image}" | cut -d":" -f 2)
echo -n "Mirroring ${image}... "
if ! docker pull "${image}"; then
echo "PULL FAILED"
exit 1
fi
# shellcheck disable=SC1083
image_hash=$(docker images -a | grep "^${image_name}" | grep "${image_version}" | awk {' print $3 '})
echo -n "${image_hash} received, retag as '${DESTINATION_PROJECT}/${image}'... "
if ! docker tag "${image_hash}" "${DESTINATION_PROJECT}/${image}"; then
echo "TAGGING FAILED"
exit 1
fi
echo -n "pushing... "
if ! docker push "${DESTINATION_PROJECT}/${image}"; then
echo "FAILED"
exit 1
fi
echo "OK"
docker image rm "${image}"
docker image rm "${DESTINATION_PROJECT}/${image}"
}
# Login to registry.
echo "Logging into '${DESTINATION_REGISTRY}' as '${USER}'..."
docker login -u "${USER}" -p "${PASSWORD}" "${DESTINATION_REGISTRY}"