├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── porter.md │ └── question.md └── workflows │ └── gcr.io_mirror.yml ├── .gitignore ├── CHANGES.md ├── LICENSE ├── README.md ├── batch-pull-k8s-image.sh ├── go.mod ├── go.sum ├── main.go ├── pull-k8s-image.sh └── rules.yaml /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/porter.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 搬运镜像使用这个模板,别瞎改 3 | about: docker镜像搬运工 4 | title: "[PORTER]" 5 | labels: porter 6 | assignees: '' 7 | 8 | --- 9 | 10 | **为了防止被滥用,目前仅仅支持一次同步一个镜像** 11 | 12 | **Issues 必须带 `porter` label,** 简单来说就是通过模板创建就没问题,别抖机灵自己瞎弄。 13 | 14 | **标题必须为 `[PORTER]镜像名:tag` 的格式,** 例如 15 | - `[PORTER]k8s.gcr.io/federation-controller-manager-arm64:v1.3.1-beta.1` 16 | - `[PORTER]gcr.io/google-containers/federation-controller-manager-arm64:v1.3.1-beta.1` 17 | 18 | **特别的**,如果要指定平台的话 `[PORTER]镜像名:tag|平台类型` 19 | - `[PORTER]busybox:latest|linux/arm64` 20 | - `[PORTER]busybox:latest|linux/arm/v7` 21 | 22 | issues的内容无所谓,可以为空 23 | 24 | 可以参考 [已搬运镜像集锦](https://github.com/anjia0532/gcr.io_mirror/issues?q=is%3Aissue+label%3Aporter+) 25 | 26 | **注意:** 27 | 28 | **>>>>>>>>本项目目前仅支持 gcr.io、k8s.gcr.io、docker.io、registry.k8s.io、quay.io、ghcr.io 镜像<<<<<<<<** -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 问问题用这个模板 3 | about: 问问题专用模板 4 | title: "[QUESTION]" 5 | labels: question 6 | assignees: 'anjia0532' 7 | 8 | --- 9 | -------------------------------------------------------------------------------- /.github/workflows/gcr.io_mirror.yml: -------------------------------------------------------------------------------- 1 | name: gcr.io_mirror 2 | 3 | on: 4 | schedule: 5 | - cron: '0 16 * * *' 6 | issues: 7 | types: [opened, edited] 8 | label: 9 | types: [created] 10 | workflow_dispatch: 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: 检出代码 17 | uses: actions/checkout@v3 18 | 19 | - name: 设置 golang 环境 20 | uses: actions/setup-go@v3 21 | with: 22 | go-version: 1.18 23 | check-latest: true 24 | cache: true 25 | 26 | - name: 运行 go 代码 27 | run: go run main.go --github.token=${{ secrets.GITHUB_TOKEN }} --github.user=${{ github.repository_owner }} --github.repo=${{ github.event.repository.name }} --docker.registry=${{ secrets.DOCKER_REGISTRY }} --docker.namespace=${{ secrets.DOCKER_NAMESPACE }} --docker.user=${{ secrets.DOCKER_USER }} --docker.secret=${{ secrets.DOCKER_PASSWORD }} --github.run_id=${{ github.run_id }} 28 | 29 | auto_close_issues: 30 | runs-on: ubuntu-latest 31 | steps: 32 | - name: check issues 33 | id: check_issues 34 | uses: actions/github-script@v3.1.0 35 | with: 36 | github-token: ${{secrets.GITHUB_TOKEN}} 37 | script: | 38 | const openIssues = await github.issues.listForRepo({ 39 | owner: '${{ github.repository_owner }}', 40 | repo: '${{ github.event.repository.name }}', 41 | state: 'open', 42 | per_page: 100, 43 | sort: "created", 44 | direction: "desc", 45 | }) 46 | 47 | if (!Array.isArray(openIssues["data"]) || !openIssues["data"].length) { 48 | core.setOutput('SUCCESS', true) 49 | return 50 | } 51 | let validLabels=false 52 | for(let issues of openIssues['data']){ 53 | for(let labels of issues["labels"]){ 54 | if(labels["name"]=="porter" || labels["name"]=="question"){ 55 | validLabels=true 56 | } 57 | } 58 | if(validLabels){ 59 | continue 60 | } 61 | await github.issues.createComment({ 62 | owner: '${{ github.repository_owner }}', 63 | repo: '${{ github.event.repository.name }}', 64 | issue_number: issues["number"], 65 | body: "@"+issues["user"]["login"]+" 不是说了嘛,通过模板创建 issues,请通过[此模板](https://github.com/anjia0532/gcr.io_mirror/issues/new?assignees=&labels=porter&template=porter.md&title=%5BPORTER%5D)重新创建,此 issues 将自动关闭" 66 | }); 67 | await github.issues.addLabels({ 68 | owner: '${{ github.repository_owner }}', 69 | repo: '${{ github.event.repository.name }}', 70 | issue_number: issues["number"], 71 | labels: ["rude"] 72 | }); 73 | await github.issues.update({ 74 | owner: '${{ github.repository_owner }}', 75 | repo: '${{ github.event.repository.name }}', 76 | issue_number: issues["number"], 77 | state: 'closed' 78 | }) 79 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ###################### 2 | # Project Specific 3 | ###################### 4 | *.lck 5 | .idea/ -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | ## 2018-11-19 01:27 2 | 3 | [gcr.io/kubeflow-images-public/tensorflow-1.6.0-notebook-gpu:v20180604-b3733835](https://hub.docker.com/r/anjia0532/kubeflow-images-public.tensorflow-1.6.0-notebook-gpu/tags/) 4 | 5 | 6 | [gcr.io/kubeflow-images-public/tensorflow-1.6.0-notebook-gpu:v-base-1c46aec-891](https://hub.docker.com/r/anjia0532/kubeflow-images-public.tensorflow-1.6.0-notebook-gpu/tags/) 7 | 8 | 9 | ## 2018-11-16 12:37 10 | 11 | [gcr.io/cloud-datalab/datalab-gpu:commit-847720b19daebe266c24ee67fb541527bbfd2628](https://hub.docker.com/r/anjia0532/cloud-datalab.datalab-gpu/tags/) 12 | 13 | 14 | [gcr.io/cloud-datalab/datalab-gpu:cloud_datalab_release_20180202_0202_RC00](https://hub.docker.com/r/anjia0532/cloud-datalab.datalab-gpu/tags/) 15 | 16 | 17 | [gcr.io/cloud-datalab/datalab-gpu:cloud_datalab_release_20180106_1615_RC00](https://hub.docker.com/r/anjia0532/cloud-datalab.datalab-gpu/tags/) 18 | 19 | 20 | [gcr.io/cloud-datalab/datalab-gpu:commit-a78ea30f4918bf02bc5a03f034f3a09ffb6ddf60](https://hub.docker.com/r/anjia0532/cloud-datalab.datalab-gpu/tags/) 21 | 22 | 23 | ## 2018-11-09 22:38 24 | 25 | [gcr.io/kubeflow-images-public/tf-model-server-gpu:v20180707-5a11c84d](https://hub.docker.com/r/anjia0532/kubeflow-images-public.tf-model-server-gpu/tags/) 26 | 27 | 28 | [gcr.io/kubeflow-images-public/tf-model-server-gpu:v20180803-4ec73180](https://hub.docker.com/r/anjia0532/kubeflow-images-public.tf-model-server-gpu/tags/) 29 | 30 | 31 | [gcr.io/kubeflow-images-public/tf-model-server-gpu:v20180608-cc3566da](https://hub.docker.com/r/anjia0532/kubeflow-images-public.tf-model-server-gpu/tags/) 32 | 33 | 34 | ## 2018-10-29 09:15 35 | 36 | [gcr.io/google-containers/kube-apiserver-ppc64le:v1.11.4](https://hub.docker.com/r/anjia0532/google-containers.kube-apiserver-ppc64le/tags/) 37 | 38 | 39 | [gcr.io/linkerd-io/cli-bin:git-1eb9d019](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 40 | 41 | 42 | [gcr.io/linkerd-io/proxy:git-c59f43d8](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 43 | 44 | 45 | [gcr.io/linkerd-io/web:git-1eb9d019](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 46 | 47 | 48 | [gcr.io/google-containers/hyperkube-arm:v1.11.4](https://hub.docker.com/r/anjia0532/google-containers.hyperkube-arm/tags/) 49 | 50 | 51 | [gcr.io/spinnaker-marketplace/orca:1.2.0-20181026022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.orca/tags/) 52 | 53 | 54 | [gcr.io/spinnaker-marketplace/deck:2.6.0-20181023163851](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.deck/tags/) 55 | 56 | 57 | [gcr.io/spinnaker-marketplace/kayenta:0.5.0-20181027022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.kayenta/tags/) 58 | 59 | 60 | [gcr.io/linkerd-io/grafana:git-c59f43d8](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 61 | 62 | 63 | [gcr.io/spinnaker-marketplace/igor:0.13.1-20181025141030](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.igor/tags/) 64 | 65 | 66 | [gcr.io/spinnaker-marketplace/fiat:1.2.0-20181026022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.fiat/tags/) 67 | 68 | 69 | [gcr.io/spinnaker-marketplace/front50:0.14.0-20181025141030](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.front50/tags/) 70 | 71 | 72 | [gcr.io/linkerd-io/cli-bin:git-0e91dbb1](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 73 | 74 | 75 | [gcr.io/linkerd-io/controller:master](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 76 | 77 | 78 | [gcr.io/linkerd-io/proxy-init:git-1eb9d019](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 79 | 80 | 81 | [gcr.io/spinnaker-marketplace/orca:1.2.0-20181025022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.orca/tags/) 82 | 83 | 84 | [gcr.io/linkerd-io/proxy:git-1eb9d019](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 85 | 86 | 87 | [gcr.io/spinnaker-marketplace/gate:1.3.0-20181024022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.gate/tags/) 88 | 89 | 90 | [gcr.io/linkerd-io/web:git-148d7bc6](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 91 | 92 | 93 | [gcr.io/linkerd-io/grafana:git-1eb9d019](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 94 | 95 | 96 | [gcr.io/spinnaker-marketplace/deck:2.6.0-20181025141030](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.deck/tags/) 97 | 98 | 99 | [gcr.io/linkerd-io/cli-bin:git-148d7bc6](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 100 | 101 | 102 | [gcr.io/spinnaker-marketplace/kayenta:0.5.0-20181025141030](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.kayenta/tags/) 103 | 104 | 105 | [gcr.io/spinnaker-marketplace/igor:0.14.0-20181026022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.igor/tags/) 106 | 107 | 108 | [gcr.io/linkerd-io/proxy-init:git-0e91dbb1](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 109 | 110 | 111 | [gcr.io/linkerd-io/proxy:git-148d7bc6](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 112 | 113 | 114 | [gcr.io/linkerd-io/controller:git-6cffad27](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 115 | 116 | 117 | [gcr.io/spinnaker-marketplace/front50:0.14.0-20181025022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.front50/tags/) 118 | 119 | 120 | [gcr.io/spinnaker-marketplace/orca:1.2.0-20181023163851](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.orca/tags/) 121 | 122 | 123 | [gcr.io/linkerd-io/web:git-39b80b11](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 124 | 125 | 126 | [gcr.io/linkerd-io/grafana:git-148d7bc6](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 127 | 128 | 129 | [gcr.io/spinnaker-marketplace/gate:1.3.0-20181025141030](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.gate/tags/) 130 | 131 | 132 | [gcr.io/linkerd-io/cli-bin:git-8ed75322](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 133 | 134 | 135 | [gcr.io/linkerd-io/proxy-init:git-148d7bc6](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 136 | 137 | 138 | [gcr.io/linkerd-io/proxy:git-39b80b11](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 139 | 140 | 141 | [gcr.io/spinnaker-marketplace/echo:2.2.0-20181025022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.echo/tags/) 142 | 143 | 144 | [gcr.io/linkerd-io/web:git-58255f56](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 145 | 146 | 147 | [gcr.io/linkerd-io/grafana:git-8ed75322](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 148 | 149 | 150 | [gcr.io/linkerd-io/controller:git-c59f43d8](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 151 | 152 | 153 | [gcr.io/spinnaker-marketplace/orca:1.2.0-20181027022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.orca/tags/) 154 | 155 | 156 | [gcr.io/spinnaker-marketplace/gate:1.3.0-20181024130441](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.gate/tags/) 157 | 158 | 159 | [gcr.io/linkerd-io/proxy-init:git-8ed75322](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 160 | 161 | 162 | [gcr.io/spinnaker-marketplace/halyard:1.12.0-20181023123733](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.halyard/tags/) 163 | 164 | 165 | [gcr.io/linkerd-io/proxy:git-58255f56](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 166 | 167 | 168 | [gcr.io/spinnaker-marketplace/front50:0.14.0-20181026022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.front50/tags/) 169 | 170 | 171 | [gcr.io/linkerd-io/grafana:git-39b80b11](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 172 | 173 | 174 | [gcr.io/linkerd-io/cli-bin:git-39b80b11](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 175 | 176 | 177 | [gcr.io/linkerd-io/web:dev-0e91dbb1-alex](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 178 | 179 | 180 | [gcr.io/spinnaker-marketplace/clouddriver:4.0.1-20181024042809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.clouddriver/tags/) 181 | 182 | 183 | [gcr.io/spinnaker-marketplace/echo:2.2.0-20181024022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.echo/tags/) 184 | 185 | 186 | [gcr.io/linkerd-io/controller:git-1eb9d019](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 187 | 188 | 189 | [gcr.io/linkerd-io/proxy-init:git-39b80b11](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 190 | 191 | 192 | [gcr.io/spinnaker-marketplace/orca:1.2.0-20181023152542](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.orca/tags/) 193 | 194 | 195 | [gcr.io/linkerd-io/proxy:git-b0b30ce7](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 196 | 197 | 198 | [gcr.io/linkerd-io/grafana:git-58255f56](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 199 | 200 | 201 | [gcr.io/spinnaker-marketplace/gate:1.3.0-20181026022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.gate/tags/) 202 | 203 | 204 | [gcr.io/linkerd-io/web:edge-18.10.4](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 205 | 206 | 207 | [gcr.io/k8s-minikube/minikube-e2e:latest](https://hub.docker.com/r/anjia0532/k8s-minikube.minikube-e2e/tags/) 208 | 209 | 210 | [gcr.io/linkerd-io/cli-bin:git-58255f56](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 211 | 212 | 213 | [gcr.io/linkerd-io/proxy-init:git-58255f56](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 214 | 215 | 216 | [gcr.io/spinnaker-marketplace/echo:2.2.0-20181023152542](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.echo/tags/) 217 | 218 | 219 | [gcr.io/linkerd-io/grafana:dev-0e91dbb1-alex](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 220 | 221 | 222 | [gcr.io/linkerd-io/proxy:edge-18.10.4](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 223 | 224 | 225 | [gcr.io/linkerd-io/controller:git-0e91dbb1](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 226 | 227 | 228 | [gcr.io/spinnaker-marketplace/halyard:1.12.0](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.halyard/tags/) 229 | 230 | 231 | [gcr.io/linkerd-io/web:git-1922dc0a](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 232 | 233 | 234 | [gcr.io/linkerd-io/proxy-init:git-b0b30ce7](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 235 | 236 | 237 | [gcr.io/linkerd-io/grafana:edge-18.10.4](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 238 | 239 | 240 | [gcr.io/linkerd-io/cli-bin:dev-0e91dbb1-alex](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 241 | 242 | 243 | [gcr.io/linkerd-io/proxy:git-cf7a532e](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 244 | 245 | 246 | [gcr.io/spinnaker-marketplace/clouddriver:4.1.0-20181027022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.clouddriver/tags/) 247 | 248 | 249 | [gcr.io/linkerd-io/proxy-init:edge-18.10.4](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 250 | 251 | 252 | [gcr.io/linkerd-io/web:git-715e8ff2](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 253 | 254 | 255 | [gcr.io/linkerd-io/grafana:git-1922dc0a](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 256 | 257 | 258 | [gcr.io/linkerd-io/controller:git-148d7bc6](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 259 | 260 | 261 | [gcr.io/linkerd-io/proxy:git-907140bc](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 262 | 263 | 264 | [gcr.io/linkerd-io/cli-bin:git-b0b30ce7](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 265 | 266 | 267 | [gcr.io/linkerd-io/controller:git-8ed75322](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 268 | 269 | 270 | [gcr.io/linkerd-io/web:git-cf7a532e](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 271 | 272 | 273 | [gcr.io/linkerd-io/proxy-init:git-1922dc0a](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 274 | 275 | 276 | [gcr.io/linkerd-io/grafana:git-715e8ff2](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 277 | 278 | 279 | [gcr.io/linkerd-io/proxy:git-d2f847a4](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 280 | 281 | 282 | [gcr.io/linkerd-io/controller:git-39b80b11](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 283 | 284 | 285 | [gcr.io/linkerd-io/cli-bin:edge-18.10.4](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 286 | 287 | 288 | [gcr.io/linkerd-io/web:git-e1671397](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 289 | 290 | 291 | [gcr.io/linkerd-io/proxy-init:git-cf7a532e](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 292 | 293 | 294 | [gcr.io/linkerd-io/grafana:git-cf7a532e](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 295 | 296 | 297 | [gcr.io/linkerd-io/controller:git-58255f56](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 298 | 299 | 300 | [gcr.io/linkerd-io/proxy:git-83333d01](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 301 | 302 | 303 | [gcr.io/spinnaker-marketplace/gradle_cache:latest](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.gradle_cache/tags/) 304 | 305 | 306 | [gcr.io/spinnaker-marketplace/halyard:1.12.0-20181023152542](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.halyard/tags/) 307 | 308 | 309 | [gcr.io/linkerd-io/proxy-init:git-e1671397](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 310 | 311 | 312 | [gcr.io/linkerd-io/web:git-907140bc](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 313 | 314 | 315 | [gcr.io/linkerd-io/grafana:git-907140bc](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 316 | 317 | 318 | [gcr.io/linkerd-io/cli-bin:git-cf7a532e](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 319 | 320 | 321 | [gcr.io/linkerd-io/proxy:git-8393aed0](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 322 | 323 | 324 | [gcr.io/linkerd-io/proxy-init:git-907140bc](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 325 | 326 | 327 | [gcr.io/linkerd-io/controller:dev-0e91dbb1-alex](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 328 | 329 | 330 | [gcr.io/linkerd-io/web:git-d2f847a4](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 331 | 332 | 333 | [gcr.io/linkerd-io/grafana:git-d2f847a4](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 334 | 335 | 336 | [gcr.io/linkerd-io/proxy-init:git-d2f847a4](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 337 | 338 | 339 | [gcr.io/spinnaker-marketplace/clouddriver:4.1.0-20181026022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.clouddriver/tags/) 340 | 341 | 342 | [gcr.io/linkerd-io/grafana:git-83333d01](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 343 | 344 | 345 | [gcr.io/linkerd-io/proxy-init:dev-1922dc0a-alex](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 346 | 347 | 348 | [gcr.io/linkerd-io/cli-bin:git-907140bc](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 349 | 350 | 351 | [gcr.io/linkerd-io/web:git-83333d01](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 352 | 353 | 354 | [gcr.io/linkerd-io/proxy:git-c661b00f](https://hub.docker.com/r/anjia0532/linkerd-io.proxy/tags/) 355 | 356 | 357 | [gcr.io/linkerd-io/proxy-init:git-83333d01](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 358 | 359 | 360 | [gcr.io/linkerd-io/controller:git-b0b30ce7](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 361 | 362 | 363 | [gcr.io/linkerd-io/controller:edge-18.10.4](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 364 | 365 | 366 | [gcr.io/linkerd-io/grafana:git-8393aed0](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 367 | 368 | 369 | [gcr.io/linkerd-io/proxy-init:git-8393aed0](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 370 | 371 | 372 | [gcr.io/linkerd-io/web:git-8393aed0](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 373 | 374 | 375 | [gcr.io/linkerd-io/proxy-init:git-4486d543](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 376 | 377 | 378 | [gcr.io/linkerd-io/cli-bin:git-d2f847a4](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 379 | 380 | 381 | [gcr.io/linkerd-io/grafana:git-4486d543](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 382 | 383 | 384 | [gcr.io/linkerd-io/proxy-init:git-c661b00f](https://hub.docker.com/r/anjia0532/linkerd-io.proxy-init/tags/) 385 | 386 | 387 | [gcr.io/linkerd-io/web:git-c661b00f](https://hub.docker.com/r/anjia0532/linkerd-io.web/tags/) 388 | 389 | 390 | [gcr.io/linkerd-io/grafana:git-c661b00f](https://hub.docker.com/r/anjia0532/linkerd-io.grafana/tags/) 391 | 392 | 393 | [gcr.io/linkerd-io/controller:git-cf7a532e](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 394 | 395 | 396 | [gcr.io/linkerd-io/cli-bin:git-83333d01](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 397 | 398 | 399 | [gcr.io/linkerd-io/controller:git-907140bc](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 400 | 401 | 402 | [gcr.io/linkerd-io/cli-bin:git-8393aed0](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 403 | 404 | 405 | [gcr.io/spinnaker-marketplace/clouddriver:4.0.2-20181026042809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.clouddriver/tags/) 406 | 407 | 408 | [gcr.io/linkerd-io/controller:git-d2f847a4](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 409 | 410 | 411 | [gcr.io/linkerd-io/cli-bin:git-4486d543](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 412 | 413 | 414 | [gcr.io/linkerd-io/controller:git-83333d01](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 415 | 416 | 417 | [gcr.io/linkerd-io/cli-bin:git-c661b00f](https://hub.docker.com/r/anjia0532/linkerd-io.cli-bin/tags/) 418 | 419 | 420 | [gcr.io/linkerd-io/controller:git-8393aed0](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 421 | 422 | 423 | [gcr.io/linkerd-io/controller:git-4486d543](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 424 | 425 | 426 | [gcr.io/linkerd-io/controller:git-c661b00f](https://hub.docker.com/r/anjia0532/linkerd-io.controller/tags/) 427 | 428 | 429 | [gcr.io/spinnaker-marketplace/clouddriver:4.1.0-20181025141030](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.clouddriver/tags/) 430 | 431 | 432 | [gcr.io/spinnaker-marketplace/clouddriver:4.1.0-20181025022809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.clouddriver/tags/) 433 | 434 | 435 | [gcr.io/spinnaker-marketplace/clouddriver:4.0.2-20181027042809](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.clouddriver/tags/) 436 | 437 | 438 | [gcr.io/spinnaker-marketplace/clouddriver:4.1.0-20181023163851](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.clouddriver/tags/) 439 | 440 | 441 | [gcr.io/spinnaker-marketplace/clouddriver:4.1.0-20181023123733](https://hub.docker.com/r/anjia0532/spinnaker-marketplace.clouddriver/tags/) 442 | 443 | 444 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 AnJia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Google Container Registry Mirror(Google Container Registry镜像加速) 2 | ------- 3 | 4 | Disclaimer/免责声明 5 | ------- 6 | 本人郑重承诺 7 | 1. 本项目不以盈利为目的,过去,现在,未来都不会用于牟利。 8 | 2. 本项目不承诺永久可用(比如包括但不限于 DockerHub 关闭,或者 DockerHub 修改免费计划限制个人免费镜像数量,Github 主动关闭本项目,Github Action 免费计划修改),但会承诺尽量做到向后兼容(也就是后续有新的扩展 Registry 不会改动原有规则导致之前的不可用)。 9 | 3. 本项目不承诺所转存的镜像是安全可靠的,本项目只做转存(从上游 Registry pull 镜像,重新打tag,推送到目标 Registry(本项目是推到 Docker hub , 可以通过 Fork 到自己仓库改成私有 Registry)),不会进行修改(但是转存后的摘要和上游摘要不相同,这是正常的(因为镜像名字变了)),但是如果上游本身就是恶意镜像,那么转存后仍然是恶意镜像。目前支持的 `gcr.io` , `k8s.gcr.io` , `registry.k8s.io` , `quay.io`, `ghcr.io` 好像都是支持个人上传镜像的,在使用镜像前,请自行确认上游是否可靠,应自行避免供应链攻击。 10 | 4. 对于 DockerHub 和 Github 某些策略修改导致的 不可预知且不可控因素等导致业务无法拉取镜像而造成损失的,本项目不承担责任。 11 | 5. 对于上游恶意镜像或者上游镜像依赖库版本低导致的安全风险 本项目无法识别,删除,停用,过滤,要求使用者自行甄别,本项目不承担责任。 12 | 13 | 如果不认可上面所述,请不要使用本项目,一旦使用,则视为同意。 14 | 15 | Syntax/语法 16 | ------- 17 | 18 | ```bash 19 | # origin / 原镜像名称 20 | gcr.io/namespace/{image}:{tag} 21 | 22 | # eq / 等同于 23 | anjia0532/namespace.{image}:{tag} 24 | 25 | # special / 特别的 26 | k8s.gcr.io/{image}:{tag} <==> gcr.io/google-containers/{image}:{tag} <==> anjia0532/google-containers.{image}:{tag} 27 | 28 | wget https://raw.githubusercontent.com/anjia0532/gcr.io_mirror/master/pull-k8s-image.sh 29 | chmod +x pull-k8s-image.sh 30 | 31 | ./pull-k8s-image.sh k8s.gcr.io/federation-controller-manager-arm64:v1.3.1-beta.1 32 | # 执行如下操作 33 | # docker pull anjia0532/google-containers.federation-controller-manager-arm64:v1.3.1-beta.1 34 | # docker tag anjia0532/google-containers.federation-controller-manager-arm64:v1.3.1-beta.1 k8s.gcr.io/federation-controller-manager-arm64:v1.3.1-beta.1 35 | ``` 36 | 37 | Uses/如何拉取新镜像 38 | ------- 39 | [创建issues(直接套用模板即可,别自己瞎改labels)](https://github.com/anjia0532/gcr.io_mirror/issues/new?assignees=&labels=porter&template=porter.md&title=%5BPORTER%5D) ,将自动触发 github actions 进行拉取转推到docker hub 40 | 41 | **注意:** 42 | 43 | **为了防止被滥用,目前仅仅支持一次同步一个镜像** 44 | 45 | **Issues 必须带 `porter` label,** 简单来说就是通过模板创建就没问题,别抖机灵自己瞎弄。 46 | 47 | **标题必须为 `[PORTER]镜像名:tag` 的格式,** 例如 48 | - `[PORTER]k8s.gcr.io/federation-controller-manager-arm64:v1.3.1-beta.1` 49 | - `[PORTER]gcr.io/google-containers/federation-controller-manager-arm64:v1.3.1-beta.1` 50 | 51 | **特别的**,如果要指定平台的话 `[PORTER]镜像名:tag|平台类型` 52 | - `[PORTER]busybox:latest|linux/arm64` 53 | - `[PORTER]busybox:latest|linux/arm/v7` 54 | 55 | issues的内容无所谓,可以为空 56 | 57 | 可以参考 [已搬运镜像集锦](https://github.com/anjia0532/gcr.io_mirror/issues?q=is%3Aissue+label%3Aporter+) 58 | 59 | **注意:** 60 | 61 | 本项目目前仅支持 `gcr.io` , `k8s.gcr.io` , `registry.k8s.io` , `quay.io`, `ghcr.io` 镜像,其余镜像源可以提 Issues 反馈或者自己 Fork 一份,修改 `rules.yaml` 62 | 63 | 64 | Fork/分叉代码自行维护 65 | ------- 66 | 67 | - 必须: 点击连接在自己账号下分叉出 `gcr.io_mirror` 项目 68 | - 可选: 修改 [./rules.yaml](./rules.yaml) 增加暂未支持的镜像库 69 | - 在 [./settings/actions](../../settings/actions) 的 `Workflow permissions` 选项中,授予读写权限 70 | - 在 [./settings/secrets/actions](../../settings/secrets/actions) 创建自己的参数 71 | - 随便新建个issues,然后在右侧创建个名为 `porter` 和 `question` 的 label,后续通过模板创建时会自动带上。 详见 https://github.com/anjia0532/gcr.io_mirror/issues/3893 72 | 73 | `DOCKER_REGISTRY`: 如果推到 docker hub 为空即可 74 | 75 | `DOCKER_NAMESPACE`: 如果推到 docker hub ,则是自己的 docker hub 账号(不带@email部分),例如我的 anjia0532 76 | 77 | `DOCKER_USER`: 如果推到 docker hub,则是 docker hub 账号(不带@email部分),例如我的 anjia0532 78 | 79 | `DOCKER_PASSWORD`: 如果推到 docker hub,则是 docker hub 密码 80 | 81 | k8s.gcr.io 和 gcr.io 镜像tags 82 | ------ 83 | ```bash 84 | 85 | # k8s.gcr.io 86 | # 可以通过浏览器打开或者curl等打开(需梯子) 87 | # e.g. https://k8s.gcr.io/v2/sig-storage/nfs-subdir-external-provisioner/tags/list 88 | https://k8s.gcr.io/v2/${namespace}/${image}/tags/list 89 | 90 | # 也可以直接用浏览打开看 UI 版的(需梯子) 91 | # e.g. web ui https://console.cloud.google.com/gcr/images/k8s-artifacts-prod/us/sig-storage/nfs-subdir-external-provisioner 92 | https://console.cloud.google.com/gcr/images/k8s-artifacts-prod/us/${namespace}/${image} 93 | 94 | # gcr.io 95 | # 可以通过浏览器打开或者curl等打开(需梯子) 96 | # e.g. https://gcr.io/v2/gloo-mesh/cert-agent/tags/list 97 | https://gcr.io/v2/${namespace}/${image}/tags/list 98 | 99 | # e.g. web ui https://console.cloud.google.com/gcr/images/etcd-development/global/etcd 100 | # 也可以直接用浏览打开看 UI 版的(需梯子) 101 | https://console.cloud.google.com/gcr/images/${namespace}/global/${image} 102 | 103 | # docker hub 104 | # e.g. https://registry.hub.docker.com/v1/repositories/anjia0532/google-containers.sig-storage.nfs-subdir-external-provisioner/tags 105 | https://registry.hub.docker.com/v1/repositories/${namespace}/${image}/tags 106 | 107 | ``` 108 | 109 | ReTag anjia0532 images to gcr.io/ 将加速下载的镜像重命名为gcr.io 110 | ------- 111 | 112 | ### 批量拉取并转换镜像 113 | 114 | ```shell 115 | sudo tee -a img.txt > /dev/null < gcr.io/google-containers/{image}/{tag} <==> anjia0532/google-containers.{image}/{tag} 132 | 133 | images=$(cat img.txt) 134 | 135 | # 或者 136 | #images=$(cat < gcr.io/google-containers/{image}/{tag} <==> anjia0532/google-containers.{image}/{tag} 152 | 153 | for img in $(sudo docker images --format "{{.Repository}}:{{.Tag}}"| grep "anjia0532"); do 154 | n=$(echo ${img}| awk -F'[/.:]' '{printf "gcr.io/%s",$2}') 155 | image=$(echo ${img}| awk -F'[/.:]' '{printf "/%s",$3}') 156 | tag=$(echo ${img}| awk -F'[:]' '{printf ":%s",$2}') 157 | sudo docker tag $img "${n}${image}${tag}" 158 | [[ ${n} == "gcr.io/google-containers" ]] && sudo docker tag $img "k8s.gcr.io${image}${tag}" 159 | done 160 | ``` 161 | 162 | ### 拉取并转换单个镜像 163 | ```shell 164 | # chmod +x pull-k8s-images.sh 165 | cat pull-k8s-images.sh 166 | # 代码如下 ↓↓↓ 167 | ``` 168 | 169 | ```shell 170 | #!/bin/sh 171 | 172 | k8s_img=$1 173 | mirror_img=$(echo ${k8s_img}| 174 | sed 's/k8s\.gcr\.io/anjia0532\/google-containers/g;s/gcr\.io/anjia0532/g;s/\//\./g;s/ /\n/g;s/anjia0532\./anjia0532\//g' | 175 | uniq) 176 | 177 | sudo docker pull ${mirror_img} 178 | sudo docker tag ${mirror_img} ${k8s_img} 179 | ``` 180 | 181 | Copyright and License 182 | --- 183 | 184 | This module is licensed under the BSD license. 185 | 186 | Copyright (C) 2017-, by AnJia . 187 | 188 | All rights reserved. 189 | 190 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 191 | 192 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 193 | 194 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 195 | 196 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 197 | -------------------------------------------------------------------------------- /batch-pull-k8s-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 替换 gcr.io/google-containers/federation-controller-manager-arm64:v1.3.1-beta.1 为真实 image 4 | # 将会把 gcr.io/google-containers/federation-controller-manager-arm64:v1.3.1-beta.1 转换为 anjia0532/google-containers.federation-controller-manager-arm64:v1.3.1-beta.1 并且会拉取他 5 | # k8s.gcr.io/{image}/{tag} <==> gcr.io/google-containers/{image}/{tag} <==> anjia0532/google-containers.{image}/{tag} 6 | 7 | images=$(cat img.txt) 8 | 9 | # 或者 10 | #images=$(cat < gcr.io/google-containers/{image}/{tag} <==> anjia0532/google-containers.{image}/{tag} 26 | 27 | for img in $(sudo docker images --format "{{.Repository}}:{{.Tag}}"| grep "anjia0532"); do 28 | n=$(echo ${img}| awk -F'[/.:]' '{printf "gcr.io/%s",$2}') 29 | image=$(echo ${img}| awk -F'[/.:]' '{printf "/%s",$3}') 30 | tag=$(echo ${img}| awk -F'[:]' '{printf ":%s",$2}') 31 | sudo docker tag $img "${n}${image}${tag}" 32 | [[ ${n} == "gcr.io/google-containers" ]] && sudo docker tag $img "k8s.gcr.io${image}${tag}" 33 | [[ ${n} == "gcr.io/google-containers" ]] && sudo docker tag $img "registry.k8s.io${image}${tag}" 34 | done 35 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module image-mirror 2 | 3 | go 1.20 4 | 5 | require ( 6 | github.com/docker/docker v20.10.17+incompatible 7 | github.com/google/go-github/v47 v47.0.0 8 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be 9 | gopkg.in/alecthomas/kingpin.v2 v2.2.6 10 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c 11 | ) 12 | 13 | require ( 14 | github.com/Microsoft/go-winio v0.5.2 // indirect 15 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect 16 | github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect 17 | github.com/docker/distribution v2.8.1+incompatible // indirect 18 | github.com/docker/go-connections v0.4.0 // indirect 19 | github.com/docker/go-units v0.5.0 // indirect 20 | github.com/gogo/protobuf v1.3.2 // indirect 21 | github.com/golang/protobuf v1.3.2 // indirect 22 | github.com/google/go-querystring v1.1.0 // indirect 23 | github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect 24 | github.com/morikuni/aec v1.0.0 // indirect 25 | github.com/opencontainers/go-digest v1.0.0 // indirect 26 | github.com/opencontainers/image-spec v1.0.2 // indirect 27 | github.com/pkg/errors v0.9.1 // indirect 28 | github.com/sirupsen/logrus v1.9.0 // indirect 29 | golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect 30 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect 31 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect 32 | golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect 33 | google.golang.org/appengine v1.6.7 // indirect 34 | gotest.tools/v3 v3.3.0 // indirect 35 | ) 36 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= 2 | github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= 3 | github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= 4 | github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= 5 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= 6 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 7 | github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc= 8 | github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= 9 | github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 10 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 11 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 12 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= 14 | github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= 15 | github.com/docker/docker v20.10.17+incompatible h1:JYCuMrWaVNophQTOrMMoSwudOVEfcegoZZrleKc1xwE= 16 | github.com/docker/docker v20.10.17+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= 17 | github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= 18 | github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= 19 | github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= 20 | github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= 21 | github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= 22 | github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= 23 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 24 | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= 25 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 26 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 27 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 28 | github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 29 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 30 | github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= 31 | github.com/google/go-github/v47 v47.0.0 h1:eQap5bIRZibukP0VhngWgpuM0zhY4xntqOzn6DhdkE4= 32 | github.com/google/go-github/v47 v47.0.0/go.mod h1:DRjdvizXE876j0YOZwInB1ESpOcU/xFBClNiQLSdorE= 33 | github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= 34 | github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= 35 | github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= 36 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 37 | github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae h1:O4SWKdcHVCvYqyDV+9CJA1fcDN2L11Bule0iFy3YlAI= 38 | github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw= 39 | github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= 40 | github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= 41 | github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= 42 | github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= 43 | github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= 44 | github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= 45 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 46 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 47 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 48 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 49 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 50 | github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= 51 | github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= 52 | github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 53 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 54 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 55 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 56 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 57 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 58 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 59 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 60 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 61 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 62 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 63 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 64 | golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= 65 | golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 66 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 67 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 68 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 69 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 70 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 71 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 72 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 73 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 74 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= 75 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 76 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= 77 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 78 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 79 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 80 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 81 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 82 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 83 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 84 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 85 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 86 | golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 87 | golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 88 | golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 89 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= 90 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 91 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 92 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 93 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 94 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 95 | golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 h1:ftMN5LMiBFjbzleLqtoBZk7KdJwhuybIU+FckUHgoyQ= 96 | golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 97 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 98 | golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 99 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 100 | golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 101 | golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 102 | golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= 103 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 104 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 105 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 106 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 107 | google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= 108 | google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 109 | gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= 110 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 111 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 112 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 113 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 114 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 115 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 116 | gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= 117 | gotest.tools/v3 v3.3.0 h1:MfDY1b1/0xN1CyMlQDac0ziEy9zJQd9CXBRRDHw2jJo= 118 | gotest.tools/v3 v3.3.0/go.mod h1:Mcr9QNxkg0uMvy/YElmo4SpXgJKWgQvYrT7Kw5RzJ1A= 119 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "encoding/base64" 7 | "encoding/json" 8 | "errors" 9 | "fmt" 10 | "github.com/docker/docker/api/types" 11 | "github.com/docker/docker/client" 12 | "github.com/google/go-github/v47/github" 13 | "golang.org/x/oauth2" 14 | "gopkg.in/alecthomas/kingpin.v2" 15 | "gopkg.in/yaml.v3" 16 | "io" 17 | "os" 18 | "regexp" 19 | "strings" 20 | "text/template" 21 | ) 22 | 23 | var resultTpl = ` 24 | {{ if .Success }} 25 | **转换完成** 26 | ^^^bash 27 | {{ if .Registry }} 28 | docker login -u{{ .RegistryUser }} {{ .Registry }} 29 | {{ end }} 30 | #原镜像 31 | {{ .OriginImageName }} 32 | 33 | #转换后镜像 34 | {{ .TargetImageName }} 35 | 36 | 37 | #下载并重命名镜像 38 | docker pull {{ .TargetImageName }} {{ if .Platform }} --platform {{ .Platform }} {{ end }} 39 | 40 | docker tag {{ .TargetImageName }} {{ index (split .OriginImageName "@") 0 }} 41 | 42 | docker images | grep $(echo {{ .OriginImageName }} |awk -F':' '{print $1}') 43 | 44 | ^^^ 45 | {{ else }} 46 | **转换失败** 47 | 详见 [构建任务](https://github.com/{{ .GhUser }}/{{ .Repo }}/actions/runs/{{ .RunId }}) 48 | {{ end }} 49 | ` 50 | 51 | func main() { 52 | ctx := context.Background() 53 | 54 | var ( 55 | ghToken = kingpin.Flag("github.token", "Github token.").Short('t').String() 56 | ghUser = kingpin.Flag("github.user", "Github Owner.").Short('u').String() 57 | ghRepo = kingpin.Flag("github.repo", "Github Repo.").Short('p').String() 58 | registry = kingpin.Flag("docker.registry", "Docker Registry.").Short('r').Default("").String() 59 | registryNamespace = kingpin.Flag("docker.namespace", "Docker Registry Namespace.").Short('n').String() 60 | registryUserName = kingpin.Flag("docker.user", "Docker Registry User.").Short('a').String() 61 | registryPassword = kingpin.Flag("docker.secret", "Docker Registry Password.").Short('s').String() 62 | runId = kingpin.Flag("github.run_id", "Github Run Id.").Short('i').String() 63 | ) 64 | kingpin.HelpFlag.Short('h') 65 | kingpin.Parse() 66 | 67 | config := &Config{ 68 | GhToken: *ghToken, 69 | GhUser: *ghUser, 70 | Repo: *ghRepo, 71 | Registry: *registry, 72 | RegistryNamespace: *registryNamespace, 73 | RegistryUserName: *registryUserName, 74 | RegistryPassword: *registryPassword, 75 | RunId: *runId, 76 | Rules: map[string]string{ 77 | "^gcr.io": "", 78 | "^docker.io": "docker", 79 | "^k8s.gcr.io": "google-containers", 80 | "^registry.k8s.io": "google-containers", 81 | "^quay.io": "quay", 82 | "^ghcr.io": "ghcr", 83 | }, 84 | } 85 | 86 | rulesFile, err := os.ReadFile("rules.yaml") 87 | if err == nil { 88 | rules := make(map[string]string) 89 | err2 := yaml.Unmarshal(rulesFile, &rules) 90 | if err2 == nil { 91 | config.Rules = rules 92 | } 93 | } 94 | 95 | ts := oauth2.StaticTokenSource( 96 | &oauth2.Token{AccessToken: config.GhToken}, 97 | ) 98 | tc := oauth2.NewClient(ctx, ts) 99 | 100 | cli := github.NewClient(tc) 101 | 102 | issues, err := getIssues(cli, ctx, config) 103 | if err != nil { 104 | fmt.Println("查询 Issues 报错,", err.Error()) 105 | os.Exit(-1) 106 | } 107 | if len(issues) == 0 { 108 | fmt.Println("暂无需要搬运的镜像") 109 | os.Exit(0) 110 | } 111 | 112 | // 可以用协程,但是懒得写 113 | issue := issues[0] 114 | 115 | fmt.Println("添加 构建进展 Comment") 116 | commentIssues(issue, cli, ctx, "[构建进展](https://github.com/"+config.GhUser+"/"+config.Repo+"/actions/runs/"+config.RunId+")") 117 | err, originImageName, targetImageName, platform := mirrorByIssues(issue, config) 118 | if err != nil { 119 | commentErr := commentIssues(issue, cli, ctx, err.Error()) 120 | if commentErr != nil { 121 | fmt.Println("提交 comment 报错", commentErr) 122 | } 123 | } 124 | 125 | result := struct { 126 | Success bool 127 | Registry string 128 | RegistryUser string 129 | OriginImageName string 130 | TargetImageName string 131 | Platform string 132 | GhUser string 133 | Repo string 134 | RunId string 135 | }{ 136 | Success: err == nil, 137 | Registry: config.Registry, 138 | RegistryUser: config.RegistryUserName, 139 | OriginImageName: originImageName, 140 | TargetImageName: targetImageName, 141 | Platform: platform, 142 | GhUser: *ghUser, 143 | Repo: *ghRepo, 144 | RunId: *runId, 145 | } 146 | 147 | var buf bytes.Buffer 148 | funcmap := template.FuncMap{ 149 | "split": strings.Split, 150 | } 151 | tmpl, err := template.New("result").Funcs(funcmap).Parse(resultTpl) 152 | err = tmpl.Execute(&buf, &result) 153 | 154 | fmt.Println("添加 转换结果 Comment") 155 | res := buf.String() 156 | 157 | commentIssues(issue, cli, ctx, strings.ReplaceAll(res, "^", "`")) 158 | 159 | fmt.Println("添加 转换结果 Label") 160 | var labels []string 161 | if len(platform) > 0 { 162 | labels = append(labels, "platform") 163 | } 164 | issuesAddLabels(issue, cli, ctx, result.Success, labels) 165 | 166 | fmt.Println("关闭 Issues") 167 | issuesClose(issue, cli, ctx) 168 | } 169 | 170 | func issuesClose(issues *github.Issue, cli *github.Client, ctx context.Context) { 171 | names := strings.Split(*issues.RepositoryURL, "/") 172 | state := "closed" 173 | cli.Issues.Edit(ctx, names[len(names)-2], names[len(names)-1], issues.GetNumber(), &github.IssueRequest{ 174 | State: &state, 175 | }) 176 | } 177 | func issuesAddLabels(issues *github.Issue, cli *github.Client, ctx context.Context, success bool, labels []string) { 178 | names := strings.Split(*issues.RepositoryURL, "/") 179 | label := "success" 180 | if !success { 181 | label = "failed" 182 | } 183 | if labels == nil { 184 | labels = []string{label} 185 | } else { 186 | labels = append(labels, label) 187 | } 188 | 189 | cli.Issues.AddLabelsToIssue(ctx, names[len(names)-2], names[len(names)-1], issues.GetNumber(), labels) 190 | } 191 | func commentIssues(issues *github.Issue, cli *github.Client, ctx context.Context, comment string) error { 192 | names := strings.Split(*issues.RepositoryURL, "/") 193 | _, _, err := cli.Issues.CreateComment(ctx, names[len(names)-2], names[len(names)-1], issues.GetNumber(), &github.IssueComment{ 194 | Body: &comment, 195 | }) 196 | return err 197 | } 198 | 199 | func mirrorByIssues(issues *github.Issue, config *Config) (err error, originImageName string, targetImageName string, platform string) { 200 | // 去掉前缀 [PORTER] 整体去除前后空格 201 | originImageName = strings.TrimSpace(strings.Replace(*issues.Title, "[PORTER]", "", 1)) 202 | names := strings.Split(originImageName, "|") 203 | 204 | originImageName = names[0] 205 | if len(names) > 1 { 206 | platform = names[1] 207 | } 208 | 209 | if strings.Index(originImageName, ".") > strings.Index(originImageName, "/") { 210 | originImageName = "docker.io/" + originImageName 211 | } 212 | 213 | targetImageName = originImageName 214 | 215 | if strings.ContainsAny(originImageName, "@") { 216 | targetImageName = strings.Split(originImageName, "@")[0] 217 | } 218 | 219 | registrys := []string{} 220 | 221 | for k, v := range config.Rules { 222 | targetImageName = regexp.MustCompile(k).ReplaceAllString(targetImageName, v) 223 | registrys = append(registrys, k) 224 | } 225 | 226 | if strings.EqualFold(targetImageName, originImageName) { 227 | return errors.New("@" + *issues.GetUser().Login + " 暂不支持同步" + originImageName + ",目前仅支持同步 `" + strings.Join(registrys, " ,") + "`镜像"), originImageName, targetImageName, platform 228 | } 229 | 230 | targetImageName = strings.ReplaceAll(targetImageName, "/", ".") 231 | 232 | if len(config.RegistryNamespace) > 0 { 233 | targetImageName = config.RegistryNamespace + "/" + targetImageName 234 | } 235 | if len(config.Registry) > 0 { 236 | targetImageName = config.Registry + "/" + targetImageName 237 | } 238 | fmt.Println("source:", originImageName, " , target:", targetImageName) 239 | 240 | //execCmd("docker", "login", config.Registry, "-u", config.RegistryUserName, "-p", config.RegistryPassword) 241 | cli, ctx, err := dockerLogin(config) 242 | if err != nil { 243 | return errors.New("@" + config.GhUser + " ,docker login 报错 `" + err.Error() + "`"), originImageName, targetImageName, platform 244 | } 245 | 246 | //execCmd("docker", "pull", originImageName) 247 | err = dockerPull(originImageName, platform, cli, ctx) 248 | 249 | if err != nil { 250 | return errors.New("@" + *issues.GetUser().Login + " ,docker pull 报错 `" + err.Error() + "`"), originImageName, targetImageName, platform 251 | } 252 | 253 | //execCmd("docker", "tag", originImageName, targetImageName) 254 | err = dockerTag(originImageName, targetImageName, cli, ctx) 255 | if err != nil { 256 | return errors.New("@" + *issues.GetUser().Login + " ,docker tag 报错 `" + err.Error() + "`"), originImageName, targetImageName, platform 257 | } 258 | 259 | //execCmd("docker", "push", targetImageName) 260 | err = dockerPush(targetImageName, platform, cli, ctx, config) 261 | if err != nil { 262 | return errors.New("@" + *issues.GetUser().Login + " ,docker push 报错 `" + err.Error() + "`"), originImageName, targetImageName, platform 263 | } 264 | 265 | return nil, originImageName, targetImageName, platform 266 | } 267 | 268 | func dockerLogin(config *Config) (*client.Client, context.Context, error) { 269 | cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) 270 | if err != nil { 271 | return nil, nil, err 272 | } 273 | fmt.Println("docker login, server: ", config.Registry, " user: ", config.RegistryUserName, ", password: ***") 274 | authConfig := types.AuthConfig{ 275 | Username: config.RegistryUserName, 276 | Password: config.RegistryPassword, 277 | ServerAddress: config.Registry, 278 | } 279 | ctx := context.Background() 280 | _, err = cli.RegistryLogin(ctx, authConfig) 281 | if err != nil { 282 | return nil, nil, err 283 | } 284 | return cli, ctx, nil 285 | } 286 | func dockerPull(originImageName string, platform string, cli *client.Client, ctx context.Context) error { 287 | fmt.Println("docker pull ", originImageName) 288 | pullOut, err := cli.ImagePull(ctx, originImageName, types.ImagePullOptions{ 289 | Platform: platform, 290 | }) 291 | if err != nil { 292 | return err 293 | } 294 | defer pullOut.Close() 295 | io.Copy(os.Stdout, pullOut) 296 | return nil 297 | } 298 | func dockerTag(originImageName string, targetImageName string, cli *client.Client, ctx context.Context) error { 299 | fmt.Println("docker tag ", originImageName, " ", targetImageName) 300 | err := cli.ImageTag(ctx, originImageName, targetImageName) 301 | return err 302 | } 303 | func dockerPush(targetImageName string, platform string, cli *client.Client, ctx context.Context, config *Config) error { 304 | fmt.Println("docker push ", targetImageName) 305 | authConfig := types.AuthConfig{ 306 | Username: config.RegistryUserName, 307 | Password: config.RegistryPassword, 308 | } 309 | if len(config.Registry) > 0 { 310 | authConfig.ServerAddress = config.Registry 311 | } 312 | encodedJSON, err := json.Marshal(authConfig) 313 | if err != nil { 314 | return err 315 | } 316 | authStr := base64.URLEncoding.EncodeToString(encodedJSON) 317 | 318 | pushOut, err := cli.ImagePush(ctx, targetImageName, types.ImagePushOptions{ 319 | RegistryAuth: authStr, 320 | Platform: platform, 321 | }) 322 | if err != nil { 323 | return err 324 | } 325 | defer pushOut.Close() 326 | io.Copy(os.Stdout, pushOut) 327 | return nil 328 | } 329 | 330 | type Config struct { 331 | GhToken string `yaml:"gh_token"` 332 | GhUser string `yaml:"gh_user"` 333 | Repo string `yaml:"repo"` 334 | Registry string `yaml:"registry"` 335 | RegistryNamespace string `yaml:"registry_namespace"` 336 | RegistryUserName string `yaml:"registry_user_name"` 337 | RegistryPassword string `yaml:"registry_password"` 338 | Rules map[string]string `yaml:"rules"` 339 | RunId string `yaml:"run_id"` 340 | } 341 | 342 | func getIssues(cli *github.Client, ctx context.Context, config *Config) ([]*github.Issue, error) { 343 | issues, _, err := cli.Issues.ListByRepo(ctx, config.GhUser, config.Repo, &github.IssueListByRepoOptions{ 344 | //State: "closed", 345 | State: "open", 346 | Labels: []string{"porter"}, 347 | Sort: "created", 348 | Direction: "desc", 349 | // 防止被滥用,每次最多只能拉20条,虽然可以递归,但是没必要。 350 | //ListOptions: github.ListOptions{Page: 1, PerPage: 20}, 351 | // 考虑了下,每次还是只允许转一个吧 352 | ListOptions: github.ListOptions{Page: 1, PerPage: 1}, 353 | }) 354 | return issues, err 355 | } 356 | -------------------------------------------------------------------------------- /pull-k8s-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | k8s_img=$1 4 | mirror_img=$(echo ${k8s_img}| 5 | sed 's/quay\.io/anjia0532\/quay/g;s/ghcr\.io/anjia0532\/ghcr/g;s/registry\.k8s\.io/anjia0532\/google-containers/g;s/k8s\.gcr\.io/anjia0532\/google-containers/g;s/gcr\.io/anjia0532/g;s/\//\./g;s/ /\n/g;s/anjia0532\./anjia0532\//g' | 6 | uniq) 7 | 8 | if [ -x "$(command -v docker)" ]; then 9 | sudo docker pull ${mirror_img} 10 | sudo docker tag ${mirror_img} ${k8s_img} 11 | exit 0 12 | fi 13 | 14 | if [ -x "$(command -v ctr)" ]; then 15 | sudo ctr -n k8s.io image pull docker.io/${mirror_img} 16 | sudo ctr -n k8s.io image tag docker.io/${mirror_img} ${k8s_img} 17 | exit 0 18 | fi 19 | 20 | echo "command not found:docker or ctr" 21 | -------------------------------------------------------------------------------- /rules.yaml: -------------------------------------------------------------------------------- 1 | "^gcr.io/": "" 2 | "^k8s.gcr.io": "google-containers" 3 | "^registry.k8s.io": "google-containers" 4 | "^quay.io": "quay" 5 | "^ghcr.io": "ghcr" 6 | "^docker.io": "docker" --------------------------------------------------------------------------------