Compare commits

...

70 Commits

Author SHA1 Message Date
77ebf660c4 Docker-buildx plugin version fix.
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-09 12:29:59 +05:00
4fcf0994a8 Update docker plugin and mirror docker-buildx plugin.
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-09 12:26:26 +05:00
19736565aa Update all images.
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-04 11:47:15 +05:00
7cd57c72ea Update Drone Docker plugin.
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-04 11:43:55 +05:00
f91dd727d9 Update versions of images.
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-15 20:05:58 +05:00
454f80eee1 Mirror newest golang and golangci-lint images.
All checks were successful
continuous-integration/drone/push Build is passing
2023-03-20 00:53:00 +05:00
68d972c812 Do not whine about complete failure when it is not.
All checks were successful
continuous-integration/drone/push Build is passing
2023-01-01 22:54:07 +05:00
7242d4004b Improved exit code logic for functions.
All checks were successful
continuous-integration/drone/push Build is passing
2023-01-01 22:52:55 +05:00
b689e41696 Show errors on push failures.
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-01-01 22:47:33 +05:00
a0c1527615 Whoopsie.
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-01-01 22:45:16 +05:00
1ff7f5ebdc Echo log if pulling failed.
Some checks failed
continuous-integration/drone/push Build is failing
2023-01-01 22:44:31 +05:00
66ca161018 Refactor mirror script, no more (almost) duplicate functions.
Some checks failed
continuous-integration/drone/push Build is failing
2023-01-01 22:42:28 +05:00
1537e05df7 Try to make image checking be non-fatal if image already exists.
Some checks failed
continuous-integration/drone/push Build is failing
2023-01-01 22:32:21 +05:00
21666b4de3 Force push for images and proper interruption when pulling images fail.
Some checks failed
continuous-integration/drone/push Build is failing
2023-01-01 22:27:47 +05:00
edb14e5112 Add golangci-lint 1.48.0.
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is failing
2022-08-14 15:20:44 +05:00
b922976a06 Add golang 1.19.
Some checks failed
continuous-integration/drone/push Build is failing
2022-08-14 15:18:55 +05:00
915f6301d7 Update Alpine to 3.16.1.
Some checks failed
continuous-integration/drone/push Build is failing
2022-07-30 00:06:57 +05:00
7e43557066 Try to limit maximum concurrent uploads.
Some checks failed
continuous-integration/drone/push Build is failing
2022-07-30 00:02:30 +05:00
3e2cacbc30 Try to limit maximum concurrent uploads.
Some checks failed
continuous-integration/drone/push Build is failing
2022-07-29 11:51:27 +05:00
4c057ad204 Add bullseye image for golang and return proper exitcode in mirror script.
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-29 15:21:43 +05:00
e0b6a10931 Add alpine:3.16.0 for mirrorring and add ability to check if image mirrorred.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-28 22:10:56 +05:00
3f26589e85 Add drone CI plugins for mirroring.
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-28 21:15:27 +05:00
ac39480c97 Add devnulls and fix login function's log output.
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-28 20:25:11 +05:00
481b2464a4 Fix login function to use proper env vars.
Some checks reported errors
continuous-integration/drone/push Build was killed
2022-06-28 20:21:13 +05:00
255496af87 Make linters happy.
Some checks reported errors
continuous-integration/drone/push Build was killed
2022-06-28 20:16:10 +05:00
996c79e4b4 Complete script rework.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-28 20:15:13 +05:00
68137b31c1 Removed doonation link and removed arm64 mirroring as gitea unable to handle it properly.
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-27 13:07:04 +05:00
beae8447ec Mirror amd64 and arm64 images.
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-27 12:53:36 +05:00
f88c396ee9 Get devnulling docker output back and script "refactor".
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-27 12:33:03 +05:00
b6197a045b Make mirror step privileged.
Some checks reported errors
continuous-integration/drone/push Build was killed
2022-06-27 12:30:46 +05:00
5dd146d2c0 Trying to start Docker daemon in script.
Some checks reported errors
continuous-integration/drone/push Build was killed
Can possibly help with authorization problems.
2022-06-27 12:29:43 +05:00
a26adfc78b Doing nasty things.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 02:45:40 +05:00
b48a949dc3 Remove output devnulling (again).
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 02:30:50 +05:00
eb135b099d Rollback changes and remove curl mirroring.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 02:20:30 +05:00
9b4504684b Broke script temporary.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 02:16:40 +05:00
732b08b12a Move registry address into Drone configuration.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 02:06:11 +05:00
49ece50d05 Fix mirror script logging in to registry.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 02:00:19 +05:00
7173cab2ba More verbosity to mirror script.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:58:47 +05:00
f366a06689 And walking...
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:58:05 +05:00
5a2436cb80 Walking around...
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:56:27 +05:00
db9922eea3 Another try.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:55:31 +05:00
df03ea6ead Still trying...
Some checks reported errors
continuous-integration/drone/push Build was killed
2022-06-27 01:52:57 +05:00
1aef03bea8 Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:52:33 +05:00
adbce93902 Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:51:24 +05:00
b7e1eb1f09 Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:48:07 +05:00
5d032cdcd6 Trying to Fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:45:39 +05:00
6af5138b90 Silence docker logging.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:36:27 +05:00
65c4f0b4db Fix mirror script - rolled back changes proposed by shellcheck.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:29:22 +05:00
cf1aa3e65f Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:26:14 +05:00
c0fa739463 Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:25:17 +05:00
379be9c9c0 Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 01:22:17 +05:00
599f19268b Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:41:31 +05:00
925cb98447 Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:38:00 +05:00
ccc66aeae8 Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:32:19 +05:00
afd4c029ec Trying to fix CI.
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2022-06-27 00:31:59 +05:00
39100af7fd Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:27:39 +05:00
54025c8a51 Trying to fix CI.
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2022-06-27 00:27:19 +05:00
9fa88a455d Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:24:01 +05:00
dd79ae7c67 Trying to fix CI.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:22:06 +05:00
12c0d3771d Remove output redirection to /dev/null for debugging purposes.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:13:31 +05:00
f8da2f4a98 Add proper FAIL state logging and fix registry variable.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:12:17 +05:00
7ced1e5528 Debug commit.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:10:40 +05:00
b66d9c5314 Debug commit.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:10:08 +05:00
62c2dbf194 Debug commit.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:08:44 +05:00
ce7044456e Debug commit.
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-27 00:06:13 +05:00
cdbe68bddc Debug commit.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-27 00:05:22 +05:00
906d02b0c6 We need Bash in dind image.
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-27 00:03:18 +05:00
c51532f71d Use another image for shellcheck.
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-26 23:56:24 +05:00
6c8f13a394 Try to fix CI.
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2022-06-26 23:54:52 +05:00
0d60c4b933 Update mirrorred images list and add Drone config.
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2022-06-26 23:53:26 +05:00
9 changed files with 215 additions and 38 deletions

