New default_tags parameter for Docker Plugin


#1

The latest version of the docker plugin includes a new default_tags flag that can be used to automatically tag your images. It is an optional, opt-in feature and can be used to simplify your configuration. The logic is pretty basic at the moment:

  • Use latest tag for push events
  • Use git tag for tag events

The git tags should following semantic version naming conventions. The plugin will parse the git tag and publish a tagged docker image for each major, minor and patch version. For example:

  • git tag v1.9.2 will publish docker tags 1, 1.9 and 1.9.2
  • git tag v1.9.2-alpha.1 will publish docker tag 1.9.2-alpha.1

This allows us to combine two separate publish steps into a single step:

pipeline:
  publish_latest:
    image: plugins/docker
    repo: octocat/hello-world
-   tags: latest
+   default_tags: true
    when:
-     event: push
+     event: [ push, tag ]

- publish_release:
-   image: plugins/docker
-   repo: octocat/hello-world
-   tags: $DRONE_TAG
-   when:
-     event: tag

This is just an initial implementation, however, I hope that it will be helpful and is something we can improve over time. Planned improvements include automated tags for pushes to non-master branches.


#2

I should also mention that in some cases you may want to add a suffix to your tags. This is especially useful when building images for multiple architectures. For example we may want to use the following tag scheme for windows images:

nanoserver
1.9.2-nanoserver
1.9-nanoserver
1-nanoserver

We would use the default_suffix parameter in our configuration:

pipeline:
  publish_latest:
    image: plugins/docker
    repo: octocat/hello-world
+   default_tags: true
+   default_suffix: nanoserver

Example behavior:

  • Push to master would publish an image with tag nanoserver
  • Tagging v1.9.2 would publish images with tags 1-nanoserver, 1.9-nanoserver, 1.9.2-nanoserver

#3

I think the downstream ECR plugin might be broken because of this, I’m noticing an exit code of 1 on it.


#4

I think the downstream ECR plugin might be broken because of this

This change did not impact the ECR plugin. The ECR plugin was recently changes and moved to the core drone-plugin repository. These changes may have included breaking changes, although I am not certain. Feel free to discuss ECR changes in the relevant thread https://github.com/drone-plugins/drone-docker/pull/155


#5

@ktruckenmiller do you have any example yaml config, version, or other data you can provide? I’m looking for some clarity to make sure your issue is resolved.


#6

Hey @tonglil ! I think it was simple:

pipeline:
  image: plugins/ecr
  repo: 00000.ecr.us-east-1.blah/amazon-garbage
  

And then I noticed the docker hub container had been updated around the time I was redeploying. It was just an exit code of 1. I recently updated my drone docker daemon to 17.09 so that might have something to do with this as well.


#7

I see.
Have you tried restarting the job with the failure?
What is the status of your question/issue now?


#8

This actually happened on multiple drone servers, so it’s definitely a thing with all of my plugins/ecr builds.


#9

I create new PR to keep only master branch for the latest tag. You can define the default_branch in .drone.yml default as an empty string.

pipeline:
  publish_latest:
    image: plugins/docker
    repo: octocat/hello-world
    tags: latest
    default_tags: true
+   default_branch: master
    when:
      event: [ push, tag ]

#10

What is the status of your question/issue now?
Are there any logs there were emitted by the agent/drone on the exits?