refactor: simplify code
This commit is contained in:
@@ -21,27 +21,30 @@ type LoadConf struct {
|
||||
func LoadCompose(conf LoadConf) (*composeGoTypes.Project, error) {
|
||||
// NOTE(d1): silence compose-go internal logger
|
||||
logrus.SetOutput(io.Discard)
|
||||
|
||||
if len(conf.ComposeFiles) == 0 {
|
||||
return nil, errors.New(i18n.G("LoadCompose: provide compose files"))
|
||||
}
|
||||
|
||||
newProjectOptions := []composeGoCli.ProjectOptionsFn{}
|
||||
if len(conf.AppEnv) == 0 {
|
||||
newProjectOptions = append(newProjectOptions, composeGoCli.WithInterpolation(false))
|
||||
} else {
|
||||
hasEnvVariables := len(conf.AppEnv) > 0
|
||||
newProjectOptions := []composeGoCli.ProjectOptionsFn{
|
||||
composeGoCli.WithInterpolation(hasEnvVariables),
|
||||
}
|
||||
|
||||
if hasEnvVariables {
|
||||
var env []string
|
||||
for k, v := range conf.AppEnv {
|
||||
env = append(env, fmt.Sprintf("%s=%s", k, v))
|
||||
}
|
||||
newProjectOptions = append(newProjectOptions, composeGoCli.WithEnv(env))
|
||||
|
||||
stackName, ok := conf.AppEnv["STACK_NAME"]
|
||||
if ok && stackName != "" {
|
||||
newProjectOptions = append(newProjectOptions, composeGoCli.WithName(stackName))
|
||||
}
|
||||
}
|
||||
|
||||
// this is needed for updating tags, because each file is loaded one by one
|
||||
// this is needed for updating tags and labels, because each file is loaded one by one
|
||||
// and the consistency check requires every loaded file to have an image with tag
|
||||
if conf.DisableConsistencyCheck {
|
||||
newProjectOptions = append(newProjectOptions, composeGoCli.WithConsistency(false))
|
||||
}
|
||||
@@ -50,10 +53,5 @@ func LoadCompose(conf LoadConf) (*composeGoTypes.Project, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
project, err := projectOptions.LoadProject(context.Background())
|
||||
if err != nil {
|
||||
return project, err
|
||||
}
|
||||
|
||||
return project, nil
|
||||
return projectOptions.LoadProject(context.Background())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user