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

This commit is contained in:
Stanislav Nikitin 2022-06-26 23:53:26 +05:00
parent ee8764fb58
commit 0d60c4b933
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
6 changed files with 52 additions and 15 deletions

29
.drone.yml Normal file
View File

@ -0,0 +1,29 @@
---
kind: pipeline
type: docker
name: "lint"
steps:
- name: lint
image: koalaman/shellcheck:v0.8.0
pull: if-not-exists
commands:
- shellcheck mirror.sh
---
kind: pipeline
type: docker
name: "mirror"
depends_on:
- "lint"
trigger:
branch: ["main"]
steps:
- name: "mirror"
image: "docker:20.10.17-dind"
pull: if-not-exists
commands:
- ./mirror.sh drone ${drone_secret}

View File

@ -1 +1,2 @@
#!/usr/bin/env bash
echo "curlimages/curl:7.79.1"

View File

@ -1 +1,2 @@
echo "docker:19.03.13-dind docker:19.03.13 docker:20.10.8-dind"
#!/usr/bin/env bash
echo "docker:20.10.17-dind"

View File

@ -1 +1,2 @@
#!/usr/bin/env bash
echo "golang:1.15.5-alpine golang:1.17.1-alpine"

View File

@ -1 +1,2 @@
echo "golangci/golangci-lint:v1.32.2 golangci/golangci-lint:v1.33.0 golangci/golangci-lint:latest golangci/golangci-lint:v1.42.1"
#!/usr/bin/env bash
echo "golangci/golangci-lint:v1.46.2"

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