Skip to content

Commit

Permalink
feat(multiwerf): print multiwerf deprecation warning if multiwerf out…
Browse files Browse the repository at this point in the history
…dated
  • Loading branch information
ilya-lesikov committed Dec 14, 2021
1 parent 1d9ac12 commit 12d0f55
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/werf/build/main.go
Expand Up @@ -126,6 +126,8 @@ If one or more IMAGE_NAME parameters specified, werf will build only these image
}

func runMain(ctx context.Context, args []string) error {
global_warnings.PostponeMultiwerfNotUpToDateWarning()

if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil {
return fmt.Errorf("initialization error: %s", err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/bundle/apply/apply.go
Expand Up @@ -103,6 +103,8 @@ func NewCmd() *cobra.Command {
func runApply() error {
ctx := common.BackgroundContext()

global_warnings.PostponeMultiwerfNotUpToDateWarning()

if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil {
return fmt.Errorf("initialization error: %s", err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/bundle/publish/publish.go
Expand Up @@ -142,6 +142,8 @@ Published into container registry bundle can be rolled out by the "werf bundle"
}

func runPublish(ctx context.Context) error {
global_warnings.PostponeMultiwerfNotUpToDateWarning()

if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil {
return fmt.Errorf("initialization error: %s", err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/converge/converge.go
Expand Up @@ -162,6 +162,8 @@ werf converge --repo registry.mydomain.com/web --env production`,
}

func runMain(ctx context.Context) error {
global_warnings.PostponeMultiwerfNotUpToDateWarning()

if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil {
return fmt.Errorf("initialization error: %s", err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/run/run.go
Expand Up @@ -215,6 +215,8 @@ func getContainerName() string {
}

func runMain(ctx context.Context) error {
global_warnings.PostponeMultiwerfNotUpToDateWarning()

if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil {
return fmt.Errorf("initialization error: %s", err)
}
Expand Down
57 changes: 57 additions & 0 deletions pkg/werf/global_warnings/global_warnings.go
@@ -1,11 +1,18 @@
package global_warnings

import (
"bytes"
"context"
"fmt"
"os/exec"
"regexp"

"github.com/Masterminds/semver"
"github.com/werf/logboek"
)

const LastMultiwerfVersion = "1.5.0"

var GlobalWarningLines []string

func PrintGlobalWarnings(ctx context.Context) {
Expand All @@ -19,6 +26,56 @@ func GlobalWarningLn(ctx context.Context, line string) {
printGlobalWarningLn(ctx, line)
}

func IsMultiwerfUpToDate() (bool, error) {
multiwerfPath, err := exec.LookPath("multiwerf")
if err != nil {
return true, nil
}

cmd := exec.Command(multiwerfPath, "version")
var stdout bytes.Buffer
cmd.Stdout = &stdout
if err := cmd.Run(); err != nil {
return false, fmt.Errorf("unable to get installed version of multiwerf: %s", err)
}

versionRegex := regexp.MustCompile(`^multiwerf v([.0-9]+)\s*$`)
regexResult := versionRegex.FindStringSubmatch(stdout.String())
if len(regexResult) != 2 {
return false, fmt.Errorf("\"multiwerf version\" returned unexpected output: %s", stdout.String())
}
installedMultiwerfVersion, err := semver.NewVersion(regexResult[1])
if err != nil {
return false, fmt.Errorf("unable to parse version of installed multiwerf version: %s", err)
}

lastMultiwerfVersion, err := semver.NewVersion(LastMultiwerfVersion)
if err != nil {
return false, fmt.Errorf("unable to parse version of last available multiwerf version: %s", err)
}

return !installedMultiwerfVersion.LessThan(lastMultiwerfVersion), nil
}

func PostponeMultiwerfNotUpToDateWarning() {
if multiwerfIsUpToDate, err := IsMultiwerfUpToDate(); err != nil {
GlobalWarningLines = append(
GlobalWarningLines,
fmt.Sprintf("Failure detecting whether multiwerf (if present) is outdated: %s", err),
"Multiwerf is deprecated, so if you are still using it we strongly recommend removing multiwerf and switching to trdl by following these instructions: https://werf.io/installation.html",
)
return
} else if multiwerfIsUpToDate {
return
}

GlobalWarningLines = append(
GlobalWarningLines,
"Multiwerf detected, but is out of date. Multiwerf is deprecated in favor of trdl: https://github.com/werf/trdl",
"If you are still using multiwerf we strongly recommend removing multiwerf and switching to trdl by following these instructions: https://werf.io/installation.html",
)
}

func printGlobalWarningLn(ctx context.Context, line string) {
logboek.Context(ctx).Error().LogF("WARNING: %s\n", line)
}

0 comments on commit 12d0f55

Please sign in to comment.