2020-11-16 19:11:59 +01:00
|
|
|
package kaniko
|
2021-10-17 20:35:18 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuild_labelsForTag(t *testing.T) {
|
|
|
|
tests := []struct {
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name string
|
|
|
|
tag string
|
|
|
|
expandTags []string
|
2021-10-17 20:35:18 +02:00
|
|
|
}{
|
|
|
|
{
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name: "semver",
|
|
|
|
tag: "v1.2.3",
|
|
|
|
expandTags: []string{"1", "1.2", "1.2.3"},
|
2021-10-17 20:35:18 +02:00
|
|
|
},
|
|
|
|
{
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name: "no_patch",
|
|
|
|
tag: "v1.2",
|
|
|
|
expandTags: []string{"1", "1.2", "1.2.0"},
|
2021-10-17 20:35:18 +02:00
|
|
|
},
|
|
|
|
{
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name: "only_major",
|
|
|
|
tag: "v1",
|
|
|
|
expandTags: []string{"1", "1.0", "1.0.0"},
|
2021-10-17 20:35:18 +02:00
|
|
|
},
|
|
|
|
{
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name: "full_with_build",
|
|
|
|
tag: "v1.2.3+build-info",
|
|
|
|
expandTags: []string{"1+build-info", "1.2+build-info", "1.2.3+build-info"},
|
2021-10-17 20:35:18 +02:00
|
|
|
},
|
|
|
|
{
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name: "build_with_underscores",
|
|
|
|
tag: "v1.2.3+linux_amd64",
|
|
|
|
expandTags: []string{"1+linux-amd64", "1.2+linux-amd64", "1.2.3+linux-amd64"},
|
2021-10-17 20:35:18 +02:00
|
|
|
},
|
|
|
|
{
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name: "prerelease",
|
|
|
|
tag: "v1.2.3-rc1",
|
|
|
|
expandTags: []string{"1.2.3-rc1"},
|
2021-10-17 20:35:18 +02:00
|
|
|
},
|
|
|
|
{
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name: "prerelease_with_build",
|
|
|
|
tag: "v1.2.3-rc1+bld",
|
|
|
|
expandTags: []string{"1.2.3-rc1+bld"},
|
2021-10-17 20:35:18 +02:00
|
|
|
},
|
|
|
|
{
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name: "invalid_build",
|
|
|
|
tag: "v1+bld", // can only include build detail with all three elements
|
|
|
|
expandTags: []string{"v1+bld"},
|
2021-10-17 20:35:18 +02:00
|
|
|
},
|
|
|
|
{
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name: "accidental_non_semver",
|
|
|
|
tag: "1.2.3",
|
|
|
|
expandTags: []string{"1", "1.2", "1.2.3"},
|
2021-10-17 20:35:18 +02:00
|
|
|
},
|
|
|
|
{
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
name: "non_semver",
|
|
|
|
tag: "latest",
|
|
|
|
expandTags: []string{"latest"},
|
2021-10-17 20:35:18 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
tags := Build{ExpandTag: true}.labelsForTag(tt.tag)
|
|
|
|
if got, want := tags, tt.expandTags; !cmp.Equal(got, want) {
|
2021-10-17 20:35:18 +02:00
|
|
|
t.Errorf("tagsFor(%q) = %q, want %q", tt.tag, got, want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
|
|
|
|
func TestBuild_AutoTags(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
repoBranch string
|
|
|
|
commitRef string
|
|
|
|
autoTagSuffix string
|
|
|
|
expectedTags []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "commit push",
|
|
|
|
repoBranch: "master",
|
|
|
|
commitRef: "refs/heads/master",
|
|
|
|
autoTagSuffix: "",
|
|
|
|
expectedTags: []string{"latest"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag push",
|
|
|
|
repoBranch: "master",
|
|
|
|
commitRef: "refs/tags/v1.0.0",
|
|
|
|
autoTagSuffix: "",
|
|
|
|
expectedTags: []string{
|
|
|
|
"1",
|
|
|
|
"1.0",
|
|
|
|
"1.0.0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tag push",
|
|
|
|
repoBranch: "master",
|
|
|
|
commitRef: "refs/tags/v1.0.0",
|
|
|
|
autoTagSuffix: "linux-amd64",
|
|
|
|
expectedTags: []string{
|
|
|
|
"1-linux-amd64",
|
|
|
|
"1.0-linux-amd64",
|
|
|
|
"1.0.0-linux-amd64",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
b := Build{DroneCommitRef: tt.commitRef, DroneRepoBranch: tt.repoBranch, AutoTag: true}
|
|
|
|
if tt.autoTagSuffix != "" {
|
|
|
|
b.AutoTagSuffix = tt.autoTagSuffix
|
|
|
|
}
|
|
|
|
tags, err := b.AutoTags()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unexpected err %q", err)
|
|
|
|
}
|
|
|
|
if got, want := tags, tt.expectedTags; !cmp.Equal(got, want) {
|
|
|
|
t.Errorf("auto detected tags = %q, wanted = %q", got, want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-02-10 14:06:36 +01:00
|
|
|
t.Run("auto-tag cannot be enabled with user provided tags", func(t *testing.T) {
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
b := Build{
|
|
|
|
DroneCommitRef: "refs/tags/v1.0.0",
|
|
|
|
DroneRepoBranch: "master",
|
|
|
|
AutoTag: true,
|
|
|
|
Tags: []string{"v1"},
|
|
|
|
}
|
|
|
|
_, err := b.AutoTags()
|
|
|
|
if err == nil {
|
2022-02-10 14:06:36 +01:00
|
|
|
t.Errorf("Expect error for invalid flags")
|
Port the auto tag feature from docker plugin (#36)
* Port the auto tag feature from https://plugins.drone.io/drone-plugins/drone-docker
The logic is forked from https://github.com/drone-plugins/drone-docker code base
with necessary modification. I've tested it e2e for DockerHub on my Drone server
via this plugin image https://hub.docker.com/repository/docker/15cm/drone-kaniko,
for both tag pushes and commit pushes.
With this change the .drone.yml in this repo should work as intended.
Other changes:
- Rename the existing "auto tag" flags/code to "expand tag" for a less
misleading naming.
- ATTENTION: make a breaking change to set default value of "--tags" to empty.
Rationale is to expect most users to use the auto tagging feature. When power
users want to specify tags, they should always explicitly set tags instead of
being surprised by the default "latest" tag.
* Change how --auto-tag flag works with other flags
The --auto-tag has to be a breaking change. This commit limit the breaking
impact to the users who enable the flag. Behaviors of flag combination after
this commit:
* --auto-tag=false: No changes.
* --auto-tag=false,--expand-tag=true,tags=1.0.0:
* Old behavior: Should not happen. --expand-tag didn't exist.
* New Behavior: Build with [1,1.0,1.0.0] tags.
* --auto-tag=true
* Old behavior: Build with the "latest" tag.
* New behavior: Build with auto detected tags. Abort if auto detection failed.
* --auto-tag=true,tags=latest: same as "--auto-tag=true".
* --auto-tag=true,tags=1.0.0:
* Old behavior: Build with [1,1.0,1.0.0] tags.
* New behavior: Abort the build with an error message.
* --auto-tag=true,--expand-tag=true,tags=1.0.0: Abort the build with an error message.
Also added a test for the integration of the BUILD struct and the tagger
package, which is used by kaniko.go.
* Update readme to note that expand-tag and auto-tag don't support artifacts
2022-02-10 08:36:14 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|