如何从无人机 ci 管道中的私有 docker 注册表中提取图像

frn*_*drk 1 docker drone.io drone

回答

问题

  • 我需要在我的测试管道中使用来自私有 docker 镜像注册表的镜像
  • 我找不到任何(编辑:被忽略的)最新文档,说明如何将私有 docker 注册表与无人机一起使用或使用专门配置的存储库。

情况

操作系统版本:ubuntu 18.04 lts
无人机版本:1.0.0
docker 版本:18.09.4 docker
-compose 版本:1.23.2

我自己用 docker 和 docker-compose(一个主,两个代理)托管了无人机 ci。

示例管道配置:

---

kind: pipeline
name: integration

steps:
  - name: tests
    image: private-registry.example.com/nodejs/special
    commands:
      - npm i
      - npm run test
    when:
      event:
        - push
        - pull_request
...
Run Code Online (Sandbox Code Playgroud)

无人机文档

无人机的文档是指配置私有注册表而不提供链接或在图像部分中有关管道步骤的文档页面上提供有关如何完成此操作更多详细信息,说明:

如果镜像不存在,Drone 会指示 Docker 拉取它。如果映像是私有的,您将需要配置注册表凭据。


我发现了这个问题,其中 op 指的是不再存在的文档中的此页面

问题的作者和接受的答案的作者都使用无人机 cli 通过registry命令向无人机添加注册表。但不幸的是,此命令不再可用。

当前的无人机 cli 使用消息如下所示:

NAME:
   drone - command line utility

USAGE:
   drone [global options] command [command options] [arguments...]

VERSION:
   1.0.7

COMMANDS:
     build      manage builds
     cron       manage cron jobs
     log        manage logs
     encrypt    encrypt a secret
     exec       execute a local build
     info       show information about the current user
     repo       manage repositories
     user       manage users
     secret     manage secrets
     server     manage servers
     queue      queue operations
     autoscale  manage autoscaling
     fmt        format the yaml file
     convert    convert legacy format
     lint       lint the yaml file
     sign       sign the yaml file
     jsonnet    generate .drone.yml from jsonnet
     script     generate .drone.yml from script
     plugins    plugin helper functions
     help, h    Shows a list of commands or help for one command

GLOBAL OPTIONS:
   -t value, --token value   server auth token [$DRONE_TOKEN]
   -s value, --server value  server address [$DRONE_SERVER]
   --autoscaler value        autoscaler address [$DRONE_AUTOSCALER]
   --help, -h                show help
   --version, -v             print the version
Run Code Online (Sandbox Code Playgroud)

我发现了一个GitHub的问题,指的是拉请求添加从2014年码头工人节这一切似乎已经被转移到了码头工人码头工人:DIND分别插件。

问题

  1. 那么最后,有没有一种方法可以为无人机添加一个私有的 docker 注册表,怎么做呢?
  2. 是否有提供有关如何操作的详细信息的文档?

frn*_*drk 5

解决方案

确实有一个专门针对私有 docker 镜像注册表的文档部分

图像拉取秘密

为了下载私有映像,您需要提供一个 docker 注册表配置文件,该文件将身份验证凭据嵌入到注册表中。

示例 .docker/config.json 文件:

{
  "auths": {
    "https://index.docker.io/v1/": {
      "auth": "b2N0b2NhdDpjb3JyZWN0LWhvcnNlLWJhdHRlcnktc3RhcGxl"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

文件的内容应存储为机密,其中命名的机密在 yaml 的 image_pull_secrets 部分中引用。

kind: pipeline
name: default
type: docker

steps:
- name: build   
  image: testing/test-image   
  commands:
  - go build
  - go test

image_pull_secrets:
- dockerconfigjson
Run Code Online (Sandbox Code Playgroud)

因此,我们要做的是执行 adocker login <registry host>并将生成的凭据~/.docker/config.json放在一个秘密中,在名为 的示例中dockerconfigjson