refactor(recipe): rename Recipe2 -> Recipe

This commit is contained in:
p4u1 2024-07-08 13:19:40 +02:00
parent f638b6a16b
commit f14d49cc64
21 changed files with 85 additions and 85 deletions

View File

@ -211,7 +211,7 @@ var appCmdListCommand = cli.Command{
Before: internal.SubCommandBefore, Before: internal.SubCommandBefore,
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
app := internal.ValidateApp(c) app := internal.ValidateApp(c)
r := recipe.Get2(app.Name) r := recipe.Get(app.Name)
if err := r.EnsureExists(); err != nil { if err := r.EnsureExists(); err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -230,7 +230,7 @@ func createSecrets(cl *dockerClient.Client, secretsConfig map[string]secret.Secr
} }
// ensureDomainFlag checks if the domain flag was used. if not, asks the user for it/ // ensureDomainFlag checks if the domain flag was used. if not, asks the user for it/
func ensureDomainFlag(recipe recipePkg.Recipe2, server string) error { func ensureDomainFlag(recipe recipePkg.Recipe, server string) error {
if internal.Domain == "" && !internal.NoInput { if internal.Domain == "" && !internal.NoInput {
prompt := &survey.Input{ prompt := &survey.Input{
Message: "Specify app domain", Message: "Specify app domain",

View File

@ -67,7 +67,7 @@ var appPsCommand = cli.Command{
// showPSOutput renders ps output. // showPSOutput renders ps output.
func showPSOutput(app appPkg.App, cl *dockerClient.Client) { func showPSOutput(app appPkg.App, cl *dockerClient.Client) {
r := recipe.Get2(app.Name) r := recipe.Get(app.Name)
composeFiles, err := r.GetComposeFiles(app.Env) composeFiles, err := r.GetComposeFiles(app.Env)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -57,7 +57,7 @@ keys configured on your account.
BashComplete: autocomplete.RecipeNameComplete, BashComplete: autocomplete.RecipeNameComplete,
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
recipeName := c.Args().First() recipeName := c.Args().First()
r := recipe.Get2(recipeName) r := recipe.Get(recipeName)
if recipeName != "" { if recipeName != "" {
internal.ValidateRecipe(c) internal.ValidateRecipe(c)

View File

@ -85,7 +85,7 @@ func SetBumpType(bumpType string) {
} }
// GetMainAppImage retrieves the main 'app' image name // GetMainAppImage retrieves the main 'app' image name
func GetMainAppImage(recipe recipe.Recipe2) (string, error) { func GetMainAppImage(recipe recipe.Recipe) (string, error) {
var path string var path string
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)

View File

@ -13,7 +13,7 @@ import (
) )
// ValidateRecipe ensures the recipe arg is valid. // ValidateRecipe ensures the recipe arg is valid.
func ValidateRecipe(c *cli.Context) recipe.Recipe2 { func ValidateRecipe(c *cli.Context) recipe.Recipe {
recipeName := c.Args().First() recipeName := c.Args().First()
if recipeName == "" && !NoInput { if recipeName == "" && !NoInput {
@ -57,7 +57,7 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe2 {
ShowSubcommandHelpAndError(c, errors.New("no recipe name provided")) ShowSubcommandHelpAndError(c, errors.New("no recipe name provided"))
} }
chosenRecipe := recipe.Get2(recipeName) chosenRecipe := recipe.Get(recipeName)
err := chosenRecipe.EnsureExists() err := chosenRecipe.EnsureExists()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -24,7 +24,7 @@ var recipeFetchCommand = cli.Command{
BashComplete: autocomplete.RecipeNameComplete, BashComplete: autocomplete.RecipeNameComplete,
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
recipeName := c.Args().First() recipeName := c.Args().First()
r := recipe.Get2(recipeName) r := recipe.Get(recipeName)
if recipeName != "" { if recipeName != "" {
internal.ValidateRecipe(c) internal.ValidateRecipe(c)
if err := r.Ensure(false, false); err != nil { if err := r.Ensure(false, false); err != nil {
@ -40,7 +40,7 @@ var recipeFetchCommand = cli.Command{
catlBar := formatter.CreateProgressbar(len(catalogue), "fetching latest recipes...") catlBar := formatter.CreateProgressbar(len(catalogue), "fetching latest recipes...")
for recipeName := range catalogue { for recipeName := range catalogue {
r := recipe.Get2(recipeName) r := recipe.Get(recipeName)
if err := r.Ensure(false, false); err != nil { if err := r.Ensure(false, false); err != nil {
log.Error(err) log.Error(err)
} }

View File

@ -56,7 +56,7 @@ recipe and domain in the sample environment config).
`, `,
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
recipeName := c.Args().First() recipeName := c.Args().First()
r := recipe.Get2(recipeName) r := recipe.Get(recipeName)
if recipeName == "" { if recipeName == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe name provided")) internal.ShowSubcommandHelpAndError(c, errors.New("no recipe name provided"))

View File

@ -141,7 +141,7 @@ your SSH keys configured on your account.
} }
// getImageVersions retrieves image versions for a recipe // getImageVersions retrieves image versions for a recipe
func getImageVersions(recipe recipe.Recipe2) (map[string]string, error) { func getImageVersions(recipe recipe.Recipe) (map[string]string, error) {
services := make(map[string]string) services := make(map[string]string)
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
@ -185,7 +185,7 @@ func getImageVersions(recipe recipe.Recipe2) (map[string]string, error) {
} }
// createReleaseFromTag creates a new release based on a supplied recipe version string // createReleaseFromTag creates a new release based on a supplied recipe version string
func createReleaseFromTag(recipe recipe.Recipe2, tagString, mainAppVersion string) error { func createReleaseFromTag(recipe recipe.Recipe, tagString, mainAppVersion string) error {
var err error var err error
directory := path.Join(config.RECIPES_DIR, recipe.Name) directory := path.Join(config.RECIPES_DIR, recipe.Name)
@ -249,7 +249,7 @@ func getTagCreateOptions(tag string) (git.CreateTagOptions, error) {
// addReleaseNotes checks if the release/next release note exists and moves the // addReleaseNotes checks if the release/next release note exists and moves the
// file to release/<tag>. // file to release/<tag>.
func addReleaseNotes(recipe recipe.Recipe2, tag string) error { func addReleaseNotes(recipe recipe.Recipe, tag string) error {
repoPath := path.Join(config.RECIPES_DIR, recipe.Name) repoPath := path.Join(config.RECIPES_DIR, recipe.Name)
tagReleaseNotePath := path.Join(repoPath, "release", tag) tagReleaseNotePath := path.Join(repoPath, "release", tag)
if _, err := os.Stat(tagReleaseNotePath); err == nil { if _, err := os.Stat(tagReleaseNotePath); err == nil {
@ -323,7 +323,7 @@ func addReleaseNotes(recipe recipe.Recipe2, tag string) error {
return nil return nil
} }
func commitRelease(recipe recipe.Recipe2, tag string) error { func commitRelease(recipe recipe.Recipe, tag string) error {
if internal.Dry { if internal.Dry {
log.Debugf("dry run: no changes committed") log.Debugf("dry run: no changes committed")
return nil return nil
@ -376,7 +376,7 @@ func tagRelease(tagString string, repo *git.Repository) error {
return nil return nil
} }
func pushRelease(recipe recipe.Recipe2, tagString string) error { func pushRelease(recipe recipe.Recipe, tagString string) error {
if internal.Dry { if internal.Dry {
log.Info("dry run: no changes published") log.Info("dry run: no changes published")
return nil return nil
@ -405,7 +405,7 @@ func pushRelease(recipe recipe.Recipe2, tagString string) error {
return nil return nil
} }
func createReleaseFromPreviousTag(tagString, mainAppVersion string, recipe recipe.Recipe2, tags []string) error { func createReleaseFromPreviousTag(tagString, mainAppVersion string, recipe recipe.Recipe, tags []string) error {
directory := path.Join(config.RECIPES_DIR, recipe.Name) directory := path.Join(config.RECIPES_DIR, recipe.Name)
repo, err := git.PlainOpen(directory) repo, err := git.PlainOpen(directory)
if err != nil { if err != nil {
@ -528,7 +528,7 @@ func cleanUpTag(tag, recipeName string) error {
return nil return nil
} }
func getLabelVersion(recipe recipe.Recipe2, prompt bool) (string, error) { func getLabelVersion(recipe recipe.Recipe, prompt bool) (string, error) {
initTag, err := recipe.GetVersionLabelLocal() initTag, err := recipe.GetVersionLabelLocal()
if err != nil { if err != nil {
return "", err return "", err

View File

@ -318,7 +318,7 @@ func getAvailableUpgrades(cl *dockerclient.Client, stackName string, recipeName
// processRecipeRepoVersion clones, pulls, checks out the version and lints the // processRecipeRepoVersion clones, pulls, checks out the version and lints the
// recipe repository. // recipe repository.
func processRecipeRepoVersion(r recipe.Recipe2, version string) error { func processRecipeRepoVersion(r recipe.Recipe, version string) error {
if err := r.EnsureExists(); err != nil { if err := r.EnsureExists(); err != nil {
return err return err
} }
@ -355,7 +355,7 @@ func mergeAbraShEnv(recipeName string, env envfile.AppEnv) error {
} }
// createDeployConfig merges and enriches the compose config for the deployment. // createDeployConfig merges and enriches the compose config for the deployment.
func createDeployConfig(r recipe.Recipe2, stackName string, env envfile.AppEnv) (*composetypes.Config, stack.Deploy, error) { func createDeployConfig(r recipe.Recipe, stackName string, env envfile.AppEnv) (*composetypes.Config, stack.Deploy, error) {
env["STACK_NAME"] = stackName env["STACK_NAME"] = stackName
deployOpts := stack.Deploy{ deployOpts := stack.Deploy{
@ -438,12 +438,12 @@ func upgrade(cl *dockerclient.Client, stackName, recipeName,
app := appPkg.App{ app := appPkg.App{
Name: stackName, Name: stackName,
Recipe: recipe.Get2(recipeName), Recipe: recipe.Get(recipeName),
Server: SERVER, Server: SERVER,
Env: env, Env: env,
} }
r := recipe.Get2(recipeName) r := recipe.Get(recipeName)
if err = processRecipeRepoVersion(r, upgradeVersion); err != nil { if err = processRecipeRepoVersion(r, upgradeVersion); err != nil {
return err return err

View File

@ -84,7 +84,7 @@ func GetApps(appFiles AppFiles, recipeFilter string) ([]App, error) {
// App reprents an app with its env file read into memory // App reprents an app with its env file read into memory
type App struct { type App struct {
Name AppName Name AppName
Recipe recipe.Recipe2 Recipe recipe.Recipe
Domain string Domain string
Env envfile.AppEnv Env envfile.AppEnv
Server string Server string
@ -260,7 +260,7 @@ func NewApp(env envfile.AppEnv, name string, appFile AppFile) (App, error) {
return App{ return App{
Name: name, Name: name,
Domain: domain, Domain: domain,
Recipe: recipe.Get2(recipeName), Recipe: recipe.Get(recipeName),
Env: env, Env: env,
Server: appFile.Server, Server: appFile.Server,
Path: appFile.Path, Path: appFile.Path,
@ -358,7 +358,7 @@ func GetAppNames() ([]string, error) {
// TemplateAppEnvSample copies the example env file for the app into the users // TemplateAppEnvSample copies the example env file for the app into the users
// env files. // env files.
func TemplateAppEnvSample(r recipe.Recipe2, appName, server, domain string) error { func TemplateAppEnvSample(r recipe.Recipe, appName, server, domain string) error {
envSample, err := os.ReadFile(r.SampleEnvPath) envSample, err := os.ReadFile(r.SampleEnvPath)
if err != nil { if err != nil {
return err return err

View File

@ -47,7 +47,7 @@ func TestGetApp(t *testing.T) {
} }
func TestGetComposeFiles(t *testing.T) { func TestGetComposeFiles(t *testing.T) {
r := recipe.Get2("abra-test-recipe") r := recipe.Get("abra-test-recipe")
err := r.EnsureExists() err := r.EnsureExists()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -85,7 +85,7 @@ func TestGetComposeFiles(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
r2 := recipe.Get2(r.Name) r2 := recipe.Get(r.Name)
composeFiles, err := r2.GetComposeFiles(test.appEnv) composeFiles, err := r2.GetComposeFiles(test.appEnv)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -95,7 +95,7 @@ func TestGetComposeFiles(t *testing.T) {
} }
func TestGetComposeFilesError(t *testing.T) { func TestGetComposeFilesError(t *testing.T) {
r := recipe.Get2("abra-test-recipe") r := recipe.Get("abra-test-recipe")
err := r.EnsureExists() err := r.EnsureExists()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -107,7 +107,7 @@ func TestGetComposeFilesError(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
r2 := recipe.Get2(r.Name) r2 := recipe.Get(r.Name)
_, err := r2.GetComposeFiles(test.appEnv) _, err := r2.GetComposeFiles(test.appEnv)
if err == nil { if err == nil {
t.Fatalf("should have failed: %v", test.appEnv) t.Fatalf("should have failed: %v", test.appEnv)

View File

@ -55,7 +55,7 @@ func TestReadEnv(t *testing.T) {
} }
func TestReadAbraShEnvVars(t *testing.T) { func TestReadAbraShEnvVars(t *testing.T) {
r := recipe.Get2("abra-test-recipe") r := recipe.Get("abra-test-recipe")
err := r.EnsureExists() err := r.EnsureExists()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -85,7 +85,7 @@ func TestReadAbraShEnvVars(t *testing.T) {
} }
func TestReadAbraShCmdNames(t *testing.T) { func TestReadAbraShCmdNames(t *testing.T) {
r := recipe.Get2("abra-test-recipe") r := recipe.Get("abra-test-recipe")
err := r.EnsureExists() err := r.EnsureExists()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -110,13 +110,13 @@ func TestReadAbraShCmdNames(t *testing.T) {
} }
func TestCheckEnv(t *testing.T) { func TestCheckEnv(t *testing.T) {
r := recipe.Get2("abra-test-recipe") r := recipe.Get("abra-test-recipe")
err := r.EnsureExists() err := r.EnsureExists()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
r2 := recipe.Get2(r.Name) r2 := recipe.Get(r.Name)
envSample, err := r2.SampleEnv() envSample, err := r2.SampleEnv()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -124,7 +124,7 @@ func TestCheckEnv(t *testing.T) {
app := appPkg.App{ app := appPkg.App{
Name: "test-app", Name: "test-app",
Recipe: recipe.Get2(r.Name), Recipe: recipe.Get(r.Name),
Domain: "example.com", Domain: "example.com",
Env: envSample, Env: envSample,
Path: "example.com.env", Path: "example.com.env",
@ -144,13 +144,13 @@ func TestCheckEnv(t *testing.T) {
} }
func TestCheckEnvError(t *testing.T) { func TestCheckEnvError(t *testing.T) {
r := recipe.Get2("abra-test-recipe") r := recipe.Get("abra-test-recipe")
err := r.EnsureExists() err := r.EnsureExists()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
r2 := recipe.Get2(r.Name) r2 := recipe.Get(r.Name)
envSample, err := r2.SampleEnv() envSample, err := r2.SampleEnv()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -160,7 +160,7 @@ func TestCheckEnvError(t *testing.T) {
app := appPkg.App{ app := appPkg.App{
Name: "test-app", Name: "test-app",
Recipe: recipe.Get2(r.Name), Recipe: recipe.Get(r.Name),
Domain: "example.com", Domain: "example.com",
Env: envSample, Env: envSample,
Path: "example.com.env", Path: "example.com.env",
@ -180,13 +180,13 @@ func TestCheckEnvError(t *testing.T) {
} }
func TestEnvVarCommentsRemoved(t *testing.T) { func TestEnvVarCommentsRemoved(t *testing.T) {
r := recipe.Get2("abra-test-recipe") r := recipe.Get("abra-test-recipe")
err := r.EnsureExists() err := r.EnsureExists()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
r2 := recipe.Get2(r.Name) r2 := recipe.Get(r.Name)
envSample, err := r2.SampleEnv() envSample, err := r2.SampleEnv()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -212,7 +212,7 @@ func TestEnvVarCommentsRemoved(t *testing.T) {
} }
func TestEnvVarModifiersIncluded(t *testing.T) { func TestEnvVarModifiersIncluded(t *testing.T) {
r := recipe.Get2("abra-test-recipe") r := recipe.Get("abra-test-recipe")
err := r.EnsureExists() err := r.EnsureExists()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -19,13 +19,13 @@ import (
var Warn = "warn" var Warn = "warn"
var Critical = "critical" var Critical = "critical"
type LintFunction func(recipe.Recipe2) (bool, error) type LintFunction func(recipe.Recipe) (bool, error)
// SkipFunction determines whether the LintFunction is run or not. It should // SkipFunction determines whether the LintFunction is run or not. It should
// not take the lint rule level into account because some rules are always an // not take the lint rule level into account because some rules are always an
// error but may depend on some additional context of the recipe configuration. // error but may depend on some additional context of the recipe configuration.
// This function aims to cover those additional cases. // This function aims to cover those additional cases.
type SkipFunction func(recipe.Recipe2) (bool, error) type SkipFunction func(recipe.Recipe) (bool, error)
// LintRule is a linting rule which helps a recipe maintainer avoid common // LintRule is a linting rule which helps a recipe maintainer avoid common
// problems in their recipe configurations. We aim to highlight things that // problems in their recipe configurations. We aim to highlight things that
@ -42,7 +42,7 @@ type LintRule struct {
} }
// Skip implements the SkipFunction for the lint rule. // Skip implements the SkipFunction for the lint rule.
func (l LintRule) Skip(recipe recipe.Recipe2) bool { func (l LintRule) Skip(recipe recipe.Recipe) bool {
if l.SkipCondition != nil { if l.SkipCondition != nil {
ok, err := l.SkipCondition(recipe) ok, err := l.SkipCondition(recipe)
if err != nil { if err != nil {
@ -173,7 +173,7 @@ var LintRules = map[string][]LintRule{
// LintForErrors lints specifically for errors and not other levels. This is // LintForErrors lints specifically for errors and not other levels. This is
// used in code paths such as "app deploy" to avoid nasty surprises but not for // used in code paths such as "app deploy" to avoid nasty surprises but not for
// the typical linting commands, which do handle other levels. // the typical linting commands, which do handle other levels.
func LintForErrors(recipe recipe.Recipe2) error { func LintForErrors(recipe recipe.Recipe) error {
log.Debugf("linting for critical errors in %s configs", recipe.Name) log.Debugf("linting for critical errors in %s configs", recipe.Name)
for level := range LintRules { for level := range LintRules {
@ -201,7 +201,7 @@ func LintForErrors(recipe recipe.Recipe2) error {
return nil return nil
} }
func LintComposeVersion(recipe recipe.Recipe2) (bool, error) { func LintComposeVersion(recipe recipe.Recipe) (bool, error) {
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
if err != nil { if err != nil {
return false, err return false, err
@ -213,8 +213,8 @@ func LintComposeVersion(recipe recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintEnvConfigPresent(r recipe.Recipe2) (bool, error) { func LintEnvConfigPresent(r recipe.Recipe) (bool, error) {
r2 := recipe.Get2(r.Name) r2 := recipe.Get(r.Name)
if _, err := os.Stat(r2.SampleEnvPath); !os.IsNotExist(err) { if _, err := os.Stat(r2.SampleEnvPath); !os.IsNotExist(err) {
return true, nil return true, nil
} }
@ -222,7 +222,7 @@ func LintEnvConfigPresent(r recipe.Recipe2) (bool, error) {
return false, nil return false, nil
} }
func LintAppService(recipe recipe.Recipe2) (bool, error) { func LintAppService(recipe recipe.Recipe) (bool, error) {
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
if err != nil { if err != nil {
return false, err return false, err
@ -240,8 +240,8 @@ func LintAppService(recipe recipe.Recipe2) (bool, error) {
// confirms that there is no "DOMAIN=..." in the .env.sample configuration of // confirms that there is no "DOMAIN=..." in the .env.sample configuration of
// the recipe. This typically means that no domain is required to deploy and // the recipe. This typically means that no domain is required to deploy and
// therefore no matching traefik deploy label will be present. // therefore no matching traefik deploy label will be present.
func LintTraefikEnabledSkipCondition(r recipe.Recipe2) (bool, error) { func LintTraefikEnabledSkipCondition(r recipe.Recipe) (bool, error) {
r2 := recipe.Get2(r.Name) r2 := recipe.Get(r.Name)
sampleEnv, err := r2.SampleEnv() sampleEnv, err := r2.SampleEnv()
if err != nil { if err != nil {
return false, fmt.Errorf("Unable to discover .env.sample for %s", r2.Name) return false, fmt.Errorf("Unable to discover .env.sample for %s", r2.Name)
@ -254,7 +254,7 @@ func LintTraefikEnabledSkipCondition(r recipe.Recipe2) (bool, error) {
return false, nil return false, nil
} }
func LintTraefikEnabled(recipe recipe.Recipe2) (bool, error) { func LintTraefikEnabled(recipe recipe.Recipe) (bool, error) {
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
if err != nil { if err != nil {
return false, err return false, err
@ -272,7 +272,7 @@ func LintTraefikEnabled(recipe recipe.Recipe2) (bool, error) {
return false, nil return false, nil
} }
func LintHealthchecks(recipe recipe.Recipe2) (bool, error) { func LintHealthchecks(recipe recipe.Recipe) (bool, error) {
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
if err != nil { if err != nil {
return false, err return false, err
@ -286,7 +286,7 @@ func LintHealthchecks(recipe recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintAllImagesTagged(recipe recipe.Recipe2) (bool, error) { func LintAllImagesTagged(recipe recipe.Recipe) (bool, error) {
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
if err != nil { if err != nil {
return false, err return false, err
@ -304,7 +304,7 @@ func LintAllImagesTagged(recipe recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintNoUnstableTags(recipe recipe.Recipe2) (bool, error) { func LintNoUnstableTags(recipe recipe.Recipe) (bool, error) {
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
if err != nil { if err != nil {
return false, err return false, err
@ -331,7 +331,7 @@ func LintNoUnstableTags(recipe recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintSemverLikeTags(recipe recipe.Recipe2) (bool, error) { func LintSemverLikeTags(recipe recipe.Recipe) (bool, error) {
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
if err != nil { if err != nil {
return false, err return false, err
@ -358,7 +358,7 @@ func LintSemverLikeTags(recipe recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintImagePresent(recipe recipe.Recipe2) (bool, error) { func LintImagePresent(recipe recipe.Recipe) (bool, error) {
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
if err != nil { if err != nil {
return false, err return false, err
@ -371,7 +371,7 @@ func LintImagePresent(recipe recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintHasPublishedVersion(recipe recipe.Recipe2) (bool, error) { func LintHasPublishedVersion(recipe recipe.Recipe) (bool, error) {
catl, err := recipePkg.ReadRecipeCatalogue(false) catl, err := recipePkg.ReadRecipeCatalogue(false)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -389,8 +389,8 @@ func LintHasPublishedVersion(recipe recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintMetadataFilledIn(r recipe.Recipe2) (bool, error) { func LintMetadataFilledIn(r recipe.Recipe) (bool, error) {
r2 := recipe.Get2(r.Name) r2 := recipe.Get(r.Name)
features, category, err := recipe.GetRecipeFeaturesAndCategory(r2) features, category, err := recipe.GetRecipeFeaturesAndCategory(r2)
if err != nil { if err != nil {
return false, err return false, err
@ -411,7 +411,7 @@ func LintMetadataFilledIn(r recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintAbraShVendors(recipe recipe.Recipe2) (bool, error) { func LintAbraShVendors(recipe recipe.Recipe) (bool, error) {
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
if err != nil { if err != nil {
return false, err return false, err
@ -430,7 +430,7 @@ func LintAbraShVendors(recipe recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintHasRecipeRepo(recipe recipe.Recipe2) (bool, error) { func LintHasRecipeRepo(recipe recipe.Recipe) (bool, error) {
url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipe.Name) url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipe.Name)
res, err := http.Get(url) res, err := http.Get(url)
@ -445,7 +445,7 @@ func LintHasRecipeRepo(recipe recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintSecretLengths(recipe recipe.Recipe2) (bool, error) { func LintSecretLengths(recipe recipe.Recipe) (bool, error) {
config, err := recipe.GetComposeConfig(nil) config, err := recipe.GetComposeConfig(nil)
if err != nil { if err != nil {
return false, err return false, err
@ -459,7 +459,7 @@ func LintSecretLengths(recipe recipe.Recipe2) (bool, error) {
return true, nil return true, nil
} }
func LintValidTags(recipe recipe.Recipe2) (bool, error) { func LintValidTags(recipe recipe.Recipe) (bool, error) {
recipeDir := path.Join(config.RECIPES_DIR, recipe.Name) recipeDir := path.Join(config.RECIPES_DIR, recipe.Name)
repo, err := git.PlainOpen(recipeDir) repo, err := git.PlainOpen(recipeDir)

View File

@ -18,7 +18,7 @@ import (
// GetComposeFiles gets the list of compose files for an app (or recipe if you // GetComposeFiles gets the list of compose files for an app (or recipe if you
// don't already have an app) which should be merged into a composetypes.Config // don't already have an app) which should be merged into a composetypes.Config
// while respecting the COMPOSE_FILE env var. // while respecting the COMPOSE_FILE env var.
func (r Recipe2) GetComposeFiles(appEnv map[string]string) ([]string, error) { func (r Recipe) GetComposeFiles(appEnv map[string]string) ([]string, error) {
composeFileEnvVar, ok := appEnv["COMPOSE_FILE"] composeFileEnvVar, ok := appEnv["COMPOSE_FILE"]
if !ok { if !ok {
if err := ensurePathExists(r.ComposePath); err != nil { if err := ensurePathExists(r.ComposePath); err != nil {
@ -59,7 +59,7 @@ func (r Recipe2) GetComposeFiles(appEnv map[string]string) ([]string, error) {
return composeFiles, nil return composeFiles, nil
} }
func (r Recipe2) GetComposeConfig(env map[string]string) (*composetypes.Config, error) { func (r Recipe) GetComposeConfig(env map[string]string) (*composetypes.Config, error) {
pattern := fmt.Sprintf("%s/compose**yml", r.Dir) pattern := fmt.Sprintf("%s/compose**yml", r.Dir)
composeFiles, err := filepath.Glob(pattern) composeFiles, err := filepath.Glob(pattern)
if err != nil { if err != nil {
@ -86,7 +86,7 @@ func (r Recipe2) GetComposeConfig(env map[string]string) (*composetypes.Config,
} }
// GetVersionLabelLocal retrieves the version label on the local recipe config // GetVersionLabelLocal retrieves the version label on the local recipe config
func (r Recipe2) GetVersionLabelLocal() (string, error) { func (r Recipe) GetVersionLabelLocal() (string, error) {
var label string var label string
config, err := r.GetComposeConfig(nil) config, err := r.GetComposeConfig(nil)
if err != nil { if err != nil {
@ -109,7 +109,7 @@ func (r Recipe2) GetVersionLabelLocal() (string, error) {
} }
// UpdateTag updates an image tag in-place on file system local compose files. // UpdateTag updates an image tag in-place on file system local compose files.
func (r Recipe2) UpdateTag(image, tag string) (bool, error) { func (r Recipe) UpdateTag(image, tag string) (bool, error) {
fullPattern := fmt.Sprintf("%s/compose**yml", r.Dir) fullPattern := fmt.Sprintf("%s/compose**yml", r.Dir)
image = formatter.StripTagMeta(image) image = formatter.StripTagMeta(image)
@ -179,7 +179,7 @@ func (r Recipe2) UpdateTag(image, tag string) (bool, error) {
} }
// UpdateLabel updates a label in-place on file system local compose files. // UpdateLabel updates a label in-place on file system local compose files.
func (r Recipe2) UpdateLabel(pattern, serviceName, label string) error { func (r Recipe) UpdateLabel(pattern, serviceName, label string) error {
fullPattern := fmt.Sprintf("%s/%s", r.Dir, pattern) fullPattern := fmt.Sprintf("%s/%s", r.Dir, pattern)
composeFiles, err := filepath.Glob(fullPattern) composeFiles, err := filepath.Glob(fullPattern)
if err != nil { if err != nil {

View File

@ -6,7 +6,7 @@ import (
"coopcloud.tech/abra/pkg/envfile" "coopcloud.tech/abra/pkg/envfile"
) )
func (r Recipe2) SampleEnv() (map[string]string, error) { func (r Recipe) SampleEnv() (map[string]string, error) {
sampleEnv, err := envfile.ReadEnv(r.SampleEnvPath) sampleEnv, err := envfile.ReadEnv(r.SampleEnvPath)
if err != nil { if err != nil {
return sampleEnv, fmt.Errorf("unable to discover .env.sample for %s", r.Name) return sampleEnv, fmt.Errorf("unable to discover .env.sample for %s", r.Name)

View File

@ -16,7 +16,7 @@ import (
) )
// Ensure makes sure the recipe exists, is up to date and has the latest version checked out. // Ensure makes sure the recipe exists, is up to date and has the latest version checked out.
func (r Recipe2) Ensure(chaos bool, offline bool) error { func (r Recipe) Ensure(chaos bool, offline bool) error {
if err := r.EnsureExists(); err != nil { if err := r.EnsureExists(); err != nil {
return err return err
} }
@ -38,7 +38,7 @@ func (r Recipe2) Ensure(chaos bool, offline bool) error {
} }
// EnsureExists ensures that the recipe is locally cloned // EnsureExists ensures that the recipe is locally cloned
func (r Recipe2) EnsureExists() error { func (r Recipe) EnsureExists() error {
recipeDir := path.Join(config.RECIPES_DIR, r.Name) recipeDir := path.Join(config.RECIPES_DIR, r.Name)
if _, err := os.Stat(recipeDir); os.IsNotExist(err) { if _, err := os.Stat(recipeDir); os.IsNotExist(err) {
@ -57,7 +57,7 @@ func (r Recipe2) EnsureExists() error {
} }
// EnsureVersion checks whether a specific version exists for a recipe. // EnsureVersion checks whether a specific version exists for a recipe.
func (r Recipe2) EnsureVersion(version string) error { func (r Recipe) EnsureVersion(version string) error {
recipeDir := path.Join(config.RECIPES_DIR, r.Name) recipeDir := path.Join(config.RECIPES_DIR, r.Name)
if err := gitPkg.EnsureGitRepo(recipeDir); err != nil { if err := gitPkg.EnsureGitRepo(recipeDir); err != nil {
@ -115,7 +115,7 @@ func (r Recipe2) EnsureVersion(version string) error {
} }
// EnsureIsClean makes sure that the recipe repository has no unstaged changes. // EnsureIsClean makes sure that the recipe repository has no unstaged changes.
func (r Recipe2) EnsureIsClean() error { func (r Recipe) EnsureIsClean() error {
recipeDir := path.Join(config.RECIPES_DIR, r.Name) recipeDir := path.Join(config.RECIPES_DIR, r.Name)
isClean, err := gitPkg.IsClean(recipeDir) isClean, err := gitPkg.IsClean(recipeDir)
@ -132,7 +132,7 @@ func (r Recipe2) EnsureIsClean() error {
} }
// EnsureLatest makes sure the latest commit is checked out for the local recipe repository // EnsureLatest makes sure the latest commit is checked out for the local recipe repository
func (r Recipe2) EnsureLatest() error { func (r Recipe) EnsureLatest() error {
recipeDir := path.Join(config.RECIPES_DIR, r.Name) recipeDir := path.Join(config.RECIPES_DIR, r.Name)
if err := gitPkg.EnsureGitRepo(recipeDir); err != nil { if err := gitPkg.EnsureGitRepo(recipeDir); err != nil {
@ -169,7 +169,7 @@ func (r Recipe2) EnsureLatest() error {
} }
// EnsureUpToDate ensures that the local repo is synced to the remote // EnsureUpToDate ensures that the local repo is synced to the remote
func (r Recipe2) EnsureUpToDate() error { func (r Recipe) EnsureUpToDate() error {
recipeDir := path.Join(config.RECIPES_DIR, r.Name) recipeDir := path.Join(config.RECIPES_DIR, r.Name)
repo, err := git.PlainOpen(recipeDir) repo, err := git.PlainOpen(recipeDir)
@ -222,7 +222,7 @@ func (r Recipe2) EnsureUpToDate() error {
} }
// ChaosVersion constructs a chaos mode recipe version. // ChaosVersion constructs a chaos mode recipe version.
func (r Recipe2) ChaosVersion() (string, error) { func (r Recipe) ChaosVersion() (string, error) {
var version string var version string
head, err := gitPkg.GetRecipeHead(r.Name) head, err := gitPkg.GetRecipeHead(r.Name)
@ -247,7 +247,7 @@ func (r Recipe2) ChaosVersion() (string, error) {
// Push pushes the latest changes to a SSH URL remote. You need to have your // Push pushes the latest changes to a SSH URL remote. You need to have your
// local SSH configuration for git.coopcloud.tech working for this to work // local SSH configuration for git.coopcloud.tech working for this to work
func (r Recipe2) Push(dryRun bool) error { func (r Recipe) Push(dryRun bool) error {
repo, err := git.PlainOpen(r.Dir) repo, err := git.PlainOpen(r.Dir)
if err != nil { if err != nil {
return err return err
@ -265,7 +265,7 @@ func (r Recipe2) Push(dryRun bool) error {
} }
// Tags list the recipe tags // Tags list the recipe tags
func (r Recipe2) Tags() ([]string, error) { func (r Recipe) Tags() ([]string, error) {
var tags []string var tags []string
repo, err := git.PlainOpen(r.Dir) repo, err := git.PlainOpen(r.Dir)
@ -291,7 +291,7 @@ func (r Recipe2) Tags() ([]string, error) {
} }
// GetRecipeVersions retrieves all recipe versions. // GetRecipeVersions retrieves all recipe versions.
func (r Recipe2) GetRecipeVersions(offline bool) (RecipeVersions, error) { func (r Recipe) GetRecipeVersions(offline bool) (RecipeVersions, error) {
versions := RecipeVersions{} versions := RecipeVersions{}
log.Debugf("attempting to open git repository in %s", r.Dir) log.Debugf("attempting to open git repository in %s", r.Dir)

View File

@ -122,9 +122,9 @@ type Features struct {
SSO string `json:"sso"` SSO string `json:"sso"`
} }
func Get2(name string) Recipe2 { func Get(name string) Recipe {
dir := path.Join(config.RECIPES_DIR, name) dir := path.Join(config.RECIPES_DIR, name)
return Recipe2{ return Recipe{
Name: name, Name: name,
Dir: dir, Dir: dir,
SSHURL: fmt.Sprintf(config.SSH_URL_TEMPLATE, name), SSHURL: fmt.Sprintf(config.SSH_URL_TEMPLATE, name),
@ -135,7 +135,7 @@ func Get2(name string) Recipe2 {
} }
} }
type Recipe2 struct { type Recipe struct {
Name string Name string
Dir string Dir string
SSHURL string SSHURL string
@ -157,7 +157,7 @@ func GetRecipesLocal() ([]string, error) {
return recipes, nil return recipes, nil
} }
func GetRecipeFeaturesAndCategory(r Recipe2) (Features, string, error) { func GetRecipeFeaturesAndCategory(r Recipe) (Features, string, error) {
feat := Features{} feat := Features{}
var category string var category string

View File

@ -14,7 +14,7 @@ func TestGetVersionLabelLocalDoesNotUseTimeoutLabel(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
r := Get2("traefik") r := Get("traefik")
for i := 1; i < 1000; i++ { for i := 1; i < 1000; i++ {
label, err := r.GetVersionLabelLocal() label, err := r.GetVersionLabelLocal()

View File

@ -246,7 +246,7 @@ type secretStatuses []secretStatus
func PollSecretsStatus(cl *dockerClient.Client, app appPkg.App) (secretStatuses, error) { func PollSecretsStatus(cl *dockerClient.Client, app appPkg.App) (secretStatuses, error) {
var secStats secretStatuses var secStats secretStatuses
r := recipe.Get2(app.Name) r := recipe.Get(app.Name)
composeFiles, err := r.GetComposeFiles(app.Env) composeFiles, err := r.GetComposeFiles(app.Env)
if err != nil { if err != nil {
return secStats, err return secStats, err

View File

@ -33,7 +33,7 @@ var ExpectedAppEnv = envfile.AppEnv{
var ExpectedApp = appPkg.App{ var ExpectedApp = appPkg.App{
Name: AppName, Name: AppName,
Recipe: recipe.Get2(ExpectedAppEnv["RECIPE"]), Recipe: recipe.Get(ExpectedAppEnv["RECIPE"]),
Domain: ExpectedAppEnv["DOMAIN"], Domain: ExpectedAppEnv["DOMAIN"],
Env: ExpectedAppEnv, Env: ExpectedAppEnv,
Path: ExpectedAppFile.Path, Path: ExpectedAppFile.Path,