How to build docker image frome .drone.yml? How to build docker image frome .drone.yml? docker docker

How to build docker image frome .drone.yml?


Note that this answer applies to drone version 0.5

You can use the Docker plugin to build and publish a Docker image at the successful completion of your build. You add the Docker plugin as a step in your build pipeline section of the .drone.yml file:

pipeline:  build:    image: golang    commands:      - go build      - go test  publish:    image: plugins/docker    repo: foo/bar

In many cases you will want to limit execution of the this step to certain branches. This can be done by adding runtime conditions:

  publish:    image: plugins/docker    repo: foo/bar    when:      branch: master

You will need to provide drone with credentials to your Docker registry in order for drone to publish. These credentials can be declared directly in the yaml file, although storing these values in plain text in the yaml is generally not recommended:

  publish:    image: plugins/docker    repo: foo/bar    username: johnsmith    password: pa55word    when:      branch: master

You can alternatively provide your credentials using the built-in secret store. Secrets can be added to the secret store on a per-repository basis using the Drone command line utility:

  export DRONE_SERVER=http://drone.server.address.com  export DRONE_TOKEN=...  drone secret add \    octocat/hello-world DOCKER_USERNAME johnsmith  drone secret add \    octocat/hello-world DOCKER_PASSWORD pa55word  drone sign octocat/hello-world

Secrets are then interpolated in your yaml at rutnime:

  publish:    image: plugins/docker    repo: foo/bar    username: ${DOCKER_USERNAME}    password: ${DOCKER_PASSWORD}    when:      branch: master