1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 22:32:14 +00:00

Bump libcompose and its dependencies

This commit is contained in:
Josh Curl
2016-05-23 17:22:40 -07:00
parent c18cd26e78
commit 50de80d09a
1109 changed files with 35052 additions and 125685 deletions

View File

@@ -0,0 +1,25 @@
package lookup
import (
"github.com/docker/libcompose/config"
)
// ComposableEnvLookup is a structure that implements the project.EnvironmentLookup interface.
// It holds an ordered list of EnvironmentLookup to call to look for the environment value.
type ComposableEnvLookup struct {
Lookups []config.EnvironmentLookup
}
// Lookup creates a string slice of string containing a "docker-friendly" environment string
// in the form of 'key=value'. It loop through the lookups and returns the latest value if
// more than one lookup return a result.
func (l *ComposableEnvLookup) Lookup(key, serviceName string, config *config.ServiceConfig) []string {
result := []string{}
for _, lookup := range l.Lookups {
env := lookup.Lookup(key, serviceName, config)
if len(env) == 1 {
result = env
}
}
return result
}

31
vendor/github.com/docker/libcompose/lookup/envfile.go generated vendored Normal file
View File

@@ -0,0 +1,31 @@
package lookup
import (
"strings"
"github.com/docker/docker/runconfig/opts"
"github.com/docker/libcompose/config"
)
// EnvfileLookup is a structure that implements the project.EnvironmentLookup interface.
// It holds the path of the file where to lookup environment values.
type EnvfileLookup struct {
Path string
}
// Lookup creates a string slice of string containing a "docker-friendly" environment string
// in the form of 'key=value'. It gets environment values using a '.env' file in the specified
// path.
func (l *EnvfileLookup) Lookup(key, serviceName string, config *config.ServiceConfig) []string {
envs, err := opts.ParseEnvFile(l.Path)
if err != nil {
return []string{}
}
for _, env := range envs {
e := strings.Split(env, "=")
if e[0] == key {
return []string{env}
}
}
return []string{}
}

View File

