ci: add script and config to mirror images to local CI registry

This script reads images.txt and copies the images from docker.io (or
other registries) to the local registry in the CI.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2021-05-14 14:49:51 +02:00 committed by mergify[bot]
parent c40a055628
commit 4ec5b6f045
2 changed files with 72 additions and 0 deletions

20
mirror/images.txt Normal file
View File

@ -0,0 +1,20 @@
# images.txt
#
# These lists contain the images that need to get mirrored from public
# registries to the local CI registry.
#
# format: <full-image-spec> <short-name>
#
# ceph-csi v3.4
docker.io/ceph/ceph:v16 ceph/ceph:v16
docker.io/rook/ceph:v1.6.2 rook/ceph:v1.6.2
# ceph-csi v3.3
docker.io/ceph/ceph:v15 ceph/ceph:v15
docker.io/rook/ceph:v1.4.9 rook/ceph:v1.4.9
# e2e testing
docker.io/library/busybox:1.29 library/busybox:1.29
docker.io/library/nginx:latest library/nginx:latest
docker.io/library/vault:latest library/vault:latest

52
mirror/mirror-images.sh Executable file
View File

@ -0,0 +1,52 @@
#!/bin/bash
#
# Mirror images listed in images.txt to the internal CI registry.
#
# Set DOCKER_CONFIG_JSON to the contents of ~/.docker/config.json to use the
# authentication details from a cached configuration file.
#
# Set CI_REGISTRY_USER and CI_REGISTRY_PASSWD with the login details for the CI
# registry.
#
CI_REGISTRY='registry-ceph-csi.apps.ocp.ci.centos.org'
# get_image_entries returns the contents of images.txt without comments or empty lines
function get_image_entries() {
grep -v -e '^#' -e '^$' images.txt
}
# create a temporary containers/auth.json for skopeo usage
REGISTRY_AUTH_FILE="$(mktemp -t)"
export REGISTRY_AUTH_FILE
# make the temporary containers/auth.json a valid json file
echo '{}' > "${REGISTRY_AUTH_FILE}"
# if DOCKER_CONFIG_JSON is non-empty, use the credentials from there
if [ -n "${DOCKER_CONFIG_JSON}" ]
then
echo 'using ~/docker/config.json from env:DOCKER_CONFIG_JSON'
echo "${DOCKER_CONFIG_JSON}" > "${REGISTRY_AUTH_FILE}"
fi
# login on the CI registry if the user/passwd are available
if [ -n "${CI_REGISTRY_USER}" ] && [ -n "${CI_REGISTRY_PASSWD}" ]
then
echo 'using CI registry login from env:CI_REGISTRY_USER and env:CI_REGISTRY_PASSWD'
skopeo login \
--username="${CI_REGISTRY_USER}" \
--password="${CI_REGISTRY_PASSWD}" \
"${CI_REGISTRY}"
fi
# read each line from get_image_entries() into an array
while read -r -a IMAGE_ENTRY
do
# 1st entry in the array is the source
# 2nd entry in the array is the destination in the CI registry
SRC="docker://${IMAGE_ENTRY[0]}"
DST="docker://${CI_REGISTRY}/${IMAGE_ENTRY[1]}"
echo "going to copy ${SRC} to ${DST}"
skopeo copy "${SRC}" "${DST}"
done <<< "$(get_image_entries)"