diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..a92aaba --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,24 @@ +image: docker:19.03.13 + +services: + - docker:19.03.13-dind + +variables: + DOCKER_HOST: tcp://docker:2375 + DOCKER_TCP_PORT: 2375 + DOCKER_TLS_CERTDIR: "" + +stages: + - mirror + +before_script: + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + +mirror: + stage: mirror + tags: + - docker + script: + - ./mirror.sh + only: + - master diff --git a/README.md b/README.md index 5e5c48c..e7e2426 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,28 @@ # mirror -Docker images mirroring project. \ No newline at end of file +Docker images mirroring project. + +This thing appears after constant inability of Gitlab developers to mitigate +Docker Hub ratelimiting shit. + +Feel free to use and re-use these images and this mirrorer. + +If it helps you much - please, [donate](https://paypal.me/pztrn) + +## How to use + +This script assumes that you are already logged in into Gitlab Registry. + +### In CI + +Ensure to add global `before_script`: + +``` +before_script: + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY +``` + +## Adding new image + +If you decided to use my mirrors and want to mirror some image - please make an +MR with image name be exactly same as in other files in `images` directory. diff --git a/images/docker.sh b/images/docker.sh new file mode 100644 index 0000000..fd71d65 --- /dev/null +++ b/images/docker.sh @@ -0,0 +1 @@ +echo "docker:19.03.13-dind" diff --git a/images/golangci-lint.sh b/images/golangci-lint.sh new file mode 100644 index 0000000..54c1b20 --- /dev/null +++ b/images/golangci-lint.sh @@ -0,0 +1 @@ +echo "golangci-lint:v1.13.2 golangci-lint:latest" diff --git a/mirror.sh b/mirror.sh new file mode 100755 index 0000000..5a38f57 --- /dev/null +++ b/mirror.sh @@ -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