forked from toolshed/abra
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			better-err
			...
			integratio
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 0a371ec360 | 
@ -3,6 +3,7 @@ package app
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"coopcloud.tech/abra/cli/internal"
 | 
						"coopcloud.tech/abra/cli/internal"
 | 
				
			||||||
	"coopcloud.tech/abra/pkg/app"
 | 
						"coopcloud.tech/abra/pkg/app"
 | 
				
			||||||
@ -275,6 +276,9 @@ func getDeployVersion(cliArgs []string, deployMeta stack.DeployMeta, app app.App
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Check if the recipe has a version in the .env file
 | 
						// Check if the recipe has a version in the .env file
 | 
				
			||||||
	if app.Recipe.EnvVersion != "" && !internal.IgnoreEnvVersion {
 | 
						if app.Recipe.EnvVersion != "" && !internal.IgnoreEnvVersion {
 | 
				
			||||||
 | 
							if strings.HasSuffix(app.Recipe.EnvVersionRaw, "+U") {
 | 
				
			||||||
 | 
								return "", fmt.Errorf("version: can not redeploy chaos version %s", app.Recipe.EnvVersionRaw)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		log.Debugf("version: taking version from .env file: %s", app.Recipe.EnvVersion)
 | 
							log.Debugf("version: taking version from .env file: %s", app.Recipe.EnvVersion)
 | 
				
			||||||
		return app.Recipe.EnvVersion, nil
 | 
							return app.Recipe.EnvVersion, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -242,7 +242,7 @@ func validateDowngradeVersionArg(
 | 
				
			|||||||
) error {
 | 
					) error {
 | 
				
			||||||
	parsedDeployedVersion, err := tagcmp.Parse(deployMeta.Version)
 | 
						parsedDeployedVersion, err := tagcmp.Parse(deployMeta.Version)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("'%s' is not a known version for %s", deployMeta.Version, app.Recipe.Name)
 | 
							return fmt.Errorf("current deployment '%s' is not a known version for %s", deployMeta.Version, app.Recipe.Name)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	parsedSpecificVersion, err := tagcmp.Parse(specificVersion)
 | 
						parsedSpecificVersion, err := tagcmp.Parse(specificVersion)
 | 
				
			||||||
 | 
				
			|||||||
@ -1,64 +0,0 @@
 | 
				
			|||||||
package internal
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"runtime"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/charmbracelet/log"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func Error(msg string) HelpError {
 | 
					 | 
				
			||||||
	caller := ""
 | 
					 | 
				
			||||||
	if Debug {
 | 
					 | 
				
			||||||
		_, file, line, _ := runtime.Caller(1)
 | 
					 | 
				
			||||||
		caller = log.ShortCallerFormatter(file, line, "")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return HelpError{err: msg, caller: caller}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func Errorf(format string, a ...any) HelpError {
 | 
					 | 
				
			||||||
	caller := ""
 | 
					 | 
				
			||||||
	if Debug {
 | 
					 | 
				
			||||||
		_, file, line, _ := runtime.Caller(1)
 | 
					 | 
				
			||||||
		caller = log.ShortCallerFormatter(file, line, "")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return HelpError{err: fmt.Sprintf(format, a...), caller: caller}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type HelpError struct {
 | 
					 | 
				
			||||||
	err    string
 | 
					 | 
				
			||||||
	caller string
 | 
					 | 
				
			||||||
	help   string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (e HelpError) Help(help string) HelpError {
 | 
					 | 
				
			||||||
	e.help = help
 | 
					 | 
				
			||||||
	return e
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (e HelpError) Helpf(format string, a ...any) HelpError {
 | 
					 | 
				
			||||||
	e.help = fmt.Sprintf(format, a...)
 | 
					 | 
				
			||||||
	return e
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (e HelpError) Error() string {
 | 
					 | 
				
			||||||
	return e.format()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (e HelpError) format() string {
 | 
					 | 
				
			||||||
	msg := ""
 | 
					 | 
				
			||||||
	if e.caller != "" {
 | 
					 | 
				
			||||||
		msg += fmt.Sprintf("<%s> ", e.caller)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	msg += e.err
 | 
					 | 
				
			||||||
	if e.help == "" {
 | 
					 | 
				
			||||||
		return msg
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return fmt.Sprintf(`%s
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Help: %s `, msg, e.help)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										16
									
								
								cli/run.go
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								cli/run.go
									
									
									
									
									
								
							@ -3,7 +3,6 @@ package cli
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"coopcloud.tech/abra/cli/app"
 | 
						"coopcloud.tech/abra/cli/app"
 | 
				
			||||||
	"coopcloud.tech/abra/cli/catalogue"
 | 
						"coopcloud.tech/abra/cli/catalogue"
 | 
				
			||||||
@ -41,7 +40,7 @@ func Run(version, commit string) {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for _, path := range paths {
 | 
								for _, path := range paths {
 | 
				
			||||||
				if err := os.Mkdir(path, 0o764); err != nil {
 | 
									if err := os.Mkdir(path, 0764); err != nil {
 | 
				
			||||||
					if !os.IsExist(err) {
 | 
										if !os.IsExist(err) {
 | 
				
			||||||
						log.Fatal(err)
 | 
											log.Fatal(err)
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
@ -67,9 +66,6 @@ func Run(version, commit string) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rootCmd.CompletionOptions.DisableDefaultCmd = true
 | 
						rootCmd.CompletionOptions.DisableDefaultCmd = true
 | 
				
			||||||
	// We handle errors ourself
 | 
					 | 
				
			||||||
	rootCmd.SilenceUsage = true
 | 
					 | 
				
			||||||
	rootCmd.SilenceErrors = true
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	manCommand := &cobra.Command{
 | 
						manCommand := &cobra.Command{
 | 
				
			||||||
		Use:     "man [flags]",
 | 
							Use:     "man [flags]",
 | 
				
			||||||
@ -216,15 +212,7 @@ func Run(version, commit string) {
 | 
				
			|||||||
		app.AppEnvCommand,
 | 
							app.AppEnvCommand,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if cmd, err := rootCmd.ExecuteC(); err != nil {
 | 
						if err := rootCmd.Execute(); err != nil {
 | 
				
			||||||
		fmt.Printf("Error: %s\n", err)
 | 
					 | 
				
			||||||
		if strings.HasPrefix(err.Error(), "unknown flag") {
 | 
					 | 
				
			||||||
			fmt.Println()
 | 
					 | 
				
			||||||
			cmd.Usage()
 | 
					 | 
				
			||||||
		} else if !internal.Debug {
 | 
					 | 
				
			||||||
			fmt.Println()
 | 
					 | 
				
			||||||
			fmt.Printf("Run with --debug for more info.\n")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		os.Exit(1)
 | 
							os.Exit(1)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,6 @@
 | 
				
			|||||||
package server
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -43,20 +41,19 @@ developer machine. The domain is then set to "default".`,
 | 
				
			|||||||
	ValidArgsFunction: func(
 | 
						ValidArgsFunction: func(
 | 
				
			||||||
		cmd *cobra.Command,
 | 
							cmd *cobra.Command,
 | 
				
			||||||
		args []string,
 | 
							args []string,
 | 
				
			||||||
		toComplete string,
 | 
							toComplete string) ([]string, cobra.ShellCompDirective) {
 | 
				
			||||||
	) ([]string, cobra.ShellCompDirective) {
 | 
					 | 
				
			||||||
		if !local {
 | 
							if !local {
 | 
				
			||||||
			return autocomplete.ServerNameComplete()
 | 
								return autocomplete.ServerNameComplete()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return nil, cobra.ShellCompDirectiveDefault
 | 
							return nil, cobra.ShellCompDirectiveDefault
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	RunE: func(cmd *cobra.Command, args []string) error {
 | 
						Run: func(cmd *cobra.Command, args []string) {
 | 
				
			||||||
		if len(args) > 0 && local {
 | 
							if len(args) > 0 && local {
 | 
				
			||||||
			return errors.New("cannot use [server] and --local together")
 | 
								log.Fatal("cannot use [server] and --local together")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if len(args) == 0 && !local {
 | 
							if len(args) == 0 && !local {
 | 
				
			||||||
			return errors.New("missing argument or --local/-l flag")
 | 
								log.Fatal("missing argument or --local/-l flag")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		name := "default"
 | 
							name := "default"
 | 
				
			||||||
@ -72,14 +69,14 @@ developer machine. The domain is then set to "default".`,
 | 
				
			|||||||
		if local {
 | 
							if local {
 | 
				
			||||||
			created, err := createServerDir(name)
 | 
								created, err := createServerDir(name)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return err
 | 
									log.Fatal(err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			log.Debugf("attempting to create client for %s", name)
 | 
								log.Debugf("attempting to create client for %s", name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if _, err := client.New(name, timeout); err != nil {
 | 
								if _, err := client.New(name, timeout); err != nil {
 | 
				
			||||||
				cleanUp(name)
 | 
									cleanUp(name)
 | 
				
			||||||
				return err
 | 
									log.Fatal(err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if created {
 | 
								if created {
 | 
				
			||||||
@ -88,18 +85,18 @@ developer machine. The domain is then set to "default".`,
 | 
				
			|||||||
				log.Warn("local server already exists")
 | 
									log.Warn("local server already exists")
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return nil
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		_, err := createServerDir(name)
 | 
							_, err := createServerDir(name)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								log.Fatal(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		created, err := newContext(name)
 | 
							created, err := newContext(name)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			cleanUp(name)
 | 
								cleanUp(name)
 | 
				
			||||||
			return fmt.Errorf("unable to create local context: %s", err)
 | 
								log.Fatalf("unable to create local context: %s", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		log.Debugf("attempting to create client for %s", name)
 | 
							log.Debugf("attempting to create client for %s", name)
 | 
				
			||||||
@ -107,7 +104,7 @@ developer machine. The domain is then set to "default".`,
 | 
				
			|||||||
		if _, err := client.New(name, timeout); err != nil {
 | 
							if _, err := client.New(name, timeout); err != nil {
 | 
				
			||||||
			cleanUp(name)
 | 
								cleanUp(name)
 | 
				
			||||||
			log.Debugf("ssh %s error: %s", name, sshPkg.Fatal(name, err))
 | 
								log.Debugf("ssh %s error: %s", name, sshPkg.Fatal(name, err))
 | 
				
			||||||
			return internal.Errorf("can't ssh to %s", name).Helpf("make sure \"ssh %s\" works", name)
 | 
								log.Fatalf("can't ssh to %s, make sure \"ssh %s\" works", name, name)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if created {
 | 
							if created {
 | 
				
			||||||
@ -117,11 +114,10 @@ developer machine. The domain is then set to "default".`,
 | 
				
			|||||||
				log.Warnf("unable to resolve IPv4 for %s", name)
 | 
									log.Warnf("unable to resolve IPv4 for %s", name)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return nil
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		log.Warnf("%s already exists", name)
 | 
							log.Warnf("%s already exists", name)
 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -193,7 +189,9 @@ func createServerDir(name string) (bool, error) {
 | 
				
			|||||||
	return true, nil
 | 
						return true, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var local bool
 | 
					var (
 | 
				
			||||||
 | 
						local bool
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
	ServerAddCommand.Flags().BoolVarP(
 | 
						ServerAddCommand.Flags().BoolVarP(
 | 
				
			||||||
 | 
				
			|||||||
@ -154,7 +154,7 @@ teardown(){
 | 
				
			|||||||
  assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | 
					  assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  run $ABRA app deploy "$TEST_APP_DOMAIN" \
 | 
					  run $ABRA app deploy "$TEST_APP_DOMAIN" \
 | 
				
			||||||
    --no-input --no-converge-checks --force
 | 
					    --no-input --no-converge-checks --force --debug
 | 
				
			||||||
  assert_failure
 | 
					  assert_failure
 | 
				
			||||||
  assert_output --regexp 'can not redeploy chaos version .*' + "${headHash:0:8}+U"
 | 
					  assert_output --regexp 'can not redeploy chaos version .*' + "${headHash:0:8}+U"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -249,7 +249,7 @@ teardown(){
 | 
				
			|||||||
    --no-input --no-converge-checks --force
 | 
					    --no-input --no-converge-checks --force
 | 
				
			||||||
  assert_success
 | 
					  assert_success
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  assert_output --partial 'CHAOS DEPLOY OVERVIEW'
 | 
					  assert_output --partial 'REDEPLOY OVERVIEW'
 | 
				
			||||||
  assert_output --partial "CURRENT DEPLOYMENT    ${headHash:0:8}"
 | 
					  assert_output --partial "CURRENT DEPLOYMENT    ${headHash:0:8}"
 | 
				
			||||||
  assert_output --partial "ENV VERSION           ${headHash:0:8}"
 | 
					  assert_output --partial "ENV VERSION           ${headHash:0:8}"
 | 
				
			||||||
  assert_output --partial "NEW DEPLOYMENT        ${headHash:0:8}"
 | 
					  assert_output --partial "NEW DEPLOYMENT        ${headHash:0:8}"
 | 
				
			||||||
 | 
				
			|||||||
@ -164,8 +164,7 @@ teardown(){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  run $ABRA app rollback "$TEST_APP_DOMAIN" "0.1.1+1.20.2" --no-input --no-converge-checks
 | 
					  run $ABRA app rollback "$TEST_APP_DOMAIN" "0.1.1+1.20.2" --no-input --no-converge-checks
 | 
				
			||||||
  assert_failure
 | 
					  assert_failure
 | 
				
			||||||
  assert_output --partial "0.1.1+1.20.2"
 | 
					  assert_output --partial 'current deployment' + "${tagHash:0:8}" + 'is not a known version'
 | 
				
			||||||
  assert_output --partial "${tagHash:0:8}" + 'is not a known version'
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# bats test_tags=slow
 | 
					# bats test_tags=slow
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user