Skip to content

Commit

Permalink
fix(bundles): fix werf-bundle-publish command error when --tag contai…
Browse files Browse the repository at this point in the history
…ns underscore chars

Werf bundle publish command automatically generates chart.version metadata field, which equals 0.0.0-TIMESTAMP-SLUG(TAG), when TAG is not a valid semver by itself.
  • Loading branch information
distorhead committed Nov 16, 2021
1 parent 65536bb commit 03e8f88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cmd/werf/bundle/publish/publish.go
Expand Up @@ -7,6 +7,8 @@ import (
"path/filepath"
"time"

"github.com/werf/werf/pkg/slug"

"github.com/Masterminds/semver"

"helm.sh/helm/v3/pkg/getter"
Expand Down Expand Up @@ -370,7 +372,12 @@ func runPublish(ctx context.Context) error {

chartVersion := cmdData.Tag
if _, err := semver.NewVersion(chartVersion); err != nil {
chartVersion = fmt.Sprintf("0.0.0-%d-%s", time.Now().Unix(), chartVersion)
chartVersion = fmt.Sprintf("0.0.0-%d-%s", time.Now().Unix(), slug.Slug(chartVersion))
if _, err := semver.NewVersion(chartVersion); err != nil {
fallbackChartVersion := fmt.Sprintf("0.0.0-%d", time.Now().Unix())
logboek.Context(ctx).Warn().LogF("Unable to use %q as chart version, will fallback on chart version %q\n", chartVersion, fallbackChartVersion)
chartVersion = fallbackChartVersion
}
}

bundleTmpDir := filepath.Join(werf.GetServiceDir(), "tmp", "bundles", uuid.NewV4().String())
Expand Down
2 changes: 1 addition & 1 deletion pkg/slug/slug.go
Expand Up @@ -71,7 +71,7 @@ func ValidateDockerTag(name string) error {
return nil
}

return fmt.Errorf(`%q is not a valid docker tag
return fmt.Errorf(`%q is not a valid docker tag
- a tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes;
- a tag name may not start with a period or a dash and may contain a maximum of 128 characters.`, name)
Expand Down

0 comments on commit 03e8f88

Please sign in to comment.