refactor!: type -> recipes
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is passing Details

This commit is contained in:
decentral1se 2022-01-25 12:37:13 +01:00
parent 224b8865bf
commit 58e98f490d
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
15 changed files with 75 additions and 77 deletions

View File

@ -24,7 +24,7 @@ var appCheckCommand = cli.Command{
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
app := internal.ValidateApp(c) 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 _, err := os.Stat(envSamplePath); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
logrus.Fatalf("%s does not exist?", envSamplePath) logrus.Fatalf("%s does not exist?", envSamplePath)

View File

@ -89,7 +89,7 @@ the logs.
} }
func checkErrors(c *cli.Context, cl *dockerClient.Client, app config.App) error { 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 { if err != nil {
return err return err
} }

View File

@ -22,12 +22,12 @@ var statusFlag = &cli.BoolFlag{
Destination: &status, Destination: &status,
} }
var appType string var appRecipe string
var typeFlag = &cli.StringFlag{ var recipeFlag = &cli.StringFlag{
Name: "type, t", Name: "recipe, r",
Value: "", Value: "",
Usage: "Show apps of a specific type", Usage: "Show apps of a specific recipe",
Destination: &appType, Destination: &appRecipe,
} }
var listAppServer string var listAppServer string
@ -73,7 +73,7 @@ can take some time.
internal.DebugFlag, internal.DebugFlag,
statusFlag, statusFlag,
listAppServerFlag, listAppServerFlag,
typeFlag, recipeFlag,
}, },
Before: internal.SubCommandBefore, Before: internal.SubCommandBefore,
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
@ -87,7 +87,7 @@ can take some time.
logrus.Fatal(err) logrus.Fatal(err)
} }
sort.Sort(config.ByServerAndType(apps)) sort.Sort(config.ByServerAndRecipe(apps))
statuses := make(map[string]map[string]string) statuses := make(map[string]map[string]string)
var catl recipe.RecipeCatalogue var catl recipe.RecipeCatalogue
@ -122,14 +122,14 @@ can take some time.
var ok bool var ok bool
if stats, ok = allStats[app.Server]; !ok { if stats, ok = allStats[app.Server]; !ok {
stats = serverStatus{} stats = serverStatus{}
if appType == "" { if appRecipe == "" {
// count server, no filtering // count server, no filtering
totalServersCount++ totalServersCount++
} }
} }
if app.Type == appType || appType == "" { if app.Recipe == appRecipe || appRecipe == "" {
if appType != "" { if appRecipe != "" {
// only count server if matches filter // only count server if matches filter
totalServersCount++ totalServersCount++
} }
@ -160,7 +160,7 @@ can take some time.
var newUpdates []string var newUpdates []string
if version != "unknown" { if version != "unknown" {
updates, err := recipe.GetRecipeCatalogueVersions(app.Type, catl) updates, err := recipe.GetRecipeCatalogueVersions(app.Recipe, catl)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
@ -197,7 +197,7 @@ can take some time.
} }
appStats.server = app.Server appStats.server = app.Server
appStats.recipe = app.Type appStats.recipe = app.Recipe
appStats.appName = app.Name appStats.appName = app.Name
appStats.domain = app.Domain appStats.domain = app.Domain

View File

@ -85,7 +85,7 @@ var appLogsCommand = cli.Command{
serviceName := c.Args().Get(1) serviceName := c.Args().Get(1)
if serviceName == "" { 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) stackLogs(c, app.StackName(), cl)
} else { } else {
logrus.Debugf("tailing logs for %s", serviceName) logrus.Debugf("tailing logs for %s", serviceName)

View File

@ -50,12 +50,12 @@ recipes.
stackName := app.StackName() stackName := app.StackName()
if !internal.Chaos { if !internal.Chaos {
if err := recipe.EnsureUpToDate(app.Type); err != nil { if err := recipe.EnsureUpToDate(app.Recipe); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
} }
r, err := recipe.Get(app.Type) r, err := recipe.Get(app.Recipe)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
@ -85,13 +85,13 @@ recipes.
logrus.Fatal(err) logrus.Fatal(err)
} }
versions, err := recipe.GetRecipeCatalogueVersions(app.Type, catl) versions, err := recipe.GetRecipeCatalogueVersions(app.Recipe, catl)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
if len(versions) == 0 && !internal.Chaos { 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 var availableDowngrades []string
@ -140,7 +140,7 @@ recipes.
} }
if !internal.Chaos { if !internal.Chaos {
if err := recipe.EnsureVersion(app.Type, chosenDowngrade); err != nil { if err := recipe.EnsureVersion(app.Recipe, chosenDowngrade); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
} }
@ -148,13 +148,13 @@ recipes.
if internal.Chaos { if internal.Chaos {
logrus.Warn("chaos mode engaged") logrus.Warn("chaos mode engaged")
var err error var err error
chosenDowngrade, err = recipe.ChaosVersion(app.Type) chosenDowngrade, err = recipe.ChaosVersion(app.Recipe)
if err != nil { if err != nil {
logrus.Fatal(err) 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) abraShEnv, err := config.ReadAbraShEnvVars(abraShPath)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
@ -163,7 +163,7 @@ recipes.
app.Env[k] = v app.Env[k] = v
} }
composeFiles, err := config.GetAppComposeFiles(app.Type, app.Env) composeFiles, err := config.GetAppComposeFiles(app.Recipe, app.Env)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }

View File

@ -53,12 +53,12 @@ recipes.
stackName := app.StackName() stackName := app.StackName()
if !internal.Chaos { if !internal.Chaos {
if err := recipe.EnsureUpToDate(app.Type); err != nil { if err := recipe.EnsureUpToDate(app.Recipe); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
} }
r, err := recipe.Get(app.Type) r, err := recipe.Get(app.Recipe)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
@ -88,13 +88,13 @@ recipes.
logrus.Fatal(err) logrus.Fatal(err)
} }
versions, err := recipe.GetRecipeCatalogueVersions(app.Type, catl) versions, err := recipe.GetRecipeCatalogueVersions(app.Recipe, catl)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
if len(versions) == 0 && !internal.Chaos { 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 var availableUpgrades []string
@ -145,13 +145,13 @@ recipes.
// if release notes written after git tag published, read them before we // 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 // 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 // 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 { if err != nil {
return err return err
} }
if !internal.Chaos { if !internal.Chaos {
if err := recipe.EnsureVersion(app.Type, chosenUpgrade); err != nil { if err := recipe.EnsureVersion(app.Recipe, chosenUpgrade); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
} }
@ -159,13 +159,13 @@ recipes.
if internal.Chaos { if internal.Chaos {
logrus.Warn("chaos mode engaged") logrus.Warn("chaos mode engaged")
var err error var err error
chosenUpgrade, err = recipe.ChaosVersion(app.Type) chosenUpgrade, err = recipe.ChaosVersion(app.Recipe)
if err != nil { if err != nil {
logrus.Fatal(err) 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) abraShEnv, err := config.ReadAbraShEnvVars(abraShPath)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
@ -174,7 +174,7 @@ recipes.
app.Env[k] = v app.Env[k] = v
} }
composeFiles, err := config.GetAppComposeFiles(app.Type, app.Env) composeFiles, err := config.GetAppComposeFiles(app.Recipe, app.Env)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }

View File

@ -69,7 +69,7 @@ Cloud recipe version.
logrus.Fatalf("%s is not deployed?", app.Name) logrus.Fatalf("%s is not deployed?", app.Name)
} }
recipeMeta, err := recipe.GetRecipeMeta(app.Type) recipeMeta, err := recipe.GetRecipeMeta(app.Recipe)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }

