diff --git a/README.md b/README.md index 752d675..4a50b5e 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,23 @@ incloud mirror.txt TODO +## 安装运行 + +安装 skopeo + + + + +``` + +运行同步程序 + +``` +export REGISTRY_PASSWORD=password #镜像仓库密码 +python scripts/sync-to-jp.py +``` + + ## 最佳实践 * 通过 加速 安装 kubeadm * 通过 加速 运行 artifacthub 上的镜像 \ No newline at end of file diff --git a/scripts/sync-to-jp.py b/scripts/sync-to-jp.py new file mode 100644 index 0000000..0732f3d --- /dev/null +++ b/scripts/sync-to-jp.py @@ -0,0 +1,39 @@ +import os + +REPO_REPLACE_RULE = { + "gcr.io":"gcr-jp.m.daocloud.io", + "k8s.gcr.io":"k8s-gcr-jp.m.daocloud.io", + "docker.io":"docker-jp.m.daocloud.io", + "quay.io":"quay-jp.m.daocloud.io", + "ghcr.io":"ghcr-jp.m.daocloud.io", +} + + +REGISTRY_PASSWORD = os.environ["REGISTRY_PASSWORD"] + + +SKEPO_CMD = "docker run -it quay.io/containers/skopeo:latest" +# SKEPO_CMD = "skepo" # RUN without docker + +def skepo_sync_cmd(src_img): + src_img = src_img.strip() + 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) +# print(src_img) +# print(dest_img) +# print(cmd) + return cmd + +def main(): + lines = [] + with open("mirror.txt") as f: + lines = f.readlines() + sync_cmds = [] + for l in lines: + sync_cmds.append(skepo_sync_cmd(l)) + for c in sync_cmds: + os.system(c) + +if __name__ == "__main__": + # execute only if run as a script + main() \ No newline at end of file