37
.drone.yml Normal file
View File

@@ -0,0 +1,37 @@
---
kind: pipeline
type: docker
name: "lint"
steps:
- name: lint
image: koalaman/shellcheck-alpine:v0.8.0
pull: if-not-exists
commands:
- /bin/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
privileged: true
environment:
REGISTRY: code.pztrn.name
REGISTRY_PROJECT: /containers/mirror
REGISTRY_USERNAME: drone
REGISTRY_PASSWORD:
from_secret: drone_secret
commands:
- apk add --no-cache bash
- ./mirror.sh

View File

@@ -7,8 +7,6 @@ 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.
@@ -17,7 +15,7 @@ This script assumes that you are already logged in into Gitlab Registry.
Ensure to add global `before_script`:
```
```yaml
before_script:
- apk add bash
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY

2
images/alpine.sh Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
echo "alpine:3.18.3 alpine:3.19.1"

View File

@@ -1 +0,0 @@
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:26.1.1-dind"

2
images/drone-plugins.sh Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
echo "plugins/docker:20.17.6 plugins/buildx:1.1.11 plugins/manifest:1.2.3"

View File

@@ -1 +1,3 @@
echo "golang:1.15.5-alpine golang:1.17.1-alpine"
#!/usr/bin/env bash
# Bullseye image for GCC.
echo "golang:1.22.2-bullseye golang:1.22.2-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.57.2"

193
mirror.sh
View File