View File

@ -26,12 +26,12 @@ func DeployAction(c *cli.Context) error {
app := ValidateApp(c) app := ValidateApp(c)
if !Chaos { if !Chaos {
if err := recipe.EnsureUpToDate(app.Type); err != nil { if err := recipe.EnsureUpToDate(app.Recipe); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
} }
r, err := recipe.Get(app.Type) r, err := recipe.Get(app.Recipe)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
@ -66,24 +66,24 @@ func DeployAction(c *cli.Context) error {
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
versions, err := recipe.GetRecipeCatalogueVersions(app.Type, catl) versions, err := recipe.GetRecipeCatalogueVersions(app.Recipe, catl)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
if len(versions) > 0 { if len(versions) > 0 {
version = versions[len(versions)-1] version = versions[len(versions)-1]
logrus.Debugf("choosing %s as version to deploy", version) 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) logrus.Fatal(err)
} }
} else { } else {
head, err := git.GetRecipeHead(app.Type) head, err := git.GetRecipeHead(app.Recipe)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
version = formatter.SmallSHA(head.String()) version = formatter.SmallSHA(head.String())
logrus.Warn("no versions detected, using latest commit") 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) logrus.Fatal(err)
} }
} }
@ -91,13 +91,13 @@ func DeployAction(c *cli.Context) error {
if version == "unknown" && !Chaos { if version == "unknown" && !Chaos {
logrus.Debugf("choosing %s as version to deploy", version) 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) logrus.Fatal(err)
} }
} }
if version != "unknown" && !Chaos { 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) logrus.Fatal(err)
} }
} }
@ -105,13 +105,13 @@ func DeployAction(c *cli.Context) error {
if Chaos { if Chaos {
logrus.Warnf("chaos mode engaged") logrus.Warnf("chaos mode engaged")
var err error var err error
version, err = recipe.ChaosVersion(app.Type) version, err = recipe.ChaosVersion(app.Recipe)
if err != nil { if err != nil {
logrus.Fatal(err) 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) abraShEnv, err := config.ReadAbraShEnvVars(abraShPath)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
@ -120,7 +120,7 @@ func DeployAction(c *cli.Context) error {
app.Env[k] = v app.Env[k] = v
} }
composeFiles, err := config.GetAppComposeFiles(app.Type, app.Env) composeFiles, err := config.GetAppComposeFiles(app.Recipe, app.Env)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
@ -218,7 +218,7 @@ func NewVersionOverview(app config.App, currentVersion, newVersion, releaseNotes
if releaseNotes == "" { if releaseNotes == "" {
var err error var err error
releaseNotes, err = GetReleaseNotes(app.Type, newVersion) releaseNotes, err = GetReleaseNotes(app.Recipe, newVersion)
if err != nil { if err != nil {
return err return err
} }

View File

@ -122,7 +122,7 @@ func ValidateApp(c *cli.Context) config.App {
logrus.Fatal(err) logrus.Fatal(err)
} }
if err := recipe.EnsureExists(app.Type); err != nil { if err := recipe.EnsureExists(app.Recipe); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }

View File

@ -36,7 +36,7 @@ type AppFiles map[AppName]AppFile
// 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
Type string Recipe string
Domain string Domain string
Env AppEnv Env AppEnv
Server string Server string
@ -63,8 +63,6 @@ func (a App) StackName() string {
return stackName return stackName
} }
// SORTING TYPES
// ByServer sort a slice of Apps // ByServer sort a slice of Apps
type ByServer []App 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) return strings.ToLower(a[i].Server) < strings.ToLower(a[j].Server)
} }
// ByServerAndType sort a slice of Apps // ByServerAndRecipe sort a slice of Apps
type ByServerAndType []App type ByServerAndRecipe []App
func (a ByServerAndType) Len() int { return len(a) } func (a ByServerAndRecipe) Len() int { return len(a) }
func (a ByServerAndType) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByServerAndRecipe) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByServerAndType) Less(i, j int) bool { func (a ByServerAndRecipe) Less(i, j int) bool {
if a[i].Server == a[j].Server { 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) return strings.ToLower(a[i].Server) < strings.ToLower(a[j].Server)
} }
// ByType sort a slice of Apps // ByRecipe sort a slice of Apps
type ByType []App type ByRecipe []App
func (a ByType) Len() int { return len(a) } func (a ByRecipe) Len() int { return len(a) }
func (a ByType) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByRecipe) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByType) Less(i, j int) bool { func (a ByRecipe) Less(i, j int) bool {
return strings.ToLower(a[i].Type) < strings.ToLower(a[j].Type) return strings.ToLower(a[i].Recipe) < strings.ToLower(a[j].Recipe)
} }
// ByName sort a slice of Apps // 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) { func newApp(env AppEnv, name string, appFile AppFile) (App, error) {
domain := env["DOMAIN"] domain := env["DOMAIN"]
appType, exists := env["TYPE"] recipe, exists := env["RECIPE"]
if !exists { 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{ return App{
Name: name, Name: name,
Domain: domain, Domain: domain,
Type: appType, Recipe: recipe,
Env: env, Env: env,
Server: appFile.Server, Server: appFile.Server,
Path: appFile.Path, Path: appFile.Path,
@ -219,13 +217,13 @@ func GetAppServiceNames(appName string) ([]string, error) {
return serviceNames, err return serviceNames, err
} }
composeFiles, err := GetAppComposeFiles(app.Type, app.Env) composeFiles, err := GetAppComposeFiles(app.Recipe, app.Env)
if err != nil { if err != nil {
return serviceNames, err return serviceNames, err
} }
opts := stack.Deploy{Composefiles: composeFiles} opts := stack.Deploy{Composefiles: composeFiles}
compose, err := GetAppComposeConfig(app.Type, opts, app.Env) compose, err := GetAppComposeConfig(app.Recipe, opts, app.Env)
if err != nil { if err != nil {
return serviceNames, err return serviceNames, err
} }

View File

@ -16,7 +16,7 @@ import (
var ABRA_DIR = os.ExpandEnv("$HOME/.abra") var ABRA_DIR = os.ExpandEnv("$HOME/.abra")
var SERVERS_DIR = path.Join(ABRA_DIR, "servers") 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 VENDOR_DIR = path.Join(ABRA_DIR, "vendor")
var RECIPES_JSON = path.Join(ABRA_DIR, "catalogue", "recipes.json") var RECIPES_JSON = path.Join(ABRA_DIR, "catalogue", "recipes.json")
var REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud" var REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud"

View File

@ -20,12 +20,12 @@ var serverName = "evil.corp"
var expectedAppEnv = AppEnv{ var expectedAppEnv = AppEnv{
"DOMAIN": "ecloud.evil.corp", "DOMAIN": "ecloud.evil.corp",
"TYPE": "ecloud", "RECIPE": "ecloud",
} }
var expectedApp = App{ var expectedApp = App{
Name: appName, Name: appName,
Type: expectedAppEnv["TYPE"], Recipe: expectedAppEnv["RECIPE"],
Domain: expectedAppEnv["DOMAIN"], Domain: expectedAppEnv["DOMAIN"],
Env: expectedAppEnv, Env: expectedAppEnv,
Path: expectedAppFile.Path, Path: expectedAppFile.Path,
@ -74,11 +74,11 @@ func TestReadEnv(t *testing.T) {
} }
if !reflect.DeepEqual(env, expectedAppEnv) { if !reflect.DeepEqual(env, expectedAppEnv) {
t.Fatalf( 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["DOMAIN"],
expectedAppEnv["TYPE"], expectedAppEnv["RECIPE"],
env["DOMAIN"], env["DOMAIN"],
env["TYPE"], env["RECIPE"],
) )
} }
} }

View File

@ -26,7 +26,7 @@ import (
) )
// RecipeCatalogueURL is the only current recipe catalogue available. // 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 // ReposMetadataURL is the recipe repository metadata
const ReposMetadataURL = "https://git.coopcloud.tech/api/v1/orgs/coop-cloud/repos" const ReposMetadataURL = "https://git.coopcloud.tech/api/v1/orgs/coop-cloud/repos"

View File

@ -38,13 +38,13 @@ func LoadComposefile(opts Deploy, appEnv map[string]string) (*composetypes.Confi
unsupportedProperties := loader.GetUnsupportedProperties(dicts...) unsupportedProperties := loader.GetUnsupportedProperties(dicts...)
if len(unsupportedProperties) > 0 { if len(unsupportedProperties) > 0 {
logrus.Warnf("%s: ignoring unsupported options: %s", logrus.Warnf("%s: ignoring unsupported options: %s",
appEnv["TYPE"], strings.Join(unsupportedProperties, ", ")) appEnv["RECIPE"], strings.Join(unsupportedProperties, ", "))
} }
deprecatedProperties := loader.GetDeprecatedProperties(dicts...) deprecatedProperties := loader.GetDeprecatedProperties(dicts...)
if len(deprecatedProperties) > 0 { if len(deprecatedProperties) > 0 {
logrus.Warnf("%s: ignoring deprecated options: %s", logrus.Warnf("%s: ignoring deprecated options: %s",
appEnv["TYPE"], propertyWarnings(deprecatedProperties)) appEnv["RECIPE"], propertyWarnings(deprecatedProperties))
} }
return config, nil return config, nil
} }

View File

@ -1,2 +1,2 @@
TYPE=ecloud RECIPE=ecloud
DOMAIN=ecloud.evil.corp DOMAIN=ecloud.evil.corp