-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazk8spull.sh
51 lines (49 loc) · 1.35 KB
/
azk8spull.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
function azk8spull()
{
image=$1
if [ -z $image ]; then
echo "## azk8spull image name cannot be null."
else
array=(`echo $image | tr '/' ' '` )
domainName=""
repoName=""
imageName=""
if [ ${#array[*]} -eq 3 ]; then
repoName=${array[1]}
imageName=${array[2]}
if [ "${array[0]}"x = "docker.io"x ]; then
domainName="dockerhub.azk8s.cn"
elif [ "${array[0]}"x = "gcr.io"x ]; then
domainName="gcr.azk8s.cn"
elif [ "${array[0]}"x = "quay.io"x ]; then
domainName="quay.azk8s.cn"
else
echo '## azk8spull can not support pulling $image right now.'
fi
elif [ ${#array[*]} -eq 2 ]; then
if [ "${array[0]}"x = "k8s.gcr.io"x ]; then
domainName="gcr.azk8s.cn"
repoName="google_containers"
imageName=${array[1]}
else
domainName="dockerhub.azk8s.cn"
repoName=${array[0]}
imageName=${array[1]}
fi
else
echo '## azk8spull can not support pulling $image right now.'
fi
if [ $domainName != "" ]; then
echo "## azk8spull try to pull image from mirror $domainName/$repoName/$imageName."
docker pull $domainName/$repoName/$imageName
if [ $? -eq 0 ]; then
echo "## azk8spull try to tag $domainName/$repoName/$imageName to $image."
docker tag $domainName/$repoName/$imageName $image
if [ $? -eq 0 ]; then
echo '## azk8spull finish pulling. '
fi
fi
fi
fi
}