Please note that this answer applies to drone version 0.5
You can use the Docker plugin to create and publish a Docker image as a step in your build pipeline. In the example .drone.yml file .drone.yml I added a publishing step that uses the docker plugin. Please note that you will need to replace foo/bar with the name of the DockerHub repository you are going to publish to.
pipeline: build: image: golang commands: - go build - go test publish: image: plugins/docker repo: foo/bar
In many cases, you need to limit the execution of this step to specific branches. This can be done by adding execution conditions:
publish: image: plugins/docker repo: foo/bar when: branch: master
You will need to provide drone with credentials to the Docker registry in order to publish drone. These credentials can be declared directly in the yaml file, although storing these values ββin plain text in yaml is usually not recommended:
publish: image: plugins/docker repo: foo/bar username: johnsmith password: pa55word when: branch: master
You can also provide your credentials using the built-in secret store. Secrets can be added to the secret repository based on each repository using the Drone command-line utility:
export DRONE_SERVER=http://drone.server.address.com export DRONE_TOKEN=... drone secret add --image plugins/docker \ octocat/hello-world DOCKER_USERNAME johnsmith drone secret add --image plugins/docker \ octocat/hello-world DOCKER_PASSWORD pa55word
In the above example, the --image flag --image used to limit the secrets to which we expose the Docker credentials that we set in the docker plugin. The octocat/hello-world parameter represents your GitHub repository name and should be replaced with the correct value.
Mouting Voumes (alternative approach)
You also asked if the Docker socket could be connected to your build environment. It is possible, but some additional permissions will be required (mark your assembly as trusted in the user interface)
pipeline: build: image: docker commands: - docker build ... - docker run ... volumes: - /var/run/docker.sock:/var/run/docker.sock
The only problem with this approach is that if the build fails, you cannot clear the images or containers created during the build.
In addition, you should not use this approach if your repository is public and accepts pull requests. Providing your Docker socket host machine for your build environment may be triggered by malicious request requests that allow access to your host machine.