Drone CI 中文文档

Registry(容器注册表凭证托管)

你可以使用 Registry 扩展来为你的流水线提供 Docker 登录凭证。如果你的流水线依赖于私有镜像,这些凭证将被用于验证远程注册表和提取私有镜像。

扩展配置

你可以通过提供以下配置参数在你的 Runner 上注册一个扩展:

  • DRONE_REGISTRY_PLUGIN_ENDPOINT
    提供用于向 Registry 扩展发出 http 请求的端点。
  • DRONE_REGISTRY_PLUGIN_TOKEN
    提供用于验证对扩展的 http 请求的令牌。这个令牌在服务器和扩展之间共享。

扩展工作原理

Runner 会发出 HTTP POST 请求,以检索注册凭证的列表。Runner 通过比较注册凭证地址和限定的 Docker 镜像网址,将注册表凭证与你的 yaml 中的 docker 镜像相匹配。

扩展请求响应

Registry 扩展收到一个 HTTP 请求,以返回注册凭证的列表。JSON 编码的请求体包括存储库和构建信息。

以下是请求体的定义:

1
2
3
4
class Request {
    repo: Repository;
    build: Build;
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Repository {
    id: int64;
    uid: int64;
    user_id: int64;
    namespace: string;
    name: string;
    slug: string;
    scm: string;
    git_http_url: string;
    git_ssh_url: string;
    link: string;
    default_branch: string;
    private: boolean;
    visibility: string;
    active: boolean;
    config: string;
    trusted: boolean;
    protected: boolean;
    ignore_forks: boolean;
    ignore_pulls: boolean;
    cancel_pulls: boolean;
    timeout: int64;
    counter: int64;
    synced: int64;
    created: int64;
    updated: int64;
    version: int64;
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Build {
    id: int64;
    repo_id: int64;
    number: int64;
    parent: int64;
    status: string;
    error: string
    event: string;
    action: string;
    link: string;
    timestamp: int64;
    title: string;
    message: string;
    before: string;
    after: string;
    ref: string;
    source_repo: string;
    source: string;
    target: string;
    author_login: string;
    author_name: string;
    author_email: string;
    author_avatar: string;
    sender: string;
    params: [string][string];
    cron: string;
    deploy_to: string;
    deploy_id: int64;
    started: int64;
    finished: int64;
    created: int64;
    updated: int64;
    version: int64;
}

扩展请求响应

Registry 扩展应该以 200 的响应代码和 JSON 格式的注册凭证列表来响应该请求。

以下是 Registry 的定义示例:

1
2
3
4
5
class Registry {
  address: string
  username: string
  password: string
}

以下是响应体的示例:

[
  {
    "address": "docker.io",
    "username": "octocat",
    "password": "correct-horse-battery-staple"
  }
]

扩展请求鉴权

HTTP 请求根据 HTTP 签名规范草案使用共享 Secret 进行签名。请求接收者应该使用签名来验证 WebHook 的真实性和完整性。

起始项目 (模板)

如果你有兴趣创建一个 Registry 扩展,我们建议使用我们的起始项目模板作为基础来启动开发。