Initial commit.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# The Docker Image Mirror script.
|
||||
# Designed to be used in Gitlab CI.
|
||||
|
||||
WHAT_TO_MIRROR=()
|
||||
REGISTRY_TO_MIRROR=registry.gitlab.pztrn.name/containers/mirror
|
||||
|
||||
for file in $(ls ./images/*.sh); do
|
||||
echo "Importing ${file}..."
|
||||
WHAT_TO_MIRROR=( ${WHAT_TO_MIRROR} $(bash ${file}) )
|
||||
done
|
||||
|
||||
echo ${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}... "
|
||||
docker pull "${image}" &> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "FAIL"
|
||||
exit
|
||||
fi
|
||||
|
||||
image_hash=$(docker images -a | grep "${image_name}" | grep "${image_version}" | awk {' print $3 '})
|
||||
echo -n "${image_hash} received... "
|
||||
|
||||
docker tag "${image_hash}" "${REGISTRY_TO_MIRROR}/${image}"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "FAIL"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo -n "pushing... "
|
||||
docker push "${REGISTRY_TO_MIRROR}/${image}"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "FAIL"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "OK"
|
||||
|
||||
docker image rm "${image}"
|
||||
}
|
||||
|
||||
# Mirror images.
|
||||
for image in ${WHAT_TO_MIRROR[@]}; do
|
||||
mirror ${image}
|
||||
done
|
||||
Reference in New Issue
Block a user