forked from toolshed/abra
		
	refactor(recipe): remove direct usage of config.RECIPE_DIR
This commit is contained in:
		@ -5,7 +5,6 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"path"
 | 
			
		||||
	"sort"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
@ -14,7 +13,6 @@ import (
 | 
			
		||||
	appPkg "coopcloud.tech/abra/pkg/app"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/autocomplete"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/client"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/log"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/recipe"
 | 
			
		||||
	"github.com/urfave/cli"
 | 
			
		||||
@ -70,10 +68,9 @@ Example:
 | 
			
		||||
 | 
			
		||||
		hasCmdArgs, parsedCmdArgs := parseCmdArgs(c.Args(), internal.LocalCmd)
 | 
			
		||||
 | 
			
		||||
		abraSh := path.Join(config.RECIPES_DIR, app.Recipe.Name, "abra.sh")
 | 
			
		||||
		if _, err := os.Stat(abraSh); err != nil {
 | 
			
		||||
		if _, err := os.Stat(app.Recipe.AbraShPath); err != nil {
 | 
			
		||||
			if os.IsNotExist(err) {
 | 
			
		||||
				log.Fatalf("%s does not exist for %s?", abraSh, app.Name)
 | 
			
		||||
				log.Fatalf("%s does not exist for %s?", app.Recipe.AbraShPath, app.Name)
 | 
			
		||||
			}
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
@ -84,7 +81,7 @@ Example:
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			cmdName := c.Args().Get(1)
 | 
			
		||||
			if err := internal.EnsureCommand(abraSh, app.Recipe.Name, cmdName); err != nil {
 | 
			
		||||
			if err := internal.EnsureCommand(app.Recipe.AbraShPath, app.Recipe.Name, cmdName); err != nil {
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@ -98,10 +95,10 @@ Example:
 | 
			
		||||
			var sourceAndExec string
 | 
			
		||||
			if hasCmdArgs {
 | 
			
		||||
				log.Debugf("parsed following command arguments: %s", parsedCmdArgs)
 | 
			
		||||
				sourceAndExec = fmt.Sprintf("TARGET=local; APP_NAME=%s; STACK_NAME=%s; %s . %s; %s %s", app.Name, app.StackName(), exportEnv, abraSh, cmdName, parsedCmdArgs)
 | 
			
		||||
				sourceAndExec = fmt.Sprintf("TARGET=local; APP_NAME=%s; STACK_NAME=%s; %s . %s; %s %s", app.Name, app.StackName(), exportEnv, app.Recipe.AbraShPath, cmdName, parsedCmdArgs)
 | 
			
		||||
			} else {
 | 
			
		||||
				log.Debug("did not detect any command arguments")
 | 
			
		||||
				sourceAndExec = fmt.Sprintf("TARGET=local; APP_NAME=%s; STACK_NAME=%s; %s . %s; %s", app.Name, app.StackName(), exportEnv, abraSh, cmdName)
 | 
			
		||||
				sourceAndExec = fmt.Sprintf("TARGET=local; APP_NAME=%s; STACK_NAME=%s; %s . %s; %s", app.Name, app.StackName(), exportEnv, app.Recipe.AbraShPath, cmdName)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			shell := "/bin/bash"
 | 
			
		||||
@ -122,7 +119,7 @@ Example:
 | 
			
		||||
			targetServiceName := c.Args().Get(1)
 | 
			
		||||
 | 
			
		||||
			cmdName := c.Args().Get(2)
 | 
			
		||||
			if err := internal.EnsureCommand(abraSh, app.Recipe.Name, cmdName); err != nil {
 | 
			
		||||
			if err := internal.EnsureCommand(app.Recipe.AbraShPath, app.Recipe.Name, cmdName); err != nil {
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@ -155,7 +152,7 @@ Example:
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if err := internal.RunCmdRemote(cl, app, abraSh, targetServiceName, cmdName, parsedCmdArgs); err != nil {
 | 
			
		||||
			if err := internal.RunCmdRemote(cl, app, app.Recipe.AbraShPath, targetServiceName, cmdName, parsedCmdArgs); err != nil {
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@ -247,8 +244,7 @@ var appCmdListCommand = cli.Command{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getShCmdNames(app appPkg.App) ([]string, error) {
 | 
			
		||||
	abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, app.Recipe, "abra.sh")
 | 
			
		||||
	cmdNames, err := appPkg.ReadAbraShCmdNames(abraShPath)
 | 
			
		||||
	cmdNames, err := appPkg.ReadAbraShCmdNames(app.Recipe.AbraShPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,6 @@ package app
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"coopcloud.tech/abra/cli/internal"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/autocomplete"
 | 
			
		||||
@ -11,7 +10,6 @@ import (
 | 
			
		||||
 | 
			
		||||
	appPkg "coopcloud.tech/abra/pkg/app"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/client"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/dns"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/formatter"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/git"
 | 
			
		||||
@ -158,8 +156,7 @@ recipes.
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, app.Recipe, "abra.sh")
 | 
			
		||||
		abraShEnv, err := envfile.ReadAbraShEnvVars(abraShPath)
 | 
			
		||||
		abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,6 @@ import (
 | 
			
		||||
 | 
			
		||||
	appPkg "coopcloud.tech/abra/pkg/app"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/autocomplete"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/envfile"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/lint"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/recipe"
 | 
			
		||||
@ -178,8 +177,7 @@ recipes.
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, app.Recipe, "abra.sh")
 | 
			
		||||
		abraShEnv, err := envfile.ReadAbraShEnvVars(abraShPath)
 | 
			
		||||
		abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,6 @@ import (
 | 
			
		||||
	appPkg "coopcloud.tech/abra/pkg/app"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/autocomplete"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/client"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/envfile"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/lint"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/log"
 | 
			
		||||
@ -189,7 +188,7 @@ recipes.
 | 
			
		||||
					log.Fatal(err)
 | 
			
		||||
				}
 | 
			
		||||
				if parsedVersion.IsGreaterThan(parsedDeployedVersion) && parsedVersion.IsLessThan(parsedChosenUpgrade) {
 | 
			
		||||
					note, err := internal.GetReleaseNotes(app.Recipe.Name, version)
 | 
			
		||||
					note, err := app.Recipe.GetReleaseNotes(version)
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						return err
 | 
			
		||||
					}
 | 
			
		||||
@ -215,8 +214,7 @@ recipes.
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, app.Recipe, "abra.sh")
 | 
			
		||||
		abraShEnv, err := envfile.ReadAbraShEnvVars(abraShPath)
 | 
			
		||||
		abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -2,13 +2,10 @@ package internal
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	appPkg "coopcloud.tech/abra/pkg/app"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/formatter"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/log"
 | 
			
		||||
	"github.com/AlecAivazis/survey/v2"
 | 
			
		||||
@ -60,34 +57,13 @@ func NewVersionOverview(app appPkg.App, currentVersion, newVersion, releaseNotes
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetReleaseNotes prints release notes for a recipe version
 | 
			
		||||
func GetReleaseNotes(recipeName, version string) (string, error) {
 | 
			
		||||
	if version == "" {
 | 
			
		||||
		return "", nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	fpath := path.Join(config.RECIPES_DIR, recipeName, "release", version)
 | 
			
		||||
 | 
			
		||||
	if _, err := os.Stat(fpath); !os.IsNotExist(err) {
 | 
			
		||||
		releaseNotes, err := ioutil.ReadFile(fpath)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "", err
 | 
			
		||||
		}
 | 
			
		||||
		withTitle := fmt.Sprintf("%s release notes:\n%s", version, string(releaseNotes))
 | 
			
		||||
		return withTitle, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PostCmds parses a string of commands and executes them inside of the respective services
 | 
			
		||||
// the commands string must have the following format:
 | 
			
		||||
// "<service> <command> <arguments>|<service> <command> <arguments>|... "
 | 
			
		||||
func PostCmds(cl *dockerClient.Client, app appPkg.App, commands string) error {
 | 
			
		||||
	abraSh := path.Join(config.RECIPES_DIR, app.Recipe.Name, "abra.sh")
 | 
			
		||||
	if _, err := os.Stat(abraSh); err != nil {
 | 
			
		||||
	if _, err := os.Stat(app.Recipe.AbraShPath); err != nil {
 | 
			
		||||
		if os.IsNotExist(err) {
 | 
			
		||||
			return fmt.Errorf(fmt.Sprintf("%s does not exist for %s?", abraSh, app.Name))
 | 
			
		||||
			return fmt.Errorf(fmt.Sprintf("%s does not exist for %s?", app.Recipe.AbraShPath, app.Name))
 | 
			
		||||
		}
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@ -105,7 +81,7 @@ func PostCmds(cl *dockerClient.Client, app appPkg.App, commands string) error {
 | 
			
		||||
		}
 | 
			
		||||
		log.Infof("running post-command '%s %s' in container %s", cmdName, parsedCmdArgs, targetServiceName)
 | 
			
		||||
 | 
			
		||||
		if err := EnsureCommand(abraSh, app.Recipe.Name, cmdName); err != nil {
 | 
			
		||||
		if err := EnsureCommand(app.Recipe.AbraShPath, app.Recipe.Name, cmdName); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -128,7 +104,7 @@ func PostCmds(cl *dockerClient.Client, app appPkg.App, commands string) error {
 | 
			
		||||
		log.Debugf("running command %s %s within the context of %s_%s", cmdName, parsedCmdArgs, app.StackName(), targetServiceName)
 | 
			
		||||
 | 
			
		||||
		Tty = true
 | 
			
		||||
		if err := RunCmdRemote(cl, app, abraSh, targetServiceName, cmdName, parsedCmdArgs); err != nil {
 | 
			
		||||
		if err := RunCmdRemote(cl, app, app.Recipe.AbraShPath, targetServiceName, cmdName, parsedCmdArgs); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -1,13 +1,11 @@
 | 
			
		||||
package recipe
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"path"
 | 
			
		||||
 | 
			
		||||
	"coopcloud.tech/abra/cli/internal"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/autocomplete"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	gitPkg "coopcloud.tech/abra/pkg/git"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/log"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/recipe"
 | 
			
		||||
	"github.com/urfave/cli"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -25,13 +23,13 @@ var recipeDiffCommand = cli.Command{
 | 
			
		||||
	BashComplete: autocomplete.RecipeNameComplete,
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		recipeName := c.Args().First()
 | 
			
		||||
		r := recipe.Get(recipeName)
 | 
			
		||||
 | 
			
		||||
		if recipeName != "" {
 | 
			
		||||
			internal.ValidateRecipe(c)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		recipeDir := path.Join(config.RECIPES_DIR, recipeName)
 | 
			
		||||
		if err := gitPkg.DiffUnstaged(recipeDir); err != nil {
 | 
			
		||||
		if err := gitPkg.DiffUnstaged(r.Dir); err != nil {
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -62,17 +62,16 @@ recipe and domain in the sample environment config).
 | 
			
		||||
			internal.ShowSubcommandHelpAndError(c, errors.New("no recipe name provided"))
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		directory := path.Join(config.RECIPES_DIR, recipeName)
 | 
			
		||||
		if _, err := os.Stat(directory); !os.IsNotExist(err) {
 | 
			
		||||
			log.Fatalf("%s recipe directory already exists?", directory)
 | 
			
		||||
		if _, err := os.Stat(r.Dir); !os.IsNotExist(err) {
 | 
			
		||||
			log.Fatalf("%s recipe directory already exists?", r.Dir)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		url := fmt.Sprintf("%s/example.git", config.REPOS_BASE_URL)
 | 
			
		||||
		if err := git.Clone(directory, url); err != nil {
 | 
			
		||||
		if err := git.Clone(r.Dir, url); err != nil {
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		gitRepo := path.Join(config.RECIPES_DIR, recipeName, ".git")
 | 
			
		||||
		gitRepo := path.Join(r.Dir, ".git")
 | 
			
		||||
		if err := os.RemoveAll(gitRepo); err != nil {
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
@ -91,14 +90,13 @@ recipe and domain in the sample environment config).
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if err := os.WriteFile(path, templated.Bytes(), 0644); err != nil {
 | 
			
		||||
			if err := os.WriteFile(path, templated.Bytes(), 0o644); err != nil {
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		newGitRepo := path.Join(config.RECIPES_DIR, recipeName)
 | 
			
		||||
		if err := git.Init(newGitRepo, true, internal.GitName, internal.GitEmail); err != nil {
 | 
			
		||||
		if err := git.Init(r.Dir, true, internal.GitName, internal.GitEmail); err != nil {
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -117,7 +115,7 @@ See "abra recipe -h" for additional recipe maintainer commands.
 | 
			
		||||
 | 
			
		||||
Happy Hacking!
 | 
			
		||||
 | 
			
		||||
`, recipeName, path.Join(config.RECIPES_DIR, recipeName), recipeName))
 | 
			
		||||
`, recipeName, path.Join(r.Dir), recipeName))
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
@ -129,7 +129,7 @@ your SSH keys configured on your account.
 | 
			
		||||
			log.Warnf("no tag specified and no previous tag available for %s, assuming this is the initial release", recipe.Name)
 | 
			
		||||
 | 
			
		||||
			if err := createReleaseFromTag(recipe, tagString, mainAppVersion); err != nil {
 | 
			
		||||
				if cleanUpErr := cleanUpTag(tagString, recipe.Name); err != nil {
 | 
			
		||||
				if cleanUpErr := cleanUpTag(recipe, tagString); err != nil {
 | 
			
		||||
					log.Fatal(cleanUpErr)
 | 
			
		||||
				}
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
@ -188,8 +188,7 @@ func getImageVersions(recipe recipe.Recipe) (map[string]string, error) {
 | 
			
		||||
func createReleaseFromTag(recipe recipe.Recipe, tagString, mainAppVersion string) error {
 | 
			
		||||
	var err error
 | 
			
		||||
 | 
			
		||||
	directory := path.Join(config.RECIPES_DIR, recipe.Name)
 | 
			
		||||
	repo, err := git.PlainOpen(directory)
 | 
			
		||||
	repo, err := git.PlainOpen(recipe.Dir)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@ -250,8 +249,7 @@ func getTagCreateOptions(tag string) (git.CreateTagOptions, error) {
 | 
			
		||||
// addReleaseNotes checks if the release/next release note exists and moves the
 | 
			
		||||
// file to release/<tag>.
 | 
			
		||||
func addReleaseNotes(recipe recipe.Recipe, tag string) error {
 | 
			
		||||
	repoPath := path.Join(config.RECIPES_DIR, recipe.Name)
 | 
			
		||||
	tagReleaseNotePath := path.Join(repoPath, "release", tag)
 | 
			
		||||
	tagReleaseNotePath := path.Join(recipe.Dir, "release", tag)
 | 
			
		||||
	if _, err := os.Stat(tagReleaseNotePath); err == nil {
 | 
			
		||||
		// Release note for current tag already exist exists.
 | 
			
		||||
		return nil
 | 
			
		||||
@ -259,7 +257,7 @@ func addReleaseNotes(recipe recipe.Recipe, tag string) error {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	nextReleaseNotePath := path.Join(repoPath, "release", "next")
 | 
			
		||||
	nextReleaseNotePath := path.Join(recipe.Dir, "release", "next")
 | 
			
		||||
	if _, err := os.Stat(nextReleaseNotePath); err == nil {
 | 
			
		||||
		// release/next note exists. Move it to release/<tag>
 | 
			
		||||
		if internal.Dry {
 | 
			
		||||
@ -282,11 +280,11 @@ func addReleaseNotes(recipe recipe.Recipe, tag string) error {
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		err = gitPkg.Add(repoPath, path.Join("release", "next"), internal.Dry)
 | 
			
		||||
		err = gitPkg.Add(recipe.Dir, path.Join("release", "next"), internal.Dry)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		err = gitPkg.Add(repoPath, path.Join("release", tag), internal.Dry)
 | 
			
		||||
		err = gitPkg.Add(recipe.Dir, path.Join("release", tag), internal.Dry)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
@ -315,7 +313,7 @@ func addReleaseNotes(recipe recipe.Recipe, tag string) error {
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	err = gitPkg.Add(repoPath, path.Join("release", tag), internal.Dry)
 | 
			
		||||
	err = gitPkg.Add(recipe.Dir, path.Join("release", tag), internal.Dry)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@ -341,8 +339,7 @@ func commitRelease(recipe recipe.Recipe, tag string) error {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	msg := fmt.Sprintf("chore: publish %s release", tag)
 | 
			
		||||
	repoPath := path.Join(config.RECIPES_DIR, recipe.Name)
 | 
			
		||||
	if err := gitPkg.Commit(repoPath, msg, internal.Dry); err != nil {
 | 
			
		||||
	if err := gitPkg.Commit(recipe.Dir, msg, internal.Dry); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -406,8 +403,7 @@ func pushRelease(recipe recipe.Recipe, tagString string) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func createReleaseFromPreviousTag(tagString, mainAppVersion string, recipe recipe.Recipe, tags []string) error {
 | 
			
		||||
	directory := path.Join(config.RECIPES_DIR, recipe.Name)
 | 
			
		||||
	repo, err := git.PlainOpen(directory)
 | 
			
		||||
	repo, err := git.PlainOpen(recipe.Dir)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@ -510,9 +506,8 @@ func createReleaseFromPreviousTag(tagString, mainAppVersion string, recipe recip
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// cleanUpTag removes a freshly created tag
 | 
			
		||||
func cleanUpTag(tag, recipeName string) error {
 | 
			
		||||
	directory := path.Join(config.RECIPES_DIR, recipeName)
 | 
			
		||||
	repo, err := git.PlainOpen(directory)
 | 
			
		||||
func cleanUpTag(recipe recipe.Recipe, tag string) error {
 | 
			
		||||
	repo, err := git.PlainOpen(recipe.Dir)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,10 @@
 | 
			
		||||
package recipe
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"path"
 | 
			
		||||
 | 
			
		||||
	"coopcloud.tech/abra/cli/internal"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/autocomplete"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/log"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/recipe"
 | 
			
		||||
	"github.com/go-git/go-git/v5"
 | 
			
		||||
	"github.com/urfave/cli"
 | 
			
		||||
)
 | 
			
		||||
@ -25,13 +23,13 @@ var recipeResetCommand = cli.Command{
 | 
			
		||||
	BashComplete: autocomplete.RecipeNameComplete,
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		recipeName := c.Args().First()
 | 
			
		||||
		r := recipe.Get(recipeName)
 | 
			
		||||
 | 
			
		||||
		if recipeName != "" {
 | 
			
		||||
			internal.ValidateRecipe(c)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		repoPath := path.Join(config.RECIPES_DIR, recipeName)
 | 
			
		||||
		repo, err := git.PlainOpen(repoPath)
 | 
			
		||||
		repo, err := git.PlainOpen(r.Dir)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -2,12 +2,10 @@ package recipe
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"path"
 | 
			
		||||
	"strconv"
 | 
			
		||||
 | 
			
		||||
	"coopcloud.tech/abra/cli/internal"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/autocomplete"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	gitPkg "coopcloud.tech/abra/pkg/git"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/log"
 | 
			
		||||
	"coopcloud.tech/tagcmp"
 | 
			
		||||
@ -107,8 +105,7 @@ likely to change.
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if nextTag == "" {
 | 
			
		||||
			recipeDir := path.Join(config.RECIPES_DIR, recipe.Name)
 | 
			
		||||
			repo, err := git.PlainOpen(recipeDir)
 | 
			
		||||
			repo, err := git.PlainOpen(recipe.Dir)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@ -12,7 +12,6 @@ import (
 | 
			
		||||
	"coopcloud.tech/abra/cli/internal"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/autocomplete"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/client"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/formatter"
 | 
			
		||||
	gitPkg "coopcloud.tech/abra/pkg/git"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/log"
 | 
			
		||||
@ -94,8 +93,7 @@ You may invoke this command in "wizard" mode and be prompted for input:
 | 
			
		||||
 | 
			
		||||
		// check for versions file and load pinned versions
 | 
			
		||||
		versionsPresent := false
 | 
			
		||||
		recipeDir := path.Join(config.RECIPES_DIR, recipe.Name)
 | 
			
		||||
		versionsPath := path.Join(recipeDir, "versions")
 | 
			
		||||
		versionsPath := path.Join(recipe.Dir, "versions")
 | 
			
		||||
		servicePins := make(map[string]imgPin)
 | 
			
		||||
		if _, err := os.Stat(versionsPath); err == nil {
 | 
			
		||||
			log.Debugf("found versions file for %s", recipe.Name)
 | 
			
		||||
@ -332,13 +330,13 @@ You may invoke this command in "wizard" mode and be prompted for input:
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		isClean, err := gitPkg.IsClean(recipeDir)
 | 
			
		||||
		isClean, err := gitPkg.IsClean(recipe.Dir)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
		if !isClean {
 | 
			
		||||
			log.Infof("%s currently has these unstaged changes 👇", recipe.Name)
 | 
			
		||||
			if err := gitPkg.DiffUnstaged(recipeDir); err != nil {
 | 
			
		||||
			if err := gitPkg.DiffUnstaged(recipe.Dir); err != nil {
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,6 @@ import (
 | 
			
		||||
	"coopcloud.tech/abra/cli/internal"
 | 
			
		||||
	appPkg "coopcloud.tech/abra/pkg/app"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/client"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/envfile"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/lint"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/recipe"
 | 
			
		||||
@ -339,9 +338,8 @@ func processRecipeRepoVersion(r recipe.Recipe, version string) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// mergeAbraShEnv merges abra.sh env vars into the app env vars.
 | 
			
		||||
func mergeAbraShEnv(recipeName string, env envfile.AppEnv) error {
 | 
			
		||||
	abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, recipeName, "abra.sh")
 | 
			
		||||
	abraShEnv, err := envfile.ReadAbraShEnvVars(abraShPath)
 | 
			
		||||
func mergeAbraShEnv(recipe recipe.Recipe, env envfile.AppEnv) error {
 | 
			
		||||
	abraShEnv, err := envfile.ReadAbraShEnvVars(recipe.AbraShPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@ -449,7 +447,7 @@ func upgrade(cl *dockerclient.Client, stackName, recipeName,
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err = mergeAbraShEnv(recipeName, app.Env); err != nil {
 | 
			
		||||
	if err = mergeAbraShEnv(app.Recipe, app.Env); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -60,26 +60,26 @@ func TestGetComposeFiles(t *testing.T) {
 | 
			
		||||
		{
 | 
			
		||||
			map[string]string{},
 | 
			
		||||
			[]string{
 | 
			
		||||
				fmt.Sprintf("%s/%s/compose.yml", config.RECIPES_DIR, r.Name),
 | 
			
		||||
				fmt.Sprintf("%s/compose.yml", r.Dir),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			map[string]string{"COMPOSE_FILE": "compose.yml"},
 | 
			
		||||
			[]string{
 | 
			
		||||
				fmt.Sprintf("%s/%s/compose.yml", config.RECIPES_DIR, r.Name),
 | 
			
		||||
				fmt.Sprintf("%s/compose.yml", r.Dir),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			map[string]string{"COMPOSE_FILE": "compose.extra_secret.yml"},
 | 
			
		||||
			[]string{
 | 
			
		||||
				fmt.Sprintf("%s/%s/compose.extra_secret.yml", config.RECIPES_DIR, r.Name),
 | 
			
		||||
				fmt.Sprintf("%s/compose.extra_secret.yml", r.Dir),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			map[string]string{"COMPOSE_FILE": "compose.yml:compose.extra_secret.yml"},
 | 
			
		||||
			[]string{
 | 
			
		||||
				fmt.Sprintf("%s/%s/compose.yml", config.RECIPES_DIR, r.Name),
 | 
			
		||||
				fmt.Sprintf("%s/%s/compose.extra_secret.yml", config.RECIPES_DIR, r.Name),
 | 
			
		||||
				fmt.Sprintf("%s/compose.yml", r.Dir),
 | 
			
		||||
				fmt.Sprintf("%s/compose.extra_secret.yml", r.Dir),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,6 @@
 | 
			
		||||
package envfile_test
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"reflect"
 | 
			
		||||
	"slices"
 | 
			
		||||
	"strings"
 | 
			
		||||
@ -61,8 +60,7 @@ func TestReadAbraShEnvVars(t *testing.T) {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, r.Name, "abra.sh")
 | 
			
		||||
	abraShEnv, err := envfile.ReadAbraShEnvVars(abraShPath)
 | 
			
		||||
	abraShEnv, err := envfile.ReadAbraShEnvVars(r.AbraShPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
@ -91,8 +89,7 @@ func TestReadAbraShCmdNames(t *testing.T) {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, r.Name, "abra.sh")
 | 
			
		||||
	cmdNames, err := appPkg.ReadAbraShCmdNames(abraShPath)
 | 
			
		||||
	cmdNames, err := appPkg.ReadAbraShCmdNames(r.AbraShPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
@ -104,7 +101,7 @@ func TestReadAbraShCmdNames(t *testing.T) {
 | 
			
		||||
	expectedCmdNames := []string{"test_cmd", "test_cmd_args"}
 | 
			
		||||
	for _, cmdName := range expectedCmdNames {
 | 
			
		||||
		if !slices.Contains(cmdNames, cmdName) {
 | 
			
		||||
			t.Fatalf("%s should have been found in %s", cmdName, abraShPath)
 | 
			
		||||
			t.Fatalf("%s should have been found in %s", cmdName, r.AbraShPath)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -460,11 +460,9 @@ func LintSecretLengths(recipe recipe.Recipe) (bool, error) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func LintValidTags(recipe recipe.Recipe) (bool, error) {
 | 
			
		||||
	recipeDir := path.Join(config.RECIPES_DIR, recipe.Name)
 | 
			
		||||
 | 
			
		||||
	repo, err := git.PlainOpen(recipeDir)
 | 
			
		||||
	repo, err := git.PlainOpen(recipe.Dir)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return false, fmt.Errorf("unable to open %s: %s", recipeDir, err)
 | 
			
		||||
		return false, fmt.Errorf("unable to open %s: %s", recipe.Dir, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	iter, err := repo.Tags()
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,8 @@ package recipe
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path"
 | 
			
		||||
 | 
			
		||||
	"coopcloud.tech/abra/pkg/envfile"
 | 
			
		||||
)
 | 
			
		||||
@ -13,3 +15,23 @@ func (r Recipe) SampleEnv() (map[string]string, error) {
 | 
			
		||||
	}
 | 
			
		||||
	return sampleEnv, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetReleaseNotes prints release notes for the recipe version
 | 
			
		||||
func (r Recipe) GetReleaseNotes(version string) (string, error) {
 | 
			
		||||
	if version == "" {
 | 
			
		||||
		return "", nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	fpath := path.Join(r.Dir, "release", version)
 | 
			
		||||
 | 
			
		||||
	if _, err := os.Stat(fpath); !os.IsNotExist(err) {
 | 
			
		||||
		releaseNotes, err := os.ReadFile(fpath)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "", err
 | 
			
		||||
		}
 | 
			
		||||
		withTitle := fmt.Sprintf("%s release notes:\n%s", version, string(releaseNotes))
 | 
			
		||||
		return withTitle, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -132,6 +132,7 @@ func Get(name string) Recipe {
 | 
			
		||||
		ComposePath:   path.Join(dir, "compose.yml"),
 | 
			
		||||
		ReadmePath:    path.Join(dir, "README.md"),
 | 
			
		||||
		SampleEnvPath: path.Join(dir, ".env.sample"),
 | 
			
		||||
		AbraShPath:    path.Join(dir, "abra.sh"),
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -143,6 +144,7 @@ type Recipe struct {
 | 
			
		||||
	ComposePath   string
 | 
			
		||||
	ReadmePath    string
 | 
			
		||||
	SampleEnvPath string
 | 
			
		||||
	AbraShPath    string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetRecipesLocal retrieves all local recipe directories
 | 
			
		||||
@ -581,8 +583,7 @@ func UpdateRepositories(repos RepoCatalogue, recipeName string) error {
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			recipeDir := path.Join(config.RECIPES_DIR, rm.Name)
 | 
			
		||||
			if err := gitPkg.Clone(recipeDir, rm.CloneURL); err != nil {
 | 
			
		||||
			if err := gitPkg.Clone(Get(rm.Name).Dir, rm.CloneURL); err != nil {
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user