diff --git a/cmd/werf/build/main.go b/cmd/werf/build/main.go index 2cfb2222aa..7652fb68cd 100644 --- a/cmd/werf/build/main.go +++ b/cmd/werf/build/main.go @@ -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) } diff --git a/cmd/werf/bundle/apply/apply.go b/cmd/werf/bundle/apply/apply.go index 8c47512efb..0821af4d5b 100644 --- a/cmd/werf/bundle/apply/apply.go +++ b/cmd/werf/bundle/apply/apply.go @@ -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) } diff --git a/cmd/werf/bundle/publish/publish.go b/cmd/werf/bundle/publish/publish.go index 5e6e1b736f..f052d0730b 100644 --- a/cmd/werf/bundle/publish/publish.go +++ b/cmd/werf/bundle/publish/publish.go @@ -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) } diff --git a/cmd/werf/converge/converge.go b/cmd/werf/converge/converge.go index d66b186753..b7c36a4819 100644 --- a/cmd/werf/converge/converge.go +++ b/cmd/werf/converge/converge.go @@ -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) } diff --git a/cmd/werf/run/run.go b/cmd/werf/run/run.go index c1488eece5..d49ce42d03 100644 --- a/cmd/werf/run/run.go +++ b/cmd/werf/run/run.go @@ -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) } diff --git a/pkg/werf/global_warnings/global_warnings.go b/pkg/werf/global_warnings/global_warnings.go index 3689ee0972..9a6ba3f21a 100644 --- a/pkg/werf/global_warnings/global_warnings.go +++ b/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) { @@ -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) }