mirror of
https://github.com/rancher/os.git
synced 2025-09-06 17:22:34 +00:00
Bump libcompose and its dependencies
This commit is contained in:
69
vendor/github.com/docker/libcompose/project/context.go
generated
vendored
69
vendor/github.com/docker/libcompose/project/context.go
generated
vendored
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/libcompose/config"
|
||||
"github.com/docker/libcompose/logger"
|
||||
)
|
||||
|
||||
@@ -18,51 +19,47 @@ var projectRegexp = regexp.MustCompile("[^a-zA-Z0-9_.-]")
|
||||
// Context holds context meta information about a libcompose project, like
|
||||
// the project name, the compose file, etc.
|
||||
type Context struct {
|
||||
Timeout uint
|
||||
Log bool
|
||||
Volume bool
|
||||
ForceRecreate bool
|
||||
NoRecreate bool
|
||||
Signal int
|
||||
ComposeFile string
|
||||
ComposeBytes []byte
|
||||
ComposeFiles []string
|
||||
ComposeBytes [][]byte
|
||||
ProjectName string
|
||||
isOpen bool
|
||||
ServiceFactory ServiceFactory
|
||||
EnvironmentLookup EnvironmentLookup
|
||||
ConfigLookup ConfigLookup
|
||||
EnvironmentLookup config.EnvironmentLookup
|
||||
ResourceLookup config.ResourceLookup
|
||||
LoggerFactory logger.Factory
|
||||
IgnoreMissingConfig bool
|
||||
Project *Project
|
||||
}
|
||||
|
||||
func (c *Context) readComposeFile() error {
|
||||
func (c *Context) readComposeFiles() error {
|
||||
if c.ComposeBytes != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
logrus.Debugf("Opening compose file: %s", c.ComposeFile)
|
||||
logrus.Debugf("Opening compose files: %s", strings.Join(c.ComposeFiles, ","))
|
||||
|
||||
if c.ComposeFile == "-" {
|
||||
// Handle STDIN (`-f -`)
|
||||
if len(c.ComposeFiles) == 1 && c.ComposeFiles[0] == "-" {
|
||||
composeBytes, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
logrus.Errorf("Failed to read compose file from stdin: %v", err)
|
||||
return err
|
||||
}
|
||||
c.ComposeBytes = composeBytes
|
||||
} else if c.ComposeFile != "" {
|
||||
if composeBytes, err := ioutil.ReadFile(c.ComposeFile); os.IsNotExist(err) {
|
||||
if c.IgnoreMissingConfig {
|
||||
return nil
|
||||
}
|
||||
logrus.Errorf("Failed to find %s", c.ComposeFile)
|
||||
c.ComposeBytes = [][]byte{composeBytes}
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, composeFile := range c.ComposeFiles {
|
||||
composeBytes, err := ioutil.ReadFile(composeFile)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
logrus.Errorf("Failed to open the compose file: %s", composeFile)
|
||||
return err
|
||||
} else if err != nil {
|
||||
logrus.Errorf("Failed to open %s", c.ComposeFile)
|
||||
return err
|
||||
} else {
|
||||
c.ComposeBytes = composeBytes
|
||||
}
|
||||
if err != nil && !c.IgnoreMissingConfig {
|
||||
logrus.Errorf("Failed to find the compose file: %s", composeFile)
|
||||
return err
|
||||
}
|
||||
c.ComposeBytes = append(c.ComposeBytes, composeBytes)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -74,16 +71,12 @@ func (c *Context) determineProject() error {
|
||||
return err
|
||||
}
|
||||
|
||||
c.ProjectName = projectRegexp.ReplaceAllString(strings.ToLower(name), "-")
|
||||
c.ProjectName = normalizeName(name)
|
||||
|
||||
if c.ProjectName == "" {
|
||||
return fmt.Errorf("Falied to determine project name")
|
||||
}
|
||||
|
||||
if strings.ContainsAny(c.ProjectName[0:1], "_.-") {
|
||||
c.ProjectName = "x" + c.ProjectName
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -96,9 +89,14 @@ func (c *Context) lookupProjectName() (string, error) {
|
||||
return envProject, nil
|
||||
}
|
||||
|
||||
f, err := filepath.Abs(c.ComposeFile)
|
||||
file := "."
|
||||
if len(c.ComposeFiles) > 0 {
|
||||
file = c.ComposeFiles[0]
|
||||
}
|
||||
|
||||
f, err := filepath.Abs(file)
|
||||
if err != nil {
|
||||
logrus.Errorf("Failed to get absolute directory for: %s", c.ComposeFile)
|
||||
logrus.Errorf("Failed to get absolute directory for: %s", file)
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -114,6 +112,11 @@ func (c *Context) lookupProjectName() (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeName(name string) string {
|
||||
r := regexp.MustCompile("[^a-z0-9]+")
|
||||
return r.ReplaceAllString(strings.ToLower(name), "")
|
||||
}
|
||||
|
||||
func toUnixPath(p string) string {
|
||||
return strings.Replace(p, "\\", "/", -1)
|
||||
}
|
||||
@@ -123,7 +126,7 @@ func (c *Context) open() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := c.readComposeFile(); err != nil {
|
||||
if err := c.readComposeFiles(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user