forked from toolshed/abra
fix: prefixes volumes with stack name instead of default fallback for deployments
This commit is contained in:
@@ -159,6 +159,7 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
||||
SendRegistryAuth: true,
|
||||
}
|
||||
|
||||
app.Env["STACK_NAME"] = stackName
|
||||
compose, err := appPkg.GetAppComposeConfig(composeFiles, app.Env)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -262,6 +262,7 @@ func getAppResources(cl *dockerclient.Client, app app.App) (*AppResources, error
|
||||
return nil, err
|
||||
}
|
||||
|
||||
app.Env["STACK_NAME"] = app.StackName()
|
||||
compose, err := appPkg.GetAppComposeConfig(composeFiles, app.Env)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -88,6 +88,7 @@ func showPSOutput(app appPkg.App, cl *dockerClient.Client, deployedVersion, chao
|
||||
return
|
||||
}
|
||||
|
||||
app.Env["STACK_NAME"] = app.StackName()
|
||||
compose, err := appPkg.GetAppComposeConfig(composeFiles, app.Env)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -174,6 +174,7 @@ beforehand. See "abra app backup" for more.`),
|
||||
SendRegistryAuth: true,
|
||||
}
|
||||
|
||||
app.Env["STACK_NAME"] = stackName
|
||||
compose, err := appPkg.GetAppComposeConfig(composeFiles, app.Env)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -89,6 +89,7 @@ Passing "--prune/-p" does not remove those volumes.`),
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
app.Env["STACK_NAME"] = stackName
|
||||
compose, err := appPkg.GetAppComposeConfig(composeFiles, app.Env)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -186,6 +186,7 @@ beforehand. See "abra app backup" for more.`),
|
||||
SendRegistryAuth: true,
|
||||
}
|
||||
|
||||
app.Env["STACK_NAME"] = stackName
|
||||
compose, err := appPkg.GetAppComposeConfig(composeFiles, app.Env)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -179,6 +179,7 @@ func (a App) Filters(appendServiceNames, exactMatch bool, services ...string) (f
|
||||
return filters, err
|
||||
}
|
||||
|
||||
a.Env["STACK_NAME"] = a.StackName()
|
||||
compose, err := GetAppComposeConfig(composeFiles, a.Env)
|
||||
if err != nil {
|
||||
return filters, err
|
||||
@@ -332,6 +333,7 @@ func GetAppServiceNames(appName string) ([]string, error) {
|
||||
return serviceNames, err
|
||||
}
|
||||
|
||||
app.Env["STACK_NAME"] = app.StackName()
|
||||
compose, err := GetAppComposeConfig(composeFiles, app.Env)
|
||||
if err != nil {
|
||||
return serviceNames, err
|
||||
|
||||
@@ -3,17 +3,11 @@ package stack // https://github.com/docker/cli/blob/master/cli/command/stack/loa
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"io"
|
||||
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
composeGoCli "github.com/compose-spec/compose-go/v2/cli"
|
||||
composeGoTypes "github.com/compose-spec/compose-go/v2/types"
|
||||
"github.com/docker/cli/cli/compose/loader"
|
||||
"github.com/docker/cli/cli/compose/schema"
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -27,7 +21,7 @@ func LoadCompose(conf LoadConf) (*composeGoTypes.Project, error) {
|
||||
var project *composeGoTypes.Project
|
||||
|
||||
// NOTE(d1): silence compose-go internal logger
|
||||
logrus.SetOutput(ioutil.Discard)
|
||||
logrus.SetOutput(io.Discard)
|
||||
|
||||
var projectOptions *composeGoCli.ProjectOptions
|
||||
if len(conf.ComposeFiles) == 0 {
|
||||
@@ -50,10 +44,14 @@ func LoadCompose(conf LoadConf) (*composeGoTypes.Project, error) {
|
||||
}
|
||||
|
||||
var err error
|
||||
projectOptions, err = composeGoCli.NewProjectOptions(
|
||||
conf.ComposeFiles,
|
||||
newProjectOptions := []composeGoCli.ProjectOptionsFn{
|
||||
composeGoCli.WithEnv(env),
|
||||
)
|
||||
}
|
||||
stackName, ok := conf.AppEnv["STACK_NAME"]
|
||||
if ok && stackName != "" {
|
||||
newProjectOptions = append(newProjectOptions, composeGoCli.WithName(stackName))
|
||||
}
|
||||
projectOptions, err = composeGoCli.NewProjectOptions(conf.ComposeFiles, newProjectOptions...)
|
||||
if err != nil {
|
||||
return project, err
|
||||
}
|
||||
@@ -66,88 +64,3 @@ func LoadCompose(conf LoadConf) (*composeGoTypes.Project, error) {
|
||||
|
||||
return project, nil
|
||||
}
|
||||
|
||||
func getDictsFrom(configFiles []composetypes.ConfigFile) []map[string]interface{} {
|
||||
dicts := []map[string]interface{}{}
|
||||
|
||||
for _, configFile := range configFiles {
|
||||
dicts = append(dicts, configFile.Config)
|
||||
}
|
||||
|
||||
return dicts
|
||||
}
|
||||
|
||||
func propertyWarnings(properties map[string]string) string {
|
||||
var msgs []string
|
||||
for name, description := range properties {
|
||||
msgs = append(msgs, fmt.Sprintf("%s: %s", name, description))
|
||||
}
|
||||
sort.Strings(msgs)
|
||||
return strings.Join(msgs, "\n\n")
|
||||
}
|
||||
|
||||
func getConfigDetails(composefiles []string, appEnv map[string]string) (composetypes.ConfigDetails, error) {
|
||||
var details composetypes.ConfigDetails
|
||||
|
||||
absPath, err := filepath.Abs(composefiles[0])
|
||||
if err != nil {
|
||||
return details, err
|
||||
}
|
||||
details.WorkingDir = filepath.Dir(absPath)
|
||||
|
||||
details.ConfigFiles, err = loadConfigFiles(composefiles)
|
||||
if err != nil {
|
||||
return details, err
|
||||
}
|
||||
// Take the first file version (2 files can't have different version)
|
||||
details.Version = schema.Version(details.ConfigFiles[0].Config)
|
||||
details.Environment = appEnv
|
||||
return details, err
|
||||
}
|
||||
|
||||
func buildEnvironment(env []string) (map[string]string, error) {
|
||||
result := make(map[string]string, len(env))
|
||||
for _, s := range env {
|
||||
// if value is empty, s is like "K=", not "K".
|
||||
if !strings.Contains(s, "=") {
|
||||
return result, errors.New(i18n.G("unexpected environment %q", s))
|
||||
}
|
||||
kv := strings.SplitN(s, "=", 2)
|
||||
result[kv[0]] = kv[1]
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func loadConfigFiles(filenames []string) ([]composetypes.ConfigFile, error) {
|
||||
var configFiles []composetypes.ConfigFile
|
||||
|
||||
for _, filename := range filenames {
|
||||
configFile, err := loadConfigFile(filename)
|
||||
if err != nil {
|
||||
return configFiles, err
|
||||
}
|
||||
configFiles = append(configFiles, *configFile)
|
||||
}
|
||||
|
||||
return configFiles, nil
|
||||
}
|
||||
|
||||
func loadConfigFile(filename string) (*composetypes.ConfigFile, error) {
|
||||
var bytes []byte
|
||||
var err error
|
||||
|
||||
bytes, err = ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config, err := loader.ParseYAML(bytes)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %s", filename, err)
|
||||
}
|
||||
|
||||
return &composetypes.ConfigFile{
|
||||
Filename: filename,
|
||||
Config: config,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user