Skip to content

Instantly share code, notes, and snippets.

@abdennour
Created May 28, 2020 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdennour/7f32f55037edeae7ad756defe7c7bf56 to your computer and use it in GitHub Desktop.
Save abdennour/7f32f55037edeae7ad756defe7c7bf56 to your computer and use it in GitHub Desktop.
Offline Cluster 1 - Pull images from the proxy registry
#!/bin/bash
echo "If you want to make quay.io/coreos/flannel:v0.11.0-amd64 available in the machine :"
echo "- Example Run : ${0} quay.io/coreos/flannel/v0.11.0-amd64"
echo "- Example Run : ${0} myapp-pod.yaml "
echo "- Example Run : ${0} http://some.thing/myapp-pod.yaml "
private_registry=${2}
regex_remote='^(https?|ftp)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]\.[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$'
# ---- functions ---
function from_imagename
{
# trim spaces
public_image=${1//[[:space:]]/}
# remove everything after first slash, and remove everything after colon
public_hostname=$(echo ${1} | sed 's@/.*@@g' | sed 's@:.*@@g');
if [[ "${public_hostname}" != *"."* ]]; then
IS_DOCKERHUB="YES"
public_image_hub=${public_image}
public_image=docker.io/${public_image_hub}
else
IS_DOCKERHUB="NO"
fi
private_image=$(echo ${public_image} | sed 's@.*/@'"$private_registry"'/@g')
docker pull ${private_image}
docker tag ${private_image} ${public_image}
if [ "${IS_DOCKERHUB}" = "YES" ]; then
docker tag ${private_image} ${public_image_hub}
fi
}
function from_remote
{
curl ${1} | grep image: | sed 's/.*image://g' | while read -r pub_image ; do
from_imagename ${pub_image}
done
}
function from_localfile
{
cat ${1} | grep image: | sed 's/.*image://g' | while read -r pub_image ; do
from_imagename ${pub_image}
done
}
#----- main
if [[ $1 =~ $regex_remote ]] ;
then
from_remote ${1}
elif [[ -f ${1} ]];
then
from_localfile ${1}
else
from_imagename ${1}
fi

proxy_registry=nexus.company.com

pull image from docker.io using proxy registry

offline_pull_images alpine:3.11 $proxy_registry

pull image from quay.io using proxy registry

offline_pull_images quay.io/coreos/flannel/v0.11.0-amd64 $proxy_registry

pull all images mentioned in the local YAML file using proxy registry

offline_pull_images ./deployment.yaml $proxy_registry

pull all images mentioned in the remote YAML file using proxy registry

offline_pull_images  https://docs.projectcalico.org/manifests/calico.yaml $proxy_registry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment