Get devnulling docker output back and script "refactor".
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
b6197a045b
commit
f88c396ee9
65
mirror.sh
65
mirror.sh
@ -7,6 +7,38 @@ DESTINATION_PROJECT=${DESTINATION_REGISTRY}/containers/mirror
|
|||||||
USER=${REGISTRY_USER}
|
USER=${REGISTRY_USER}
|
||||||
PASSWORD=${REGISTRY_PASSWORD}
|
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.
|
# Starting Docker daemon.
|
||||||
/usr/local/bin/dockerd --data-root=/var/lib/docker &
|
/usr/local/bin/dockerd --data-root=/var/lib/docker &
|
||||||
|
|
||||||
@ -18,6 +50,7 @@ while true; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Load shell files and execute them to get list of mirrorred images.
|
||||||
MIRROR_CONFIGS=$(ls ./images/*.sh)
|
MIRROR_CONFIGS=$(ls ./images/*.sh)
|
||||||
# shellcheck disable=SC2068
|
# shellcheck disable=SC2068
|
||||||
for file in ${MIRROR_CONFIGS[@]}; do
|
for file in ${MIRROR_CONFIGS[@]}; do
|
||||||
@ -28,38 +61,6 @@ done
|
|||||||
|
|
||||||
echo "Images to mirror: ${WHAT_TO_MIRROR[*]}"
|
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.
|
# Login to registry.
|
||||||
echo "Logging into '${DESTINATION_REGISTRY}' as '${USER}'..."
|
echo "Logging into '${DESTINATION_REGISTRY}' as '${USER}'..."
|
||||||
docker login -u "${USER}" -p "${PASSWORD}" "${DESTINATION_REGISTRY}"
|
docker login -u "${USER}" -p "${PASSWORD}" "${DESTINATION_REGISTRY}"
|
||||||
|
Loading…
Reference in New Issue
Block a user