Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
23 changes: 16 additions & 7 deletions docker_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,55 @@
import os
import sys

# gcr.io/xxx/yyy:zzz -> gcr.azk8s.cn/xxx/yyy:zzz, for example gcr.io/google_containers/kube-apiserver:v1.14.1
# k8s.gcr.io/xxx:yyy => gcr.io/google-containers/xxx:yyy -> gcr.azk8s.cn/google-containers/xxx:yyy, for example k8s.gcr.io/kube-apiserver:v1.14.1
# quay.io/xxx/yyy:zzz -> quay.azk8s.cn/xxx/yyy:zzz, for example quay.io/coreos/flannel:v0.10.0-amd64
# gcr.io/xxx/yyy:zzz -> gcr.azk8s.cn/xxx/yyy:zzz,
# for example registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.14.1
# k8s.gcr.io/xxx:yyy -> registry.cn-hangzhou.aliyuncs.com/google-containers/xxx:yyy,
# for example k8s.gcr.io/kube-apiserver:v1.14.1
# quay.io/xxx/yyy:zzz -> quay.azk8s.cn/xxx/yyy:zzz,
# for example quay.io/coreos/flannel:v0.10.0-amd64 -- not support for now.

converts = [
{
'prefix': 'gcr.io',
'replace': lambda x: x.replace('gcr.io', 'gcr.azk8s.cn'),
'replace': lambda x: x.replace('gcr.io', 'registry.cn-hangzhou.aliyuncs.com'),
},
{
'prefix': 'k8s.gcr.io',
'replace': lambda x: x.replace('k8s.gcr.io', 'gcr.azk8s.cn/google-containers'),
'replace': lambda x: x.replace('k8s.gcr.io', 'registry.cn-hangzhou.aliyuncs.com/google_containers'),
},
{
'prefix': 'quay.io',
'replace': lambda x: x.replace('quay.io', 'quay.azk8s.cn'),
}
]


def execute_sys_cmd(cmd):
result = os.system(cmd)
if result != 0:
print(cmd + " failed.")
sys.exit(-1)


def usage():
print("Usage: " + sys.argv[0] + " pull ${image}")


if __name__ == "__main__":
if len(sys.argv) != 3:
usage()
sys.exit(-1)

image = sys.argv[2]
imageArray = image.split("/")
newImage = ''

newImage = ''
for cvt in converts:
if imageArray[0] == cvt['prefix']:
newImage = cvt['replace'](image)
# this is a special case: the tag of coredns image on aliyun repo has no "v" prefix.
if imageArray[1] == "coredns":
newImage = newImage.replace("/coredns:v", ":")
break
if newImage:
print("-- pull {image} from {newimage} instead --".format(image=image, newimage=newImage))
Expand Down