Name | dock-worker JSON |
Version |
0.0.0
JSON |
| download |
home_page | None |
Summary | Fork Docker images between registries using GitHub Actions |
upload_time | 2025-01-22 09:12:15 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | None |
keywords |
docker
github-actions
registry
cli
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Docker Images Pusher
使用Github Action将国外的Docker镜像转存到阿里云私有仓库,供国内服务器使用,免费易用<br>
- 支持DockerHub, gcr.io, k8s.io, ghcr.io等任意仓库<br>
- 支持最大40GB的大型镜像<br>
- 使用阿里云的官方线路,速度快<br>
---
## leo03w 20240830
新增 `api_hook.yaml` 带参workflow, 支持api方式启动github action, 可传 `原始镜像地址` 和 `目的镜像地址` 两个参数
- 支持 `streamlit` 形式提供web界面
- 支持 `cli.py` 命令行工具调用
## 使用方式
```bash
pip install .
```
```bash
export github_token=your_token
```
```bash
docker-image-forker --help
```
### 配置文件
在项目根目录下创建 `.env` 配置文件, 参考 `config.py` 中定义的配置项进行设置
token为必须配置, 参考
[workflow rest api doc](https://docs.github.com/zh/rest/actions/workflows?apiVersion=2022-11-28)
生成你的访问令牌, 建议 `细粒度的个人访问令牌`
配置 owner为你的github用户名, repo为你克隆此项目后的项目命名
[workflow 触发及参数文档](https://docs.github.com/zh/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_dispatch)
### todo
- [x] `cli.py` 支持单位置参数
- [ ] 外部调用 `cli.py` 配置文件读取不到问题
- [x] 镜像目标位置 名称中 `/` 替换为 `-`
- [ ] 客户端工具, 输入镜像名称, 自动从阿里云仓库克隆, 并重命名
- [ ] 封装可执行文件
---
视频教程:https://www.bilibili.com/video/BV1Zn4y19743/
作者:**[技术爬爬虾](https://github.com/tech-shrimp/me)**<br>
B站,抖音,Youtube全网同名,转载请注明作者<br>
## 使用方式
### 配置阿里云
登录阿里云容器镜像服务<br>
https://cr.console.aliyun.com/<br>
启用个人实例,创建一个命名空间(**ALIYUN_NAME_SPACE**)
![](/doc/命名空间.png)
访问凭证–>获取环境变量<br>
用户名(**ALIYUN_REGISTRY_USER**)<br>
密码(**ALIYUN_REGISTRY_PASSWORD**)<br>
仓库地址(**ALIYUN_REGISTRY**)<br>
![](/doc/用户名密码.png)
### Fork本项目
Fork本项目<br>
#### 启动Action
进入您自己的项目,点击Action,启用Github Action功能<br>
#### 配置环境变量
进入Settings->Secret and variables->Actions->New Repository secret
![](doc/配置环境变量.png)
将上一步的**四个值**<br>
ALIYUN_NAME_SPACE,ALIYUN_REGISTRY_USER,ALIYUN_REGISTRY_PASSWORD,ALIYUN_REGISTRY<br>
配置成环境变量
### 添加镜像
打开images.txt文件,添加你想要的镜像
可以加tag,也可以不用(默认latest)<br>
可添加 --platform=xxxxx 的参数指定镜像架构<br>
可使用 k8s.gcr.io/kube-state-metrics/kube-state-metrics 格式指定私库<br>
可使用 #开头作为注释<br>
![](doc/images.png)
文件提交后,自动进入Github Action构建
### 使用镜像
回到阿里云,镜像仓库,点击任意镜像,可查看镜像状态。(可以改成公开,拉取镜像免登录)
![](doc/开始使用.png)
在国内服务器pull镜像, 例如:<br>
```
docker pull registry.cn-hangzhou.aliyuncs.com/shrimp-images/alpine
```
registry.cn-hangzhou.aliyuncs.com 即 ALIYUN_REGISTRY(阿里云仓库地址)<br>
shrimp-images 即 ALIYUN_NAME_SPACE(阿里云命名空间)<br>
alpine 即 阿里云中显示的镜像名<br>
### 多架构
需要在images.txt中用 --platform=xxxxx手动指定镜像架构
指定后的架构会以前缀的形式放在镜像名字前面
![](doc/多架构.png)
### 镜像重名
程序自动判断是否存在名称相同, 但是属于不同命名空间的情况。
如果存在,会把命名空间作为前缀加在镜像名称前。
例如:
```
xhofe/alist
xiaoyaliu/alist
```
![](doc/镜像重名.png)
### 定时执行
修改/.github/workflows/docker.yaml文件
添加 schedule即可定时执行(此处cron使用UTC时区)
![](doc/定时执行.png)
## 备注
### 通过API调用后,获取run_id
https://stackoverflow.com/questions/69479400/get-run-id-after-triggering-a-github-workflow-dispatch-event
https://github.com/orgs/community/discussions/17389
## PyPi packaging
twine==6.1.0 版本太新, 导致
```bash
❯ python -m twine check dist/*
Checking dist/dock_worker-0.0.0-py3-none-any.whl: ERROR InvalidDistribution: Invalid distribution metadata: unrecognized or malformed field 'license-file'
```
```bash
pip install "twine<6.0" -U
```
降到 5.1.1 好了
Raw data
{
"_id": null,
"home_page": null,
"name": "dock-worker",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "docker, github-actions, registry, cli",
"author": null,
"author_email": "Leo Wang <leo03w@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/10/0f/b1c5625667e6decd00d832f149da647d7a85ebfab995d41b77e66ce9411f/dock_worker-0.0.0.tar.gz",
"platform": null,
"description": "# Docker Images Pusher\n\n\u4f7f\u7528Github Action\u5c06\u56fd\u5916\u7684Docker\u955c\u50cf\u8f6c\u5b58\u5230\u963f\u91cc\u4e91\u79c1\u6709\u4ed3\u5e93\uff0c\u4f9b\u56fd\u5185\u670d\u52a1\u5668\u4f7f\u7528\uff0c\u514d\u8d39\u6613\u7528<br>\n\n- \u652f\u6301DockerHub, gcr.io, k8s.io, ghcr.io\u7b49\u4efb\u610f\u4ed3\u5e93<br>\n- \u652f\u6301\u6700\u592740GB\u7684\u5927\u578b\u955c\u50cf<br>\n- \u4f7f\u7528\u963f\u91cc\u4e91\u7684\u5b98\u65b9\u7ebf\u8def\uff0c\u901f\u5ea6\u5feb<br>\n\n---\n\n## leo03w 20240830\n\n\u65b0\u589e `api_hook.yaml` \u5e26\u53c2workflow, \u652f\u6301api\u65b9\u5f0f\u542f\u52a8github action, \u53ef\u4f20 `\u539f\u59cb\u955c\u50cf\u5730\u5740` \u548c `\u76ee\u7684\u955c\u50cf\u5730\u5740` \u4e24\u4e2a\u53c2\u6570\n\n- \u652f\u6301 `streamlit` \u5f62\u5f0f\u63d0\u4f9bweb\u754c\u9762\n- \u652f\u6301 `cli.py` \u547d\u4ee4\u884c\u5de5\u5177\u8c03\u7528\n\n## \u4f7f\u7528\u65b9\u5f0f\n\n```bash\npip install .\n```\n\n```bash\nexport github_token=your_token\n```\n\n```bash\ndocker-image-forker --help\n```\n\n### \u914d\u7f6e\u6587\u4ef6\n\n\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa `.env` \u914d\u7f6e\u6587\u4ef6, \u53c2\u8003 `config.py` \u4e2d\u5b9a\u4e49\u7684\u914d\u7f6e\u9879\u8fdb\u884c\u8bbe\u7f6e\n\ntoken\u4e3a\u5fc5\u987b\u914d\u7f6e, \u53c2\u8003\n[workflow rest api doc](https://docs.github.com/zh/rest/actions/workflows?apiVersion=2022-11-28)\n\u751f\u6210\u4f60\u7684\u8bbf\u95ee\u4ee4\u724c, \u5efa\u8bae `\u7ec6\u7c92\u5ea6\u7684\u4e2a\u4eba\u8bbf\u95ee\u4ee4\u724c`\n\n\u914d\u7f6e owner\u4e3a\u4f60\u7684github\u7528\u6237\u540d, repo\u4e3a\u4f60\u514b\u9686\u6b64\u9879\u76ee\u540e\u7684\u9879\u76ee\u547d\u540d\n\n[workflow \u89e6\u53d1\u53ca\u53c2\u6570\u6587\u6863](https://docs.github.com/zh/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_dispatch)\n\n### todo\n\n- [x] `cli.py` \u652f\u6301\u5355\u4f4d\u7f6e\u53c2\u6570\n- [ ] \u5916\u90e8\u8c03\u7528 `cli.py` \u914d\u7f6e\u6587\u4ef6\u8bfb\u53d6\u4e0d\u5230\u95ee\u9898\n- [x] \u955c\u50cf\u76ee\u6807\u4f4d\u7f6e \u540d\u79f0\u4e2d `/` \u66ff\u6362\u4e3a `-`\n- [ ] \u5ba2\u6237\u7aef\u5de5\u5177, \u8f93\u5165\u955c\u50cf\u540d\u79f0, \u81ea\u52a8\u4ece\u963f\u91cc\u4e91\u4ed3\u5e93\u514b\u9686, \u5e76\u91cd\u547d\u540d\n- [ ] \u5c01\u88c5\u53ef\u6267\u884c\u6587\u4ef6\n\n---\n\n\n\u89c6\u9891\u6559\u7a0b\uff1ahttps://www.bilibili.com/video/BV1Zn4y19743/\n\n\u4f5c\u8005\uff1a**[\u6280\u672f\u722c\u722c\u867e](https://github.com/tech-shrimp/me)**<br>\nB\u7ad9\uff0c\u6296\u97f3\uff0cYoutube\u5168\u7f51\u540c\u540d\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u4f5c\u8005<br>\n\n## \u4f7f\u7528\u65b9\u5f0f\n\n### \u914d\u7f6e\u963f\u91cc\u4e91\n\n\u767b\u5f55\u963f\u91cc\u4e91\u5bb9\u5668\u955c\u50cf\u670d\u52a1<br>\nhttps://cr.console.aliyun.com/<br>\n\u542f\u7528\u4e2a\u4eba\u5b9e\u4f8b\uff0c\u521b\u5efa\u4e00\u4e2a\u547d\u540d\u7a7a\u95f4\uff08**ALIYUN_NAME_SPACE**\uff09\n![](/doc/\u547d\u540d\u7a7a\u95f4.png)\n\n\u8bbf\u95ee\u51ed\u8bc1\u2013>\u83b7\u53d6\u73af\u5883\u53d8\u91cf<br>\n\u7528\u6237\u540d\uff08**ALIYUN_REGISTRY_USER**)<br>\n\u5bc6\u7801\uff08**ALIYUN_REGISTRY_PASSWORD**)<br>\n\u4ed3\u5e93\u5730\u5740\uff08**ALIYUN_REGISTRY**\uff09<br>\n\n![](/doc/\u7528\u6237\u540d\u5bc6\u7801.png)\n\n### Fork\u672c\u9879\u76ee\n\nFork\u672c\u9879\u76ee<br>\n\n#### \u542f\u52a8Action\n\n\u8fdb\u5165\u60a8\u81ea\u5df1\u7684\u9879\u76ee\uff0c\u70b9\u51fbAction\uff0c\u542f\u7528Github Action\u529f\u80fd<br>\n\n#### \u914d\u7f6e\u73af\u5883\u53d8\u91cf\n\n\u8fdb\u5165Settings->Secret and variables->Actions->New Repository secret\n![](doc/\u914d\u7f6e\u73af\u5883\u53d8\u91cf.png)\n\u5c06\u4e0a\u4e00\u6b65\u7684**\u56db\u4e2a\u503c**<br>\nALIYUN_NAME_SPACE,ALIYUN_REGISTRY_USER\uff0cALIYUN_REGISTRY_PASSWORD\uff0cALIYUN_REGISTRY<br>\n\u914d\u7f6e\u6210\u73af\u5883\u53d8\u91cf\n\n### \u6dfb\u52a0\u955c\u50cf\n\n\u6253\u5f00images.txt\u6587\u4ef6\uff0c\u6dfb\u52a0\u4f60\u60f3\u8981\u7684\u955c\u50cf\n\u53ef\u4ee5\u52a0tag\uff0c\u4e5f\u53ef\u4ee5\u4e0d\u7528(\u9ed8\u8ba4latest)<br>\n\u53ef\u6dfb\u52a0 --platform=xxxxx \u7684\u53c2\u6570\u6307\u5b9a\u955c\u50cf\u67b6\u6784<br>\n\u53ef\u4f7f\u7528 k8s.gcr.io/kube-state-metrics/kube-state-metrics \u683c\u5f0f\u6307\u5b9a\u79c1\u5e93<br>\n\u53ef\u4f7f\u7528 #\u5f00\u5934\u4f5c\u4e3a\u6ce8\u91ca<br>\n![](doc/images.png)\n\u6587\u4ef6\u63d0\u4ea4\u540e\uff0c\u81ea\u52a8\u8fdb\u5165Github Action\u6784\u5efa\n\n### \u4f7f\u7528\u955c\u50cf\n\n\u56de\u5230\u963f\u91cc\u4e91\uff0c\u955c\u50cf\u4ed3\u5e93\uff0c\u70b9\u51fb\u4efb\u610f\u955c\u50cf\uff0c\u53ef\u67e5\u770b\u955c\u50cf\u72b6\u6001\u3002(\u53ef\u4ee5\u6539\u6210\u516c\u5f00\uff0c\u62c9\u53d6\u955c\u50cf\u514d\u767b\u5f55)\n![](doc/\u5f00\u59cb\u4f7f\u7528.png)\n\n\u5728\u56fd\u5185\u670d\u52a1\u5668pull\u955c\u50cf, \u4f8b\u5982\uff1a<br>\n\n```\ndocker pull registry.cn-hangzhou.aliyuncs.com/shrimp-images/alpine\n```\n\nregistry.cn-hangzhou.aliyuncs.com \u5373 ALIYUN_REGISTRY(\u963f\u91cc\u4e91\u4ed3\u5e93\u5730\u5740)<br>\nshrimp-images \u5373 ALIYUN_NAME_SPACE(\u963f\u91cc\u4e91\u547d\u540d\u7a7a\u95f4)<br>\nalpine \u5373 \u963f\u91cc\u4e91\u4e2d\u663e\u793a\u7684\u955c\u50cf\u540d<br>\n\n### \u591a\u67b6\u6784\n\n\u9700\u8981\u5728images.txt\u4e2d\u7528 --platform=xxxxx\u624b\u52a8\u6307\u5b9a\u955c\u50cf\u67b6\u6784\n\u6307\u5b9a\u540e\u7684\u67b6\u6784\u4f1a\u4ee5\u524d\u7f00\u7684\u5f62\u5f0f\u653e\u5728\u955c\u50cf\u540d\u5b57\u524d\u9762\n![](doc/\u591a\u67b6\u6784.png)\n\n### \u955c\u50cf\u91cd\u540d\n\n\u7a0b\u5e8f\u81ea\u52a8\u5224\u65ad\u662f\u5426\u5b58\u5728\u540d\u79f0\u76f8\u540c, \u4f46\u662f\u5c5e\u4e8e\u4e0d\u540c\u547d\u540d\u7a7a\u95f4\u7684\u60c5\u51b5\u3002\n\u5982\u679c\u5b58\u5728\uff0c\u4f1a\u628a\u547d\u540d\u7a7a\u95f4\u4f5c\u4e3a\u524d\u7f00\u52a0\u5728\u955c\u50cf\u540d\u79f0\u524d\u3002\n\u4f8b\u5982:\n\n```\nxhofe/alist\nxiaoyaliu/alist\n```\n\n![](doc/\u955c\u50cf\u91cd\u540d.png)\n\n### \u5b9a\u65f6\u6267\u884c\n\n\u4fee\u6539/.github/workflows/docker.yaml\u6587\u4ef6\n\u6dfb\u52a0 schedule\u5373\u53ef\u5b9a\u65f6\u6267\u884c(\u6b64\u5904cron\u4f7f\u7528UTC\u65f6\u533a)\n![](doc/\u5b9a\u65f6\u6267\u884c.png)\n\n\n## \u5907\u6ce8\n\n### \u901a\u8fc7API\u8c03\u7528\u540e\uff0c\u83b7\u53d6run_id\n\nhttps://stackoverflow.com/questions/69479400/get-run-id-after-triggering-a-github-workflow-dispatch-event\n\nhttps://github.com/orgs/community/discussions/17389\n\n## PyPi packaging\n\ntwine==6.1.0 \u7248\u672c\u592a\u65b0, \u5bfc\u81f4\n\n```bash\n\u276f python -m twine check dist/*\nChecking dist/dock_worker-0.0.0-py3-none-any.whl: ERROR InvalidDistribution: Invalid distribution metadata: unrecognized or malformed field 'license-file' \n```\n\n```bash\npip install \"twine<6.0\" -U\n```\n\n\u964d\u5230 5.1.1 \u597d\u4e86\n",
"bugtrack_url": null,
"license": null,
"summary": "Fork Docker images between registries using GitHub Actions",
"version": "0.0.0",
"project_urls": null,
"split_keywords": [
"docker",
" github-actions",
" registry",
" cli"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e92ab041a4c82af7b857a7b0c7a9eea96428a13d9b73628fca6560117b2b1f1b",
"md5": "2bf3a074698737736c751011ea51102a",
"sha256": "6c56a9e8283960277c50cb361ed301308717c11ebc8dcd96ea249d3bbdf24d75"
},
"downloads": -1,
"filename": "dock_worker-0.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2bf3a074698737736c751011ea51102a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 17230,
"upload_time": "2025-01-22T09:12:11",
"upload_time_iso_8601": "2025-01-22T09:12:11.580100Z",
"url": "https://files.pythonhosted.org/packages/e9/2a/b041a4c82af7b857a7b0c7a9eea96428a13d9b73628fca6560117b2b1f1b/dock_worker-0.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "100fb1c5625667e6decd00d832f149da647d7a85ebfab995d41b77e66ce9411f",
"md5": "2aad29ef21dc3283519395b6065e7b74",
"sha256": "4aef11657537df3549d70ea67ec47f5e77f50149fd1a04414c6fed946a25ca6b"
},
"downloads": -1,
"filename": "dock_worker-0.0.0.tar.gz",
"has_sig": false,
"md5_digest": "2aad29ef21dc3283519395b6065e7b74",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 17740,
"upload_time": "2025-01-22T09:12:15",
"upload_time_iso_8601": "2025-01-22T09:12:15.338464Z",
"url": "https://files.pythonhosted.org/packages/10/0f/b1c5625667e6decd00d832f149da647d7a85ebfab995d41b77e66ce9411f/dock_worker-0.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-22 09:12:15",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "dock-worker"
}