GoogleContainerTools / skaffold

Easy and Repeatable Kubernetes Development
https://skaffold.dev/
Apache License 2.0
15.03k stars 1.62k forks source link

Add tagPolicy: gitCommit: variant: Branches #6989

Closed snickell closed 2 years ago

snickell commented 2 years ago

Since https://github.com/GoogleContainerTools/skaffold/pull/6904 has been merged, cacheFrom will automatically munge an not-explicitly-tagged image name to append the current tagPolicy. This makes it potentially very useful for easy layer-build-caching of dev branches..... if the gitCommit tagPolicy permitted a Branch variant.

In a dev context when building large docker build on a non-local machine relying on cacheFrom pulls rather than a local build cache, image tags are important for exporting and importing the most-relevant-to-current build cache, and git tags are generally not relevant.

I would propose that:

tagPolicy:
  gitCommit:
    variant: 'Branches'

behave just like variant: 'Tags', but will check if the current commit is part of a branch, and use that for the image tag, rather than using the git tag.

snickell commented 2 years ago

As an alternative approach, perhaps the set of "skaffold created special env vars" could be expanded to include git branch, git commit, etc: https://skaffold.dev/docs/environment/templating/

This would allow very nice control of git related tagging (including composite tags) using the envTemplate variant

MarlonGamez commented 2 years ago

@snickell thanks for opening up this issue, I don't know that this will be prioritized by the team but we're always open to PRs :)

snickell commented 2 years ago

I'd be up to implement a PR if there was Skaffold team consensus that (at least in principal) this was a desirable feature

gsquared94 commented 2 years ago

I would propose that:

tagPolicy:
  gitCommit:
    variant: 'Branches'

behave just like variant: 'Tags', but will check if the current commit is part of a branch, and use that for the image tag, rather than using the git tag.

I'd be up to implement a PR if there was Skaffold team consensus that (at least in principal) this was a desirable feature

I'd say go for it 👍

vikas027 commented 2 years ago

I'd be up to implement a PR if there was Skaffold team consensus that (at least in principal) this was a desirable feature

Hey @snickell , This is indeed a popular request in the slack community :)

snickell commented 2 years ago

See #7006 for a PR that implements the proposal here

cyraid commented 5 months ago

Sorry for the extremely late bump, but is there a way to specify a specific branch? Like if you always want to get the latest commit of "release"?