@@ -2,13 +2,44 @@ package lookup
import (
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"github.com/Sirupsen/logrus"
)
// FileConfigLookup is a "bare" structure that implements the project.ConfigLookup interface
// relativePath returns the proper relative path for the given file path. If
// the relativeTo string equals "-", then it means that it's from the stdin,
// and the returned path will be the current working directory. Otherwise, if
// file is really an absolute path, then it will be returned without any
// changes. Otherwise, the returned path will be a combination of relativeTo
// and file.
func relativePath(file, relativeTo string) string {
// stdin: return the current working directory if possible.
if relativeTo == "-" {
if cwd, err := os.Getwd(); err == nil {
return cwd
}
}
// If the given file is already an absolute path, just return it.
// Otherwise, the returned path will be relative to the given relativeTo
// path.
if filepath.IsAbs(file) {
return file
}
abs, err := filepath.Abs(filepath.Join(path.Dir(relativeTo), file))
if err != nil {
logrus.Errorf("Failed to get absolute directory: %s", err)
return file
}
return abs
}
// FileConfigLookup is a "bare" structure that implements the project.ResourceLookup interface
type FileConfigLookup struct {
}
@@ -17,14 +48,19 @@ type FileConfigLookup struct {
// If file starts with a slash ('/'), it tries to load it, otherwise it will build a
// filename using the folder part of relativeTo joined with file.
func (f *FileConfigLookup) Lookup(file, relativeTo string) ([]byte, string, error) {
if strings.HasPrefix(file, "/") {
logrus.Debugf("Reading file %s", file)
bytes, err := ioutil.ReadFile(file)
return bytes, file, err
}
fileName := path.Join(path.Dir(relativeTo), file)
logrus.Debugf("Reading file %s relative to %s", fileName, relativeTo)
bytes, err := ioutil.ReadFile(fileName)
return bytes, fileName, err
file = relativePath(file, relativeTo)
logrus.Debugf("Reading file %s", file)
bytes, err := ioutil.ReadFile(file)
return bytes, file, err
}
// ResolvePath returns the path to be used for the given path volume. This
// function already takes care of relative paths.
func (f *FileConfigLookup) ResolvePath(path, inFile string) string {
vs := strings.SplitN(path, ":", 2)
if len(vs) != 2 || filepath.IsAbs(vs[0]) {
return path
}
vs[0] = relativePath(vs[0], inFile)
return strings.Join(vs, ":")
}

View File

@@ -1,65 +0,0 @@
package lookup
import (
"io/ioutil"
"path/filepath"
"testing"
)
type input struct {
file string
relativeTo string
}
func TestLookupError(t *testing.T) {
invalids := map[input]string{
input{"", ""}: "read .: is a directory",
input{"", "/tmp/"}: "read /tmp: is a directory",
input{"file", "/does/not/exists/"}: "open /does/not/exists/file: no such file or directory",
input{"file", "/does/not/something"}: "open /does/not/file: no such file or directory",
input{"file", "/does/not/exists/another"}: "open /does/not/exists/file: no such file or directory",
input{"/does/not/exists/file", "/tmp/"}: "open /does/not/exists/file: no such file or directory",
input{"does/not/exists/file", "/tmp/"}: "open /tmp/does/not/exists/file: no such file or directory",
}
fileConfigLookup := FileConfigLookup{}
for invalid, expectedError := range invalids {
_, _, err := fileConfigLookup.Lookup(invalid.file, invalid.relativeTo)
if err == nil || err.Error() != expectedError {
t.Fatalf("Expected error with '%s', got '%v'", expectedError, err)
}
}
}
func TestLookupOK(t *testing.T) {
tmpFolder, err := ioutil.TempDir("", "lookup-tests")
if err != nil {
t.Fatal(err)
}
tmpFile1 := filepath.Join(tmpFolder, "file1")
tmpFile2 := filepath.Join(tmpFolder, "file2")
if err = ioutil.WriteFile(tmpFile1, []byte("content1"), 0755); err != nil {
t.Fatal(err)
}
if err = ioutil.WriteFile(tmpFile2, []byte("content2"), 0755); err != nil {
t.Fatal(err)
}
fileConfigLookup := FileConfigLookup{}
valids := map[input]string{
input{"file1", tmpFolder + "/"}: "content1",
input{"file2", tmpFolder + "/"}: "content2",
input{tmpFile1, tmpFolder}: "content1",
input{tmpFile1, "/does/not/exists"}: "content1",
input{"file2", tmpFile1}: "content2",
}
for valid, expectedContent := range valids {
out, _, err := fileConfigLookup.Lookup(valid.file, valid.relativeTo)
if err != nil || string(out) != expectedContent {
t.Fatalf("Expected %s to contains '%s', got %s, %v.", valid.file, expectedContent, out, err)
}
}
}

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"os"
"github.com/docker/libcompose/project"
"github.com/docker/libcompose/config"
)
// OsEnvLookup is a "bare" structure that implements the project.EnvironmentLookup interface
@@ -15,7 +15,7 @@ type OsEnvLookup struct {
// in the form of 'key=value'. It gets environment values using os.Getenv.
// If the os environment variable does not exists, the slice is empty. serviceName and config
// are not used at all in this implementation.
func (o *OsEnvLookup) Lookup(key, serviceName string, config *project.ServiceConfig) []string {
func (o *OsEnvLookup) Lookup(key, serviceName string, config *config.ServiceConfig) []string {
ret := os.Getenv(key)
if ret == "" {
return []string{}

View File

@@ -1,31 +0,0 @@
package lookup
import (
"testing"
"github.com/docker/libcompose/project"
)
func TestOsEnvLookup(t *testing.T) {
// Putting bare minimun value for serviceName and config as there are
// not important on this test.
serviceName := "anything"
config := &project.ServiceConfig{}
osEnvLookup := &OsEnvLookup{}
envs := osEnvLookup.Lookup("PATH", serviceName, config)
if len(envs) != 1 {
t.Fatalf("Expected envs to contains one element, but was %v", envs)
}
envs = osEnvLookup.Lookup("path", serviceName, config)
if len(envs) != 0 {
t.Fatalf("Expected envs to be empty, but was %v", envs)
}
envs = osEnvLookup.Lookup("DOES_NOT_EXIST", serviceName, config)
if len(envs) != 0 {
t.Fatalf("Expected envs to be empty, but was %v", envs)
}
}