Skip to content
Permalink
Browse files
feat(multiwerf): print multiwerf deprecation warning if multiwerf out…
…dated
  • Loading branch information
ilya-lesikov committed Dec 14, 2021
1 parent 1d9ac12 commit 12d0f55357cf0efcdc05db23835f997357b99eb6
Showing with 67 additions and 0 deletions.
  1. +2 −0 cmd/werf/build/main.go
  2. +2 −0 cmd/werf/bundle/apply/apply.go
  3. +2 −0 cmd/werf/bundle/publish/publish.go
  4. +2 −0 cmd/werf/converge/converge.go
  5. +2 −0 cmd/werf/run/run.go
  6. +57 −0 pkg/werf/global_warnings/global_warnings.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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}

0 comments on commit 12d0f55

Please sign in to comment.