From 58e98f490d2f3e29e9e184f48d9f5920dec86540 Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Tue, 25 Jan 2022 12:37:13 +0100 Subject: [PATCH] refactor!: type -> recipes --- cli/app/check.go | 2 +- cli/app/errors.go | 2 +- cli/app/list.go | 24 ++++++------ cli/app/logs.go | 2 +- cli/app/rollback.go | 16 ++++---- cli/app/upgrade.go | 18 ++++----- cli/app/version.go | 2 +- cli/internal/deploy.go | 24 ++++++------ cli/internal/validate.go | 2 +- pkg/config/app.go | 38 +++++++++---------- pkg/config/env.go | 2 +- pkg/config/env_test.go | 10 ++--- pkg/recipe/recipe.go | 2 +- pkg/upstream/stack/loader.go | 4 +- .../servers/evil.corp/ecloud.env | 4 +- 15 files changed, 75 insertions(+), 77 deletions(-) diff --git a/cli/app/check.go b/cli/app/check.go index 7ef3cacd..605259cc 100644 --- a/cli/app/check.go +++ b/cli/app/check.go @@ -24,7 +24,7 @@ var appCheckCommand = cli.Command{ Action: func(c *cli.Context) error { app := internal.ValidateApp(c) - envSamplePath := path.Join(config.RECIPES_DIR, app.Type, ".env.sample") + envSamplePath := path.Join(config.RECIPES_DIR, app.Recipe, ".env.sample") if _, err := os.Stat(envSamplePath); err != nil { if os.IsNotExist(err) { logrus.Fatalf("%s does not exist?", envSamplePath) diff --git a/cli/app/errors.go b/cli/app/errors.go index f18f3a76..ad61c999 100644 --- a/cli/app/errors.go +++ b/cli/app/errors.go @@ -89,7 +89,7 @@ the logs. } func checkErrors(c *cli.Context, cl *dockerClient.Client, app config.App) error { - recipe, err := recipe.Get(app.Type) + recipe, err := recipe.Get(app.Recipe) if err != nil { return err } diff --git a/cli/app/list.go b/cli/app/list.go index 71e18ce1..525d4bcd 100644 --- a/cli/app/list.go +++ b/cli/app/list.go @@ -22,12 +22,12 @@ var statusFlag = &cli.BoolFlag{ Destination: &status, } -var appType string -var typeFlag = &cli.StringFlag{ - Name: "type, t", +var appRecipe string +var recipeFlag = &cli.StringFlag{ + Name: "recipe, r", Value: "", - Usage: "Show apps of a specific type", - Destination: &appType, + Usage: "Show apps of a specific recipe", + Destination: &appRecipe, } var listAppServer string @@ -73,7 +73,7 @@ can take some time. internal.DebugFlag, statusFlag, listAppServerFlag, - typeFlag, + recipeFlag, }, Before: internal.SubCommandBefore, Action: func(c *cli.Context) error { @@ -87,7 +87,7 @@ can take some time. logrus.Fatal(err) } - sort.Sort(config.ByServerAndType(apps)) + sort.Sort(config.ByServerAndRecipe(apps)) statuses := make(map[string]map[string]string) var catl recipe.RecipeCatalogue @@ -122,14 +122,14 @@ can take some time. var ok bool if stats, ok = allStats[app.Server]; !ok { stats = serverStatus{} - if appType == "" { + if appRecipe == "" { // count server, no filtering totalServersCount++ } } - if app.Type == appType || appType == "" { - if appType != "" { + if app.Recipe == appRecipe || appRecipe == "" { + if appRecipe != "" { // only count server if matches filter totalServersCount++ } @@ -160,7 +160,7 @@ can take some time. var newUpdates []string if version != "unknown" { - updates, err := recipe.GetRecipeCatalogueVersions(app.Type, catl) + updates, err := recipe.GetRecipeCatalogueVersions(app.Recipe, catl) if err != nil { logrus.Fatal(err) } @@ -197,7 +197,7 @@ can take some time. } appStats.server = app.Server - appStats.recipe = app.Type + appStats.recipe = app.Recipe appStats.appName = app.Name appStats.domain = app.Domain diff --git a/cli/app/logs.go b/cli/app/logs.go index 599b20ad..8eb88920 100644 --- a/cli/app/logs.go +++ b/cli/app/logs.go @@ -85,7 +85,7 @@ var appLogsCommand = cli.Command{ serviceName := c.Args().Get(1) if serviceName == "" { - logrus.Debugf("tailing logs for all %s services", app.Type) + logrus.Debugf("tailing logs for all %s services", app.Recipe) stackLogs(c, app.StackName(), cl) } else { logrus.Debugf("tailing logs for %s", serviceName) diff --git a/cli/app/rollback.go b/cli/app/rollback.go index 9f6460ce..26f83525 100644 --- a/cli/app/rollback.go +++ b/cli/app/rollback.go @@ -50,12 +50,12 @@ recipes. stackName := app.StackName() if !internal.Chaos { - if err := recipe.EnsureUpToDate(app.Type); err != nil { + if err := recipe.EnsureUpToDate(app.Recipe); err != nil { logrus.Fatal(err) } } - r, err := recipe.Get(app.Type) + r, err := recipe.Get(app.Recipe) if err != nil { logrus.Fatal(err) } @@ -85,13 +85,13 @@ recipes. logrus.Fatal(err) } - versions, err := recipe.GetRecipeCatalogueVersions(app.Type, catl) + versions, err := recipe.GetRecipeCatalogueVersions(app.Recipe, catl) if err != nil { logrus.Fatal(err) } if len(versions) == 0 && !internal.Chaos { - logrus.Fatalf("no published releases for %s in the recipe catalogue?", app.Type) + logrus.Fatalf("no published releases for %s in the recipe catalogue?", app.Recipe) } var availableDowngrades []string @@ -140,7 +140,7 @@ recipes. } if !internal.Chaos { - if err := recipe.EnsureVersion(app.Type, chosenDowngrade); err != nil { + if err := recipe.EnsureVersion(app.Recipe, chosenDowngrade); err != nil { logrus.Fatal(err) } } @@ -148,13 +148,13 @@ recipes. if internal.Chaos { logrus.Warn("chaos mode engaged") var err error - chosenDowngrade, err = recipe.ChaosVersion(app.Type) + chosenDowngrade, err = recipe.ChaosVersion(app.Recipe) if err != nil { logrus.Fatal(err) } } - abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, app.Type, "abra.sh") + abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, app.Recipe, "abra.sh") abraShEnv, err := config.ReadAbraShEnvVars(abraShPath) if err != nil { logrus.Fatal(err) @@ -163,7 +163,7 @@ recipes. app.Env[k] = v } - composeFiles, err := config.GetAppComposeFiles(app.Type, app.Env) + composeFiles, err := config.GetAppComposeFiles(app.Recipe, app.Env) if err != nil { logrus.Fatal(err) } diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index ff995921..d3e66ee5 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -53,12 +53,12 @@ recipes. stackName := app.StackName() if !internal.Chaos { - if err := recipe.EnsureUpToDate(app.Type); err != nil { + if err := recipe.EnsureUpToDate(app.Recipe); err != nil { logrus.Fatal(err) } } - r, err := recipe.Get(app.Type) + r, err := recipe.Get(app.Recipe) if err != nil { logrus.Fatal(err) } @@ -88,13 +88,13 @@ recipes. logrus.Fatal(err) } - versions, err := recipe.GetRecipeCatalogueVersions(app.Type, catl) + versions, err := recipe.GetRecipeCatalogueVersions(app.Recipe, catl) if err != nil { logrus.Fatal(err) } if len(versions) == 0 && !internal.Chaos { - logrus.Fatalf("no published releases for %s in the recipe catalogue?", app.Type) + logrus.Fatalf("no published releases for %s in the recipe catalogue?", app.Recipe) } var availableUpgrades []string @@ -145,13 +145,13 @@ recipes. // if release notes written after git tag published, read them before we // check out the tag and then they'll appear to be missing. this covers // when we obviously will forget to write release notes before publishing - releaseNotes, err := internal.GetReleaseNotes(app.Type, chosenUpgrade) + releaseNotes, err := internal.GetReleaseNotes(app.Recipe, chosenUpgrade) if err != nil { return err } if !internal.Chaos { - if err := recipe.EnsureVersion(app.Type, chosenUpgrade); err != nil { + if err := recipe.EnsureVersion(app.Recipe, chosenUpgrade); err != nil { logrus.Fatal(err) } } @@ -159,13 +159,13 @@ recipes. if internal.Chaos { logrus.Warn("chaos mode engaged") var err error - chosenUpgrade, err = recipe.ChaosVersion(app.Type) + chosenUpgrade, err = recipe.ChaosVersion(app.Recipe) if err != nil { logrus.Fatal(err) } } - abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, app.Type, "abra.sh") + abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, app.Recipe, "abra.sh") abraShEnv, err := config.ReadAbraShEnvVars(abraShPath) if err != nil { logrus.Fatal(err) @@ -174,7 +174,7 @@ recipes. app.Env[k] = v } - composeFiles, err := config.GetAppComposeFiles(app.Type, app.Env) + composeFiles, err := config.GetAppComposeFiles(app.Recipe, app.Env) if err != nil { logrus.Fatal(err) } diff --git a/cli/app/version.go b/cli/app/version.go index 1e0238ad..f0ec498b 100644 --- a/cli/app/version.go +++ b/cli/app/version.go @@ -69,7 +69,7 @@ Cloud recipe version. logrus.Fatalf("%s is not deployed?", app.Name) } - recipeMeta, err := recipe.GetRecipeMeta(app.Type) + recipeMeta, err := recipe.GetRecipeMeta(app.Recipe) if err != nil { logrus.Fatal(err) } diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index 90f40f25..96acbfcd 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -26,12 +26,12 @@ func DeployAction(c *cli.Context) error { app := ValidateApp(c) if !Chaos { - if err := recipe.EnsureUpToDate(app.Type); err != nil { + if err := recipe.EnsureUpToDate(app.Recipe); err != nil { logrus.Fatal(err) } } - r, err := recipe.Get(app.Type) + r, err := recipe.Get(app.Recipe) if err != nil { logrus.Fatal(err) } @@ -66,24 +66,24 @@ func DeployAction(c *cli.Context) error { if err != nil { logrus.Fatal(err) } - versions, err := recipe.GetRecipeCatalogueVersions(app.Type, catl) + versions, err := recipe.GetRecipeCatalogueVersions(app.Recipe, catl) if err != nil { logrus.Fatal(err) } if len(versions) > 0 { version = versions[len(versions)-1] logrus.Debugf("choosing %s as version to deploy", version) - if err := recipe.EnsureVersion(app.Type, version); err != nil { + if err := recipe.EnsureVersion(app.Recipe, version); err != nil { logrus.Fatal(err) } } else { - head, err := git.GetRecipeHead(app.Type) + head, err := git.GetRecipeHead(app.Recipe) if err != nil { logrus.Fatal(err) } version = formatter.SmallSHA(head.String()) logrus.Warn("no versions detected, using latest commit") - if err := recipe.EnsureLatest(app.Type); err != nil { + if err := recipe.EnsureLatest(app.Recipe); err != nil { logrus.Fatal(err) } } @@ -91,13 +91,13 @@ func DeployAction(c *cli.Context) error { if version == "unknown" && !Chaos { logrus.Debugf("choosing %s as version to deploy", version) - if err := recipe.EnsureVersion(app.Type, version); err != nil { + if err := recipe.EnsureVersion(app.Recipe, version); err != nil { logrus.Fatal(err) } } if version != "unknown" && !Chaos { - if err := recipe.EnsureVersion(app.Type, version); err != nil { + if err := recipe.EnsureVersion(app.Recipe, version); err != nil { logrus.Fatal(err) } } @@ -105,13 +105,13 @@ func DeployAction(c *cli.Context) error { if Chaos { logrus.Warnf("chaos mode engaged") var err error - version, err = recipe.ChaosVersion(app.Type) + version, err = recipe.ChaosVersion(app.Recipe) if err != nil { logrus.Fatal(err) } } - abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, app.Type, "abra.sh") + abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, app.Recipe, "abra.sh") abraShEnv, err := config.ReadAbraShEnvVars(abraShPath) if err != nil { logrus.Fatal(err) @@ -120,7 +120,7 @@ func DeployAction(c *cli.Context) error { app.Env[k] = v } - composeFiles, err := config.GetAppComposeFiles(app.Type, app.Env) + composeFiles, err := config.GetAppComposeFiles(app.Recipe, app.Env) if err != nil { logrus.Fatal(err) } @@ -218,7 +218,7 @@ func NewVersionOverview(app config.App, currentVersion, newVersion, releaseNotes if releaseNotes == "" { var err error - releaseNotes, err = GetReleaseNotes(app.Type, newVersion) + releaseNotes, err = GetReleaseNotes(app.Recipe, newVersion) if err != nil { return err } diff --git a/cli/internal/validate.go b/cli/internal/validate.go index 46745b94..1c87904b 100644 --- a/cli/internal/validate.go +++ b/cli/internal/validate.go @@ -122,7 +122,7 @@ func ValidateApp(c *cli.Context) config.App { logrus.Fatal(err) } - if err := recipe.EnsureExists(app.Type); err != nil { + if err := recipe.EnsureExists(app.Recipe); err != nil { logrus.Fatal(err) } diff --git a/pkg/config/app.go b/pkg/config/app.go index a2868d42..6556c7f0 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -36,7 +36,7 @@ type AppFiles map[AppName]AppFile // App reprents an app with its env file read into memory type App struct { Name AppName - Type string + Recipe string Domain string Env AppEnv Server string @@ -63,8 +63,6 @@ func (a App) StackName() string { return stackName } -// SORTING TYPES - // ByServer sort a slice of Apps type ByServer []App @@ -74,25 +72,25 @@ func (a ByServer) Less(i, j int) bool { return strings.ToLower(a[i].Server) < strings.ToLower(a[j].Server) } -// ByServerAndType sort a slice of Apps -type ByServerAndType []App +// ByServerAndRecipe sort a slice of Apps +type ByServerAndRecipe []App -func (a ByServerAndType) Len() int { return len(a) } -func (a ByServerAndType) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a ByServerAndType) Less(i, j int) bool { +func (a ByServerAndRecipe) Len() int { return len(a) } +func (a ByServerAndRecipe) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByServerAndRecipe) Less(i, j int) bool { if a[i].Server == a[j].Server { - return strings.ToLower(a[i].Type) < strings.ToLower(a[j].Type) + return strings.ToLower(a[i].Recipe) < strings.ToLower(a[j].Recipe) } return strings.ToLower(a[i].Server) < strings.ToLower(a[j].Server) } -// ByType sort a slice of Apps -type ByType []App +// ByRecipe sort a slice of Apps +type ByRecipe []App -func (a ByType) Len() int { return len(a) } -func (a ByType) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a ByType) Less(i, j int) bool { - return strings.ToLower(a[i].Type) < strings.ToLower(a[j].Type) +func (a ByRecipe) Len() int { return len(a) } +func (a ByRecipe) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByRecipe) Less(i, j int) bool { + return strings.ToLower(a[i].Recipe) < strings.ToLower(a[j].Recipe) } // ByName sort a slice of Apps @@ -124,15 +122,15 @@ func readAppEnvFile(appFile AppFile, name AppName) (App, error) { func newApp(env AppEnv, name string, appFile AppFile) (App, error) { domain := env["DOMAIN"] - appType, exists := env["TYPE"] + recipe, exists := env["RECIPE"] if !exists { - return App{}, fmt.Errorf("%s is missing the TYPE env var", name) + return App{}, fmt.Errorf("%s is missing the RECIPE env var", name) } return App{ Name: name, Domain: domain, - Type: appType, + Recipe: recipe, Env: env, Server: appFile.Server, Path: appFile.Path, @@ -219,13 +217,13 @@ func GetAppServiceNames(appName string) ([]string, error) { return serviceNames, err } - composeFiles, err := GetAppComposeFiles(app.Type, app.Env) + composeFiles, err := GetAppComposeFiles(app.Recipe, app.Env) if err != nil { return serviceNames, err } opts := stack.Deploy{Composefiles: composeFiles} - compose, err := GetAppComposeConfig(app.Type, opts, app.Env) + compose, err := GetAppComposeConfig(app.Recipe, opts, app.Env) if err != nil { return serviceNames, err } diff --git a/pkg/config/env.go b/pkg/config/env.go index 00e7c45c..44c40578 100644 --- a/pkg/config/env.go +++ b/pkg/config/env.go @@ -16,7 +16,7 @@ import ( var ABRA_DIR = os.ExpandEnv("$HOME/.abra") var SERVERS_DIR = path.Join(ABRA_DIR, "servers") -var RECIPES_DIR = path.Join(ABRA_DIR, "apps") +var RECIPES_DIR = path.Join(ABRA_DIR, "recipes") var VENDOR_DIR = path.Join(ABRA_DIR, "vendor") var RECIPES_JSON = path.Join(ABRA_DIR, "catalogue", "recipes.json") var REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud" diff --git a/pkg/config/env_test.go b/pkg/config/env_test.go index f13ab989..58ddb726 100644 --- a/pkg/config/env_test.go +++ b/pkg/config/env_test.go @@ -20,12 +20,12 @@ var serverName = "evil.corp" var expectedAppEnv = AppEnv{ "DOMAIN": "ecloud.evil.corp", - "TYPE": "ecloud", + "RECIPE": "ecloud", } var expectedApp = App{ Name: appName, - Type: expectedAppEnv["TYPE"], + Recipe: expectedAppEnv["RECIPE"], Domain: expectedAppEnv["DOMAIN"], Env: expectedAppEnv, Path: expectedAppFile.Path, @@ -74,11 +74,11 @@ func TestReadEnv(t *testing.T) { } if !reflect.DeepEqual(env, expectedAppEnv) { t.Fatalf( - "did not get expected application settings. Expected: DOMAIN=%s TYPE=%s; Got: DOMAIN=%s TYPE=%s", + "did not get expected application settings. Expected: DOMAIN=%s RECIPE=%s; Got: DOMAIN=%s RECIPE=%s", expectedAppEnv["DOMAIN"], - expectedAppEnv["TYPE"], + expectedAppEnv["RECIPE"], env["DOMAIN"], - env["TYPE"], + env["RECIPE"], ) } } diff --git a/pkg/recipe/recipe.go b/pkg/recipe/recipe.go index db9c803e..4f18f8bf 100644 --- a/pkg/recipe/recipe.go +++ b/pkg/recipe/recipe.go @@ -26,7 +26,7 @@ import ( ) // RecipeCatalogueURL is the only current recipe catalogue available. -const RecipeCatalogueURL = "https://apps.coopcloud.tech" +const RecipeCatalogueURL = "https://recipes.coopcloud.tech" // ReposMetadataURL is the recipe repository metadata const ReposMetadataURL = "https://git.coopcloud.tech/api/v1/orgs/coop-cloud/repos" diff --git a/pkg/upstream/stack/loader.go b/pkg/upstream/stack/loader.go index 5686c4c2..bb621666 100644 --- a/pkg/upstream/stack/loader.go +++ b/pkg/upstream/stack/loader.go @@ -38,13 +38,13 @@ func LoadComposefile(opts Deploy, appEnv map[string]string) (*composetypes.Confi unsupportedProperties := loader.GetUnsupportedProperties(dicts...) if len(unsupportedProperties) > 0 { logrus.Warnf("%s: ignoring unsupported options: %s", - appEnv["TYPE"], strings.Join(unsupportedProperties, ", ")) + appEnv["RECIPE"], strings.Join(unsupportedProperties, ", ")) } deprecatedProperties := loader.GetDeprecatedProperties(dicts...) if len(deprecatedProperties) > 0 { logrus.Warnf("%s: ignoring deprecated options: %s", - appEnv["TYPE"], propertyWarnings(deprecatedProperties)) + appEnv["RECIPE"], propertyWarnings(deprecatedProperties)) } return config, nil } diff --git a/tests/resources/valid_abra_config/servers/evil.corp/ecloud.env b/tests/resources/valid_abra_config/servers/evil.corp/ecloud.env index d5aa434c..feb7610c 100644 --- a/tests/resources/valid_abra_config/servers/evil.corp/ecloud.env +++ b/tests/resources/valid_abra_config/servers/evil.corp/ecloud.env @@ -1,2 +1,2 @@ -TYPE=ecloud -DOMAIN=ecloud.evil.corp \ No newline at end of file +RECIPE=ecloud +DOMAIN=ecloud.evil.corp