Initial commit.
This commit is contained in:
parent
c3a7a8b832
commit
08c5f16d04
24
.gitlab-ci.yml
Normal file
24
.gitlab-ci.yml
Normal file
@ -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
|
27
README.md
27
README.md
@ -1,3 +1,28 @@
|
||||
# mirror
|
||||
|
||||
Docker images mirroring project.
|
||||
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.
|
||||
|
1
images/docker.sh
Normal file
1
images/docker.sh
Normal file
@ -0,0 +1 @@
|
||||
echo "docker:19.03.13-dind"
|
1
images/golangci-lint.sh
Normal file
1
images/golangci-lint.sh
Normal file
@ -0,0 +1 @@
|
||||
echo "golangci-lint:v1.13.2 golangci-lint:latest"
|
52
mirror.sh
Executable file
52
mirror.sh
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user