Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image-sync

容器镜像同步 HTTP 服务,支持在不同 Registry 之间异步同步镜像。

技术栈

快速开始

前置依赖

  • Go 1.25+
  • Redis

构建与运行

go build -o image-sync .
./image-sync --config ./config.yaml

服务启动后同时运行 HTTP Server(默认 :8080)和 Asynq Worker。

配置

config.yaml 示例:

server:
  port: 8080
redis:
  addr: localhost:6379
  password: ""
asynq:
  concurrency: 10
registries:
  harbor:
    url: harbor.example.com
    username: admin
    password: secret
  acr:
    url: registry.cn-hangzhou.aliyuncs.com
    username: ""
    password: ""
  • registries 是一个 map,key 为 alias(如 harbor),API 请求中通过 alias 引用
  • asynq.concurrency 控制 Asynq Worker 并发数
  • redis 配置供 Asynq 内部使用,服务本身不直接操作 Redis

API

提交同步任务

POST /api/v1/sync

请求体:

{
  "src": "harbor",
  "dst": "acr",
  "image": "library/nginx",
  "tag": "1.25",
  "priority": "high"
}
字段 必填 说明
src 源 Registry alias
dst 目标 Registry alias
image 镜像名(如 library/nginx
tag 镜像 tag
priority high / default / low,默认 default

响应 202 Accepted

{
  "task_id": "abc123"
}

查询任务状态

GET /api/v1/tasks/:id

响应 200 OK

{
  "task_id": "abc123",
  "status": "completed",
  "completed_at": "2026-07-05T12:00:00Z"
}

status 取值:pending / processing / completed / failed。任务不存在时返回 404

架构

POST /api/v1/sync → Gin 校验 → Asynq 入队(优先级队列)
                                      ↓
                GET /api/v1/tasks/:id ← Asynq Worker
                                      ↓
                                  crane.Pull(src)
                                      ↓
                                  crane.Push(dst)
  • 异步处理:接口立即返回 task_id,后台执行镜像拷贝
  • Asynq 优先级队列:high → critical(6) / default → default(3) / low → low(1),权重比决定 Worker 消费速率
  • 任务最大重试 3 次(Asynq MaxRetry)
  • src/dst 使用独立认证(Pull + Push 而非 crane.Copy)

About

通过http的方式触发镜像在不同仓库的同步。支持任务异步执行,持久化存储,支持优先级队列

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages