diff --git a/cmd/werf/build_and_publish/main.go b/cmd/werf/build_and_publish/main.go index 08a1be25ca..738a9519d7 100644 --- a/cmd/werf/build_and_publish/main.go +++ b/cmd/werf/build_and_publish/main.go @@ -119,6 +119,8 @@ func runBuildAndPublish(imagesToProcess []string) error { tmp_manager.AutoGCEnabled = true ctx := common.BackgroundContext() + werf.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 a3f994b377..83082e6887 100644 --- a/cmd/werf/converge/converge.go +++ b/cmd/werf/converge/converge.go @@ -125,6 +125,8 @@ func runConverge() error { tmp_manager.AutoGCEnabled = true ctx := common.BackgroundContext() + werf.PostponeMultiwerfNotUpToDateWarning() + if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil { return fmt.Errorf("initialization error: %s", err) } diff --git a/cmd/werf/deploy/main.go b/cmd/werf/deploy/main.go index cfdbc6269e..bea10740f4 100644 --- a/cmd/werf/deploy/main.go +++ b/cmd/werf/deploy/main.go @@ -128,6 +128,8 @@ func runDeploy() error { tmp_manager.AutoGCEnabled = true ctx := common.BackgroundContext() + werf.PostponeMultiwerfNotUpToDateWarning() + if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil { return fmt.Errorf("initialization error: %s", err) } diff --git a/cmd/werf/deploy_v2/main.go b/cmd/werf/deploy_v2/main.go index 50a2f1c3b5..aefcdda421 100644 --- a/cmd/werf/deploy_v2/main.go +++ b/cmd/werf/deploy_v2/main.go @@ -142,6 +142,8 @@ func runDeploy() error { tmp_manager.AutoGCEnabled = true ctx := common.BackgroundContext() + werf.PostponeMultiwerfNotUpToDateWarning() + if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil { return fmt.Errorf("initialization error: %s", err) } diff --git a/cmd/werf/images/publish/cmd_factory/main.go b/cmd/werf/images/publish/cmd_factory/main.go index 4aac447f4c..06f4001757 100644 --- a/cmd/werf/images/publish/cmd_factory/main.go +++ b/cmd/werf/images/publish/cmd_factory/main.go @@ -89,6 +89,8 @@ If one or more IMAGE_NAME parameters specified, werf will publish only these ima func runImagesPublish(commonCmdData *common.CmdData, imagesToProcess []string) error { ctx := common.BackgroundContext() + werf.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 6fe1a2e25e..26935b50d7 100644 --- a/cmd/werf/run/run.go +++ b/cmd/werf/run/run.go @@ -168,6 +168,8 @@ func processArgs(cmd *cobra.Command, args []string) error { func runRun() error { ctx := common.BackgroundContext() + werf.PostponeMultiwerfNotUpToDateWarning() + if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil { return fmt.Errorf("initialization error: %s", err) } diff --git a/cmd/werf/stages/build/cmd_factory/main.go b/cmd/werf/stages/build/cmd_factory/main.go index 0282869b36..3160578888 100644 --- a/cmd/werf/stages/build/cmd_factory/main.go +++ b/cmd/werf/stages/build/cmd_factory/main.go @@ -107,6 +107,8 @@ func runStagesBuild(cmdData *CmdData, commonCmdData *common.CmdData, imagesToPro tmp_manager.AutoGCEnabled = true ctx := common.BackgroundContext() + werf.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.go b/pkg/werf/global_warnings.go index a08590a86b..ac0bd413c4 100644 --- a/pkg/werf/global_warnings.go +++ b/pkg/werf/global_warnings.go @@ -1,11 +1,18 @@ package werf import ( + "bytes" "context" + "fmt" + "os/exec" + "regexp" + "github.com/Masterminds/semver" "github.com/werf/logboek" ) +const LastMultiwerfVersion = "1.5.0" + var ( GlobalWarningLines []string ) @@ -21,6 +28,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) }