@@ -1,52 +1,187 @@
#!/usr/bin/env bash
# The Docker Image Mirror script.
# Designed to mirror amd64 and arm64 images somewhere you want.
# Required environment variables:
#
# * REGISTRY: to which registry images should be sent. Should not contain protocols,
# should be the very same as you use 'docker login' with.
# * REGISTRY_USERNAME: user name to use for destination registry.
# * REGISTRY_PASSWORD: password to use for destination registry's user.
# * REGISTRY_PROJECT: path within registry (or it's part) where images will be push'd.
# Should start with '/'!
# What images we will mirror. Collected by executing scripts in "images" directory, see
# "collect_images" function.
WHAT_TO_MIRROR=()
REGISTRY_TO_MIRROR=registry.gitlab.pztrn.name/containers/mirror
for file in $(ls ./images/*.sh); do
# New tag for currently processing image as it will be used with 'docker push'.
# Updates for every image. Contains only path, image name and base tag from source.
REMOTE_IMAGE=""
# Is image multiarch? E.g. is we're successfully fetched not only amd64 image,
# but also an arm64? Updates for every image.
MULTIARCH=0
function cleanup() {
local image=$1
docker image rm "${image}" &> /dev/null
docker image rm "${REMOTE_IMAGE}" &> /dev/null
docker image rm "${REMOTE_IMAGE}"-amd64 &> /dev/null
docker image rm "${REMOTE_IMAGE}"-arm64 &> /dev/null
}
function collect_images() {
# Load shell files and execute them to get list of mirrorred images.
MIRROR_CONFIGS=$(ls ./images/*.sh)
# shellcheck disable=SC2068
for file in ${MIRROR_CONFIGS[@]}; do
echo "Importing ${file}..."
# shellcheck disable=SC2086,SC2207,SC2206
WHAT_TO_MIRROR=( ${WHAT_TO_MIRROR[@]} $(bash ${file}) )
done
done
echo "Images to mirror: ${WHAT_TO_MIRROR[@]}"
echo "Images to mirror: ${WHAT_TO_MIRROR[*]}"
}
function get_image() {
local image=$1
local arch=$2
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
# Check if layers for requested architecture should be fetched.
if docker manifest inspect "${REMOTE_IMAGE}-${arch}" &> /dev/null; then
echo -e "\t* Layers for ${arch} architecture for this image exist at registry we mirror to!"
# This means that no mirrorring for arch-specific image is required.
return 2
fi
echo -ne "\t* Getting ${arch} layers... "
# arm64 layers might be missing. So we just put "FAIL!" here and do nothing else.
if ! docker pull --platform=linux/"${arch}" "${image}" &> "/tmp/pull-${arch}"; then
echo "FAIL!"
echo -e "\nLogs:\n\n" && cat "/tmp/pull-${arch}" && echo -e "\n"
# We presume that amd64 layers are always present. Returning an error here if they're absent.
if [ "${arch}" == "amd64" ]; then
return 1
fi
fi
echo -n "Downloaded, "
# shellcheck disable=SC1083
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
echo "FAIL"
exit
if ! docker tag "${image_hash}" "${REMOTE_IMAGE}-${arch}" &> /dev/null; then
echo "but tagging failed!"
exit 1
fi
echo -n "pushing... "
docker push "${REGISTRY_TO_MIRROR}/${image}" &> /dev/null
if [ $? -ne 0 ]; then
echo "FAIL"
exit
echo "tagged."
# Set multiarch flag for any other arch than amd64.
if [ "${arch}" != "amd64" ]; then
MULTIARCH=1
fi
echo "OK"
docker image rm "${image}" &> /dev/null
docker image rm "${REGISTRY_TO_MIRROR}/${image}" &> /dev/null
}
# Mirror images.
for image in ${WHAT_TO_MIRROR[@]}; do
mirror ${image}
function login_to_registry() {
# Login to registry.
echo "Logging into '${REGISTRY}' as '${REGISTRY_USERNAME}'..."
docker login -u "${REGISTRY_USERNAME}" -p "${REGISTRY_PASSWORD}" "${REGISTRY}"
}
function mirror() {
local image=$1
image_name=$(echo "${image}" | cut -d":" -f 1)
image_version=$(echo "${image}" | cut -d":" -f 2)
echo "* Mirroring ${image}"
REMOTE_IMAGE="${REGISTRY}${REGISTRY_PROJECT}/${image}"
MULTIARCH=0
# We presumes that amd64 image should always be available.
if ! get_image "${image}" "amd64"; then
exitcode=$?
# Shit happened.
if [ ${exitcode} -eq 1 ]; then
echo "! Image mirroring failed! Cannot obtain amd64 image!"
fi
return ${exitcode}
fi
get_image "${image}" "arm64"
push_multiarch_image "${image}"
cleanup "${image}"
}
function push_multiarch_image() {
local image=$1
if ! docker push "${REMOTE_IMAGE}"-amd64 &> /tmp/push-amd64; then
echo -e "\t! amd64 image push failed!"
echo -e "\nLogs:\n\n" && cat /tmp/push-amd64 && echo -e "\n"
else
echo -e "\t* amd64 image pushed"
fi
if ! docker push "${REMOTE_IMAGE}"-arm64 &> /tmp/push-arm64; then
echo -e "\t! arm64 image push failed!"
echo -e "\nLogs:\n\n" && cat /tmp/push-arm64 && echo -e "\n"
else
echo -e "\t* arm64 image pushed"
fi
if [ ${MULTIARCH} -eq 1 ]; then
echo -e "\t* Image is multi-arch, creating and pushing a manifest..."
docker manifest create "${REMOTE_IMAGE}" \
--amend "${REMOTE_IMAGE}"-amd64 \
--amend "${REMOTE_IMAGE}"-arm64 \
&> /dev/null
docker manifest push "${REMOTE_IMAGE}" &> /dev/null
fi
}
function start_docker_daemon() {
# Starting Docker daemon.
/usr/local/bin/dockerd --data-root=/var/lib/docker --max-concurrent-uploads 1 &
# Wait for it.
echo "Waiting for Docker daemon to start..."
while true; do
if docker ps &> /dev/null; then
break
fi
done
}
start_docker_daemon
login_to_registry
collect_images
for package in "${WHAT_TO_MIRROR[@]}"; do
if ! mirror "${package}"; then
exitcode=$?
echo "! Failed to mirror package ${package}! Exit code: ${exitcode} (1 is fatal)."
# Shit happens only for exitcode 1.
if [ ${exitcode} -eq 1 ]; then
exit 1
fi
fi
done