Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for automatic tagging (:1, :1.2, :1.2.3, etc) for semantic versions #22

Merged
merged 6 commits into from Oct 17, 2021

Conversation

kylelemons
Copy link
Contributor

@kylelemons kylelemons commented Jun 1, 2021

Enabling the feature

This feature is off by default. To enable it, either:

  • PLUGIN_AUTO_TAG for drone plugins
  • --auto_tag for command-line use

This changes the way tags (both --tags and PLUGIN_TAGS) are interpreted. Now, instead of saying 1,1.2,1.2.3,latest you can say v1.2.3,latest

This mostly follows semver.org, except that it also swaps underscores (which are not permitted) for hyphens, as otherwise it will likely be confusing when you try v1.2.3+linux_arm and your semver tagging breaks.

Semantics

This parses all tags as semantic versions (after performing a swap of _ for - as required by semver.org). If they parse correctly, the following logic happens:

  • If the semver is pre-release, it is emitted directly (e.g. v1.2.3-alpha1 tags 1.2.3-alpha1)
  • If the semver has build info, it is appended to all tags (e.g. v1.2.3+linux tags 1+linux, 1.2+linux, etc)
  • If it is not a valid semver, nothing changes

Alternatives

Instead of interpreting PLUGIN_TAGS differently, we could make PLUGIN_AUTO_TAGS a list that would be required to parse correctly as semantic versions, which might avoid some classes of error. That would make invocation look like

-e PLUGIN_TAGS=latest
-e PLUGIN_AUTO_TAGS=$DRONE_TAG

This probably works fine for most drone workflows, though it will break workflows where e.g. someone tags a build for_testing or something along those lines, so I did not go with this approach initially.

Copy link
Contributor

@shubham149 shubham149 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late review. I missed the notification for this pr.

README.md Show resolved Hide resolved
cmd/kaniko-docker/main.go Show resolved Hide resolved
When --auto_tag is enabled, a semver (semver.org) tag like v1.2.3 expands to:
  :1
  :1.2
  :1.2.3

This allows a workflow by which "${DRONE_TAG}" is passed directly to the tags
paraneter, and this results in tagging the docker images correctly for the
"less specific" versions.  It passes through non-semver tags, to allow passing
e.g. ["$DRONE_TAG", "latest"] for images for which "latest" refers only to the
latest release, even if there are "non-release" pushes in between.
@kylelemons
Copy link
Contributor Author

kylelemons commented Oct 15, 2021

Sorry for late review.

Oof, sorry for the even later reply. This fell so far down my TODO list that I lost it :(

We've been using this for awhile now so I'm pretty confident that it works -- the main "gotcha" is that if you forget the "v" you will only get the numeric tag (e.g. if you tag "1.2.3" instead of "v1.2.3" you won't get ":1" or ":1.2"). I think it's especially easy to forget the v since docker tags don't have them.

So, I have also included (as a single commit, in case you'd like me to revert this piece) a change that will recognize them as well.

@shubham149
Copy link
Contributor

LGTM. We can merge after the build check passes.

@shubham149 shubham149 merged commit 0a35538 into drone:main Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants