This commit is contained in:
yankay 2021-09-10 12:17:06 +08:00
parent 1e5d20d10b
commit 0729c1729b
1 changed files with 23 additions and 20 deletions

View File

@ -1,12 +1,12 @@
import os import os
REPO_REPLACE_RULE = { REPO_REPLACE_RULE = {
"gcr.io":"gcr-jp.m.daocloud.io", "gcr.io":"gcr-jp.m.daocloud.io",
"k8s.gcr.io":"k8s-gcr-jp.m.daocloud.io", "docker.io":"docker-jp.m.daocloud.io",
"docker.io":"docker-jp.m.daocloud.io", "quay.io":"quay-jp.m.daocloud.io",
"quay.io":"quay-jp.m.daocloud.io", "ghcr.io":"ghcr-jp.m.daocloud.io",
"ghcr.io":"ghcr-jp.m.daocloud.io",
} }
# "k8s.gcr.io":"k8s-gcr-jp.m.daocloud.io",
REGISTRY_PASSWORD = os.environ["REGISTRY_PASSWORD"] REGISTRY_PASSWORD = os.environ["REGISTRY_PASSWORD"]
@ -16,23 +16,26 @@ SKEPO_CMD = "docker run -it quay.io/containers/skopeo:latest"
# SKEPO_CMD = "skepo" # RUN without docker # SKEPO_CMD = "skepo" # RUN without docker
def skepo_sync_cmd(src_img): def skepo_sync_cmd(src_img):
src_img = src_img.strip() src_img = src_img.strip()
dest_img = "/".join(src_img.split("/")[:-1]) dest_img = "/".join(src_img.split("/")[:-1])
cmd = SKEPO_CMD + " sync --src docker --dest %s --dest-tls-verify=false --dest-creds root:%s -f oci %s" %(src_img,REGISTRY_PASSWORD,dest_img) for k,v in REPO_REPLACE_RULE.items():
# print(src_img) dest_img = dest_img.replace(k,v)
# print(dest_img) cmd = SKEPO_CMD + " sync --src docker --dest docker --dest-tls-verify=false --dest-creds root:%s -f oci %s %s" %(REGISTRY_PASSWORD,src_img,dest_img)
# print(cmd) # print(src_img)
return cmd # print(dest_img)
# print(cmd)
return cmd
def main(): def main():
lines = [] lines = []
with open("mirror.txt") as f: with open("mirror.txt") as f:
lines = f.readlines() lines = f.readlines()
sync_cmds = [] sync_cmds = []
for l in lines: for l in lines:
sync_cmds.append(skepo_sync_cmd(l)) sync_cmds.append(skepo_sync_cmd(l))
for c in sync_cmds: for c in sync_cmds:
os.system(c) print(c)
os.system(c)
if __name__ == "__main__": if __name__ == "__main__":
# execute only if run as a script # execute only if run as a script