RikyLee / google_containers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

关于

可以去阿里云镜像仓库市场看看registry.aliyuncs.com/google_containers实际上这个ns是用户创建的。

由于这个ns的所有者同步太慢了,我便写了这个工具来时刻同步

本仓库只同步registry.k8s.io ==> registry.aliyuncs.com/riky_k8s,目前k8s.gcr.io将于2023年4.3冻结,所以目前只同步registry.k8s.io

目前已经同步完了,可以看github action的运行状态

查看镜像列表的话去阿里云镜像仓库市场

登录后在搜索框那输入riky_k8s/搜索即可,也可以看单独的镜像例如riky_k8s/kube-apiserver

特性

  • 不依赖 Docker 运行

  • 同步期间不占用本地磁盘空间(直接通过标准库转发镜像)

  • 可控的并发同步(优雅关闭/可调节并发数量)

  • 可指定拉取对应的镜像

  • 核心拷贝方法引用的containers/image,代码fork自zhangguanzhang/google_containers

  • 利用 boltdb 存储每个镜像 manifest 信息的 crc32 校验值,通过比对判断是否需要同步,而不是每次请求目标仓库

  • 把 boltdb 文件放 docker镜像里存在 dockerhub 上,多次运行 action 来同步

  • 项目根目录下提供repo.json,可用于指定同步对应的镜像,如果不需要删除文件即可,文件内容结构如下

    {
      "child": [
        "k8s-cloud-kms-plugin",
        "k8s-custom-iptables",
        "kube-apiserver",
        "kube-proxy",
        "etcd",
        "kube-controller-manager"
      ],
      "manifest": {},
      "name": "",
      "tags": []
    }

用法

编译的话记得带上tag,关闭CGO

go build -tags=containers_image_openpgp main.go

sync命令是同步的命令,sum是查看boltdb文件的信息

imgsync sync --help

    Sync docker images.

    Usage:
      imgsync sync [flags]

    Flags:
          --addition-ns stringArray    addition ns to sync (default [])
          --command-timeout duration   timeout for the command execution.
          --db string                  the boltdb file (default "bolt.db")
      -h, --help                       help for sync
          --img-timeout duration       sync single image timeout. (default 15m0s)
          --live-interval duration     live output for travis-ci.
          --login-retry uint8          login retry when timeout. (default 2)
      -p, --password string            The password to push.
          --process-limit int          sync process limit. (default 2)
          --push-ns string             the ns push to
          --push-to string             the repo push to (default "docker.io")
          --query-limit int            http query limit. (default 10)
          --retry int                  retry count while err. (default 4)
          --retry-interval duration    retry interval while err. (default 4s)
      -u, --user string                The username to push.

    Global Flags:
          --debug   debug mode

示例

那里设置好环境变量来控制运行的一些属性,也可以把镜像同步到自己的内网仓库上

  ${HOME}/sync/imgsync sync
  --db ${HOME}/sync/bolt.db
  --push-to registry.aliyuncs.com
  --password ${ALIYUN_PASS}
  --push-ns riky_k8s
  --user ${ALIYUN_USER}
  --command-timeout ${TMOUT}
  --process-limit ${PROCESS:=2}
  --img-timeout ${IMG_TMOUT:=10m}
  --live-interval ${LIVE:=9m20s}
  --login-retry ${LOGIN_RETRY:=2}
  --debug=${DEBUG:=false}

About

License:MIT License


Languages

Language:Go 87.7%Language:Shell 10.2%Language:Dockerfile 2.1%