Update mirrorred images list and add Drone config.
continuous-integration/drone/push Build encountered an error

This commit is contained in:
2022-06-26 23:53:26 +05:00
parent ee8764fb58
commit 0d60c4b933
6 changed files with 52 additions and 15 deletions
+17 -13
View File
@@ -3,14 +3,18 @@
# The Docker Image Mirror script.
WHAT_TO_MIRROR=()
REGISTRY_TO_MIRROR=registry.gitlab.pztrn.name/containers/mirror
DESTINATION_REGISTRY=code.pztrn.name/containers/mirror
REGISTRY_USER=$1
REGISTRY_PASSWORD=$2
for file in $(ls ./images/*.sh); do
MIRROR_CONFIGS=$(ls ./images/*.sh)
for file in "${MIRROR_CONFIGS[@]}"; do
echo "Importing ${file}..."
WHAT_TO_MIRROR=( ${WHAT_TO_MIRROR[@]} $(bash ${file}) )
# shellcheck disable=SC2086
WHAT_TO_MIRROR=( "${WHAT_TO_MIRROR[@]}" "$(bash ${file})" )
done
echo "Images to mirror: ${WHAT_TO_MIRROR[@]}"
echo "Images to mirror: ${WHAT_TO_MIRROR[*]}"
function mirror() {
image=$1
@@ -18,24 +22,21 @@ function mirror() {
image_version=$(echo "${image}" | cut -d":" -f 2)
echo -n "Mirroring ${image}... "
docker pull "${image}" &> /dev/null
if [ $? -ne 0 ]; then
if ! docker pull "${image}" &> /dev/null; then
echo "FAIL"
exit
fi
image_hash=$(docker images -a | grep "^${image_name}" | grep "${image_version}" | awk {' print $3 '})
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}" &> /dev/null
if [ $? -ne 0 ]; then
if ! docker tag "${image_hash}" "${DESTINATION_REGISTRY}/${image}" &> /dev/null; then
echo "FAIL"
exit
fi
echo -n "pushing... "
docker push "${REGISTRY_TO_MIRROR}/${image}" &> /dev/null
if [ $? -ne 0 ]; then
if ! docker push "${REGISTRY_TO_MIRROR}/${image}" &> /dev/null; then
echo "FAIL"
exit
fi
@@ -46,7 +47,10 @@ function mirror() {
docker image rm "${REGISTRY_TO_MIRROR}/${image}" &> /dev/null
}
# Login to registry.
docker login -u "${REGISTRY_USER}" -p "${REGISTRY_PASSWORD}" "${DESTINATION_REGISTRY}"
# Mirror images.
for image in ${WHAT_TO_MIRROR[@]}; do
mirror ${image}
for image in "${WHAT_TO_MIRROR[@]}"; do
mirror "${image}"
done