forked from toolshed/abra
refactor: create compose package
This commit is contained in:
@ -19,9 +19,9 @@ var recipeCreateCommand = &cli.Command{
|
||||
Aliases: []string{"c"},
|
||||
ArgsUsage: "<recipe>",
|
||||
Action: func(c *cli.Context) error {
|
||||
recipe := internal.ValidateRecipe(c)
|
||||
recipeName := internal.ValidateRecipe(c)
|
||||
|
||||
directory := path.Join(config.APPS_DIR, recipe)
|
||||
directory := path.Join(config.APPS_DIR, recipeName)
|
||||
if _, err := os.Stat(directory); !os.IsNotExist(err) {
|
||||
logrus.Fatalf("'%s' recipe directory already exists?", directory)
|
||||
return nil
|
||||
@ -34,16 +34,16 @@ var recipeCreateCommand = &cli.Command{
|
||||
return nil
|
||||
}
|
||||
|
||||
gitRepo := path.Join(config.APPS_DIR, recipe, ".git")
|
||||
gitRepo := path.Join(config.APPS_DIR, recipeName, ".git")
|
||||
if err := os.RemoveAll(gitRepo); err != nil {
|
||||
logrus.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
toParse := []string{
|
||||
path.Join(config.APPS_DIR, recipe, "README.md"),
|
||||
path.Join(config.APPS_DIR, recipe, ".env.sample"),
|
||||
path.Join(config.APPS_DIR, recipe, ".drone.yml"),
|
||||
path.Join(config.APPS_DIR, recipeName, "README.md"),
|
||||
path.Join(config.APPS_DIR, recipeName, ".env.sample"),
|
||||
path.Join(config.APPS_DIR, recipeName, ".drone.yml"),
|
||||
}
|
||||
for _, path := range toParse {
|
||||
file, err := os.OpenFile(path, os.O_RDWR, 0755)
|
||||
@ -64,7 +64,7 @@ var recipeCreateCommand = &cli.Command{
|
||||
if err := tpl.Execute(file, struct {
|
||||
Name string
|
||||
Description string
|
||||
}{recipe, "TODO"}); err != nil {
|
||||
}{recipeName, "TODO"}); err != nil {
|
||||
logrus.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
@ -72,7 +72,7 @@ var recipeCreateCommand = &cli.Command{
|
||||
|
||||
logrus.Infof(
|
||||
"New recipe '%s' created in %s, happy hacking!\n",
|
||||
recipe, path.Join(config.APPS_DIR, recipe),
|
||||
recipeName, path.Join(config.APPS_DIR, recipeName),
|
||||
)
|
||||
|
||||
return nil
|
||||
|
@ -23,9 +23,9 @@ var recipeLintCommand = &cli.Command{
|
||||
Aliases: []string{"l"},
|
||||
ArgsUsage: "<recipe>",
|
||||
Action: func(c *cli.Context) error {
|
||||
recipe := internal.ValidateRecipe(c)
|
||||
recipeName := internal.ValidateRecipe(c)
|
||||
|
||||
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, recipe)
|
||||
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, recipeName)
|
||||
composeFiles, err := filepath.Glob(pattern)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
@ -42,7 +42,7 @@ var recipeLintCommand = &cli.Command{
|
||||
}
|
||||
|
||||
envSampleProvided := false
|
||||
envSample := fmt.Sprintf("%s/%s/.env.sample", config.APPS_DIR, recipe)
|
||||
envSample := fmt.Sprintf("%s/%s/.env.sample", config.APPS_DIR, recipeName)
|
||||
if _, err := os.Stat(envSample); !os.IsNotExist(err) {
|
||||
envSampleProvided = true
|
||||
}
|
||||
|
@ -5,8 +5,9 @@ import (
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/client/stack"
|
||||
"coopcloud.tech/abra/pkg/compose"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -28,36 +29,26 @@ the versioning metadata of up-and-running containers are.
|
||||
`,
|
||||
ArgsUsage: "<recipe>",
|
||||
Action: func(c *cli.Context) error {
|
||||
recipe := internal.ValidateRecipe(c)
|
||||
recipeName := internal.ValidateRecipe(c)
|
||||
|
||||
appFiles, err := config.LoadAppFiles("")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
appEnv, err := config.GetApp(appFiles, recipe)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
compose, err := config.GetAppComposeConfig(recipe, stack.Deploy{}, appEnv.Env)
|
||||
composeConfig, err := recipe.GetComposeConfig(recipeName)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
hasAppService := false
|
||||
for _, service := range compose.Services {
|
||||
for _, service := range composeConfig.Services {
|
||||
if service.Name == "app" {
|
||||
hasAppService = true
|
||||
}
|
||||
}
|
||||
|
||||
if !hasAppService {
|
||||
logrus.Fatal(fmt.Sprintf("No 'app' service defined in '%s', cannot proceed", recipe))
|
||||
logrus.Fatal(fmt.Sprintf("No 'app' service defined in '%s', cannot proceed", recipeName))
|
||||
}
|
||||
|
||||
for _, service := range compose.Services {
|
||||
img, _ := reference.ParseNormalizedNamed(service.Image)
|
||||
for _, service := range composeConfig.Services {
|
||||
img, err := reference.ParseNormalizedNamed(service.Image)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
@ -69,7 +60,8 @@ the versioning metadata of up-and-running containers are.
|
||||
|
||||
tag := img.(reference.NamedTagged).Tag()
|
||||
label := fmt.Sprintf("coop-cloud.${STACK_NAME}.%s.version=%s-%s", service.Name, tag, digest)
|
||||
if err := config.UpdateAppComposeLabel(recipe, service.Name, label, appEnv.Env); err != nil {
|
||||
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, recipeName)
|
||||
if err := compose.UpdateLabel(pattern, service.Name, label); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,9 @@ import (
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/catalogue"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/client/stack"
|
||||
"coopcloud.tech/abra/pkg/compose"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/tagcmp"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/docker/distribution/reference"
|
||||
@ -35,25 +36,15 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync
|
||||
`,
|
||||
ArgsUsage: "<recipe>",
|
||||
Action: func(c *cli.Context) error {
|
||||
recipe := internal.ValidateRecipe(c)
|
||||
recipeName := internal.ValidateRecipe(c)
|
||||
|
||||
appFiles, err := config.LoadAppFiles("")
|
||||
composeConfig, err := recipe.GetComposeConfig(recipeName)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
appEnv, err := config.GetApp(appFiles, recipe)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
compose, err := config.GetAppComposeConfig(recipe, stack.Deploy{}, appEnv.Env)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
for _, service := range compose.Services {
|
||||
catlVersions, err := catalogue.VersionsOfService(recipe, service.Name)
|
||||
for _, service := range composeConfig.Services {
|
||||
catlVersions, err := catalogue.VersionsOfService(recipeName, service.Name)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
@ -138,7 +129,8 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if err := config.UpdateAppComposeTag(recipe, image, upgradeTag, appEnv.Env); err != nil {
|
||||
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, recipeName)
|
||||
if err := compose.UpdateTag(pattern, image, upgradeTag); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ var recipeVersionCommand = &cli.Command{
|
||||
Aliases: []string{"v"},
|
||||
ArgsUsage: "<recipe>",
|
||||
Action: func(c *cli.Context) error {
|
||||
recipe := internal.ValidateRecipe(c)
|
||||
recipeName := internal.ValidateRecipe(c)
|
||||
|
||||
catalogue, err := catalogue.ReadRecipeCatalogue()
|
||||
if err != nil {
|
||||
@ -22,17 +22,17 @@ var recipeVersionCommand = &cli.Command{
|
||||
return nil
|
||||
}
|
||||
|
||||
rec, ok := catalogue[recipe]
|
||||
recipe, ok := catalogue[recipeName]
|
||||
if !ok {
|
||||
logrus.Fatalf("'%s' recipe doesn't exist?", recipe)
|
||||
logrus.Fatalf("'%s' recipe doesn't exist?", recipeName)
|
||||
}
|
||||
|
||||
tableCol := []string{"Version", "Service", "Image", "Digest"}
|
||||
table := formatter.CreateTable(tableCol)
|
||||
|
||||
for version := range rec.Versions {
|
||||
for service := range rec.Versions[version] {
|
||||
meta := rec.Versions[version][service]
|
||||
for version := range recipe.Versions {
|
||||
for service := range recipe.Versions[version] {
|
||||
meta := recipe.Versions[version][service]
|
||||
table.Append([]string{version, service, meta.Image, meta.Digest})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user