Skip to content

Commit

Permalink
Merge pull request #4037 from werf/feat-1.1-multiwerf-deprecation-war…
Browse files Browse the repository at this point in the history
…ning

1.1: feat(multiwerf): print multiwerf deprecation warning if multiwerf outdated
  • Loading branch information
alexey-igrychev committed Dec 16, 2021
2 parents 71819da + de6ea51 commit 55b1fc9
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/werf/build_and_publish/main.go
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/converge/converge.go
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/deploy/main.go
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/deploy_v2/main.go
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/images/publish/cmd_factory/main.go
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/run/run.go
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/werf/stages/build/cmd_factory/main.go
Expand Up @@ -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)
}
Expand Down
57 changes: 57 additions & 0 deletions 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
)
Expand All @@ -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 it 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 55b1fc9

Please sign in to comment.