Drone 插件市场 Drone 插件文档 原文地址 - Docker 插件的手册
Docker 插件可以用于构建镜像及发布镜像到 Docker registry。下面的 pipeline 配置,就使用了 Docker 插件来构建和发布镜像:
pipeline: docker: image: plugins/docker username: kevinbacon password: pa55word repo: foo/bar tags: latest使用多个 tag 的示例配置:
pipeline: docker: image: plugins/docker repo: foo/bar - tags: latest + tags: + - latest + - 1.0.1 + - 1.0使用 .tag 文件(用逗号分隔的 tag 列表)的示例配置:
pipeline: build: image: golang:1.10.0-alpine commands: - [...] + - echo -n "5.2.6,5.2.4" > .tags docker: image: plugins/docker repo: foo/bar - tags: latest使用 build_args 参数的示例配置:
pipeline: docker: image: plugins/docker repo: foo/bar + build_args: + - HTTP_PROXY=http://yourproxy.com使用备用 Dockerfile 的示例配置:
pipeline: docker: image: plugins/docker repo: foo/bar - dockerfile: Dockerfile + dockerfile: path/to/Dockerfile使用自定义 registry 的示例配置:
pipeline: docker: image: plugins/docker - repo: foo/bar + repo: index.company.com/foo/bar + registry: index.company.com使用行内凭据(inline credentials)的示例配置:
pipeline: docker: image: plugins/docker + username: kevinbacon + password: pa55word repo: foo/bar使用 secrets 中的凭据(通过 Drone 的 web 页面添加)的示例配置:
pipeline: docker: image: plugins/docker - username: kevinbacon - password: pa55word repo: foo/bar + secrets: [ docker_username, docker_password ]Docker 插件可以被配置成自动为你的镜像创建 tag。当开启这个特性且事件类型是 tag 时,插件会自动使用标准的 major、minor、release 惯例为镜像创建 tag。例如:
1.0.0 生成 docker tag 1, 1.0, 1.0.01.0.0-rc.1 生成 docker tag 1.0.0-rc.1当事件类型是 push 并且目标分支是你的默认分支(例如 master)时,插件会自动为镜像添加 latest 这个 tag。所有其他的事件类型和分支都会被忽略。
示例配置:
pipeline: docker: image: plugins/docker repo: foo/bar + auto_tag: true secrets: [ docker_username, docker_password ]使用了 tag 后缀的示例配置:
pipeline: docker: image: plugins/docker repo: foo/bar + auto_tag: true + auto_tag_suffix: linux-amd64 secrets: [ docker_username, docker_password ]请注意,自动标记 auto_tag 是故意简单和无法定制的,目前不接受 pull 请求以进一步定制逻辑。
Docker 插件允许在 官方文档 中描述的 Dockerfile 中定义的特定阶段停止构建。如果未定义 target 属性,则 Docker 插件不会在任何阶段停止,此时只会构建完整的 Docker 镜像。
The Docker plugin allow to stop build at a specific stage defined in Dockerfile as described in the official docs. If the target attribute is not defined, the Docker plugin will not stop at any stage and build the full docker image.
Dockerfile 示例:
FROM golang as builder WORKSPACE /go/src/github.com/foo/bar RUN CGO_ENABLED=0 GOOS=linux go build -o demo main.go FROM scratch as production COPY --from=builder /go/src/github.com/foo/bar/demo . CMD ["./demo"] FROM alpine as debug COPY --from=builder /go/src/github.com/foo/bar/demo . CMD ["./demo"]允许构建生产环境 Docker 镜像的示例配置:
pipeline: docker: image: plugins/docker repo: foo/bar + target: production secrets: [ docker_username, docker_password ]下面这个会构建 debug 环境 Docker 镜像:
pipeline: docker: image: plugins/docker repo: foo/bar + target: debug secrets: [ docker_username, docker_password ]转载于:https://www.cnblogs.com/kika/p/10851589.html
相关资源:drone-telegram:用于发送电报通知的Drone插件-源码