2020-12-23 18:39:02 +05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# The Docker Image Mirror script.
|
|
|
|
|
|
|
|
WHAT_TO_MIRROR=()
|
|
|
|
REGISTRY_TO_MIRROR=registry.gitlab.pztrn.name/containers/mirror
|
|
|
|
|
|
|
|
for file in $(ls ./images/*.sh); do
|
|
|
|
echo "Importing ${file}..."
|
2020-12-23 18:59:11 +05:00
|
|
|
WHAT_TO_MIRROR=( ${WHAT_TO_MIRROR[@]} $(bash ${file}) )
|
2020-12-23 18:39:02 +05:00
|
|
|
done
|
|
|
|
|
2020-12-23 18:59:11 +05:00
|
|
|
echo "Images to mirror: ${WHAT_TO_MIRROR[@]}"
|
2020-12-23 18:39:02 +05:00
|
|
|
|
|
|
|
function mirror() {
|
|
|
|
image=$1
|
|
|
|
image_name=$(echo "${image}" | cut -d":" -f 1)
|
|
|
|
image_version=$(echo "${image}" | cut -d":" -f 2)
|
|
|
|
|
|
|
|
echo -n "Mirroring ${image}... "
|
|
|
|
docker pull "${image}" &> /dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "FAIL"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2020-12-23 18:59:11 +05:00
|
|
|
image_hash=$(docker images -a | grep "^${image_name}" | grep "${image_version}" | awk {' print $3 '})
|
2020-12-23 18:39:02 +05:00
|
|
|
echo -n "${image_hash} received... "
|
|
|
|
|
2020-12-23 18:42:29 +05:00
|
|
|
docker tag "${image_hash}" "${REGISTRY_TO_MIRROR}/${image}" &> /dev/null
|
2020-12-23 18:39:02 +05:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "FAIL"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -n "pushing... "
|
2020-12-23 18:42:29 +05:00
|
|
|
docker push "${REGISTRY_TO_MIRROR}/${image}" &> /dev/null
|
2020-12-23 18:39:02 +05:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "FAIL"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "OK"
|
|
|
|
|
2020-12-23 18:42:29 +05:00
|
|
|
docker image rm "${image}" &> /dev/null
|
2020-12-23 18:59:11 +05:00
|
|
|
docker image rm "${REGISTRY_TO_MIRROR}/${image}" &> /dev/null
|
2020-12-23 18:39:02 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
# Mirror images.
|
|
|
|
for image in ${WHAT_TO_MIRROR[@]}; do
|
|
|
|
mirror ${image}
|
|
|
|
done
|