mirror of
https://github.com/docker/compose.git
synced 2025-07-26 15:14:04 +02:00
better error display and cleanup
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
881818223c
commit
3bd15bf0d4
@ -1,6 +1,7 @@
|
|||||||
package compose
|
package compose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -19,13 +20,19 @@ type ComposeProject struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Load(name string, configpaths []string) (*ComposeProject, error) {
|
func Load(name string, configpaths []string) (*ComposeProject, error) {
|
||||||
if name == "" {
|
|
||||||
name = "docker-compose"
|
|
||||||
}
|
|
||||||
model, workingDir, err := internal.GetConfig(name, configpaths)
|
model, workingDir, err := internal.GetConfig(name, configpaths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name == "" {
|
||||||
|
if model != nil {
|
||||||
|
name = filepath.Base(filepath.Dir(model.Filename))
|
||||||
|
} else if workingDir != "" {
|
||||||
|
name = filepath.Base(filepath.Dir(workingDir))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &ComposeProject{
|
return &ComposeProject{
|
||||||
config: model,
|
config: model,
|
||||||
helm: helm.NewHelmActions(nil),
|
helm: helm.NewHelmActions(nil),
|
||||||
@ -35,6 +42,10 @@ func Load(name string, configpaths []string) (*ComposeProject, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cp *ComposeProject) GenerateChart(dirname string) error {
|
func (cp *ComposeProject) GenerateChart(dirname string) error {
|
||||||
|
if cp.config == nil {
|
||||||
|
return errors.New(`Can't find a suitable configuration file in this directory or any
|
||||||
|
parent. Are you in the right directory?`)
|
||||||
|
}
|
||||||
if dirname == "" {
|
if dirname == "" {
|
||||||
dirname = cp.config.Filename
|
dirname = cp.config.Filename
|
||||||
if strings.Contains(dirname, ".") {
|
if strings.Contains(dirname, ".") {
|
||||||
@ -51,7 +62,13 @@ func (cp *ComposeProject) Install(name, path string) error {
|
|||||||
if path != "" {
|
if path != "" {
|
||||||
return cp.helm.InstallChartFromDir(name, path)
|
return cp.helm.InstallChartFromDir(name, path)
|
||||||
}
|
}
|
||||||
|
if cp.config == nil {
|
||||||
|
return errors.New(`Can't find a suitable configuration file in this directory or any
|
||||||
|
parent. Are you in the right directory?`)
|
||||||
|
}
|
||||||
|
if name == "" {
|
||||||
|
name = cp.Name
|
||||||
|
}
|
||||||
chart, err := internal.GetChartInMemory(cp.config, name)
|
chart, err := internal.GetChartInMemory(cp.config, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -60,6 +77,16 @@ func (cp *ComposeProject) Install(name, path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cp *ComposeProject) Uninstall(name string) error {
|
func (cp *ComposeProject) Uninstall(name string) error {
|
||||||
|
if name == "" {
|
||||||
|
if cp.config == nil {
|
||||||
|
return errors.New(`Can't find a suitable configuration file in this directory or any
|
||||||
|
parent. Are you in the right directory?
|
||||||
|
|
||||||
|
Alternative: uninstall [INSTALLATION NAME]
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
name = cp.Name
|
||||||
|
}
|
||||||
return cp.helm.Uninstall(name)
|
return cp.helm.Uninstall(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,9 +29,6 @@ func Environment() map[string]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetConfig(name string, configPaths []string) (*types.Config, string, error) {
|
func GetConfig(name string, configPaths []string) (*types.Config, string, error) {
|
||||||
if name == "" {
|
|
||||||
name = "docker-compose"
|
|
||||||
}
|
|
||||||
workingDir, configs, err := utils.GetConfigs(
|
workingDir, configs, err := utils.GetConfigs(
|
||||||
name,
|
name,
|
||||||
configPaths,
|
configPaths,
|
||||||
@ -39,6 +36,9 @@ func GetConfig(name string, configPaths []string) (*types.Config, string, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
if configs == nil {
|
||||||
|
return nil, "", nil
|
||||||
|
}
|
||||||
config, err := loader.Load(types.ConfigDetails{
|
config, err := loader.Load(types.ConfigDetails{
|
||||||
WorkingDir: workingDir,
|
WorkingDir: workingDir,
|
||||||
ConfigFiles: configs,
|
ConfigFiles: configs,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -20,6 +19,9 @@ func GetConfigs(name string, configPaths []string) (string, []types.ConfigFile,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
if configPath == nil {
|
||||||
|
return "", nil, nil
|
||||||
|
}
|
||||||
workingDir := filepath.Dir(configPath[0])
|
workingDir := filepath.Dir(configPath[0])
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
@ -88,7 +90,7 @@ func getConfigPaths(configPaths []string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
parent := filepath.Dir(pwd)
|
parent := filepath.Dir(pwd)
|
||||||
if parent == pwd {
|
if parent == pwd {
|
||||||
return nil, fmt.Errorf("Can't find a suitable configuration file in this directory or any parent. Are you in the right directory?")
|
return nil, nil
|
||||||
}
|
}
|
||||||
pwd = parent
|
pwd = parent
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user