refactor!: simplifying publish logic

This commit is contained in:
2021-12-27 19:56:27 +01:00
parent eb1b6be4c5
commit 0aa37fcee8
10 changed files with 137 additions and 168 deletions

View File

@ -6,6 +6,7 @@ import (
"coopcloud.tech/abra/pkg/recipe"
"github.com/AlecAivazis/survey/v2"
"github.com/docker/distribution/reference"
"github.com/sirupsen/logrus"
)
@ -64,20 +65,29 @@ func SetBumpType(bumpType string) {
}
}
// GetMainApp retrieves the main 'app' image name
func GetMainApp(recipe recipe.Recipe) string {
var app string
// GetMainAppImage retrieves the main 'app' image name
func GetMainAppImage(recipe recipe.Recipe) (string, error) {
var path string
for _, service := range recipe.Config.Services {
name := service.Name
if name == "app" {
app = strings.Split(service.Image, ":")[0]
if service.Name == "app" {
img, err := reference.ParseNormalizedNamed(service.Image)
if err != nil {
return "", err
}
path = reference.Path(img)
if strings.Contains(path, "library") {
path = strings.Split(path, "/")[1]
}
return path, nil
}
}
if app == "" {
logrus.Fatalf("%s has no main 'app' service?", recipe.Name)
if path == "" {
return path, fmt.Errorf("%s has no main 'app' service?", recipe.Name)
}
return app
return path, nil
}