-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompose.go
49 lines (42 loc) · 1.18 KB
/
compose.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package compose
import (
"os"
"path/filepath"
"github.com/docker/cli/cli/compose/loader"
"github.com/docker/cli/cli/compose/types"
errors "github.com/pkg/errors"
"github.com/spf13/afero"
)
func buildConfigDetails(dir string, source map[string]interface{}) *types.ConfigDetails {
workingDir, err := os.Getwd()
if err != nil {
panic(err)
}
return &types.ConfigDetails{
WorkingDir: workingDir,
ConfigFiles: []types.ConfigFile{
{Filename: "filename.yml", Config: source},
},
Environment: map[string]string{
"HOME": os.Getenv("HOME"),
},
}
}
// Parse reads and parses the specified docker-compose.yml files and returns
// a map holdind the parsed structure representing each file.
func Parse(fs afero.Fs, wd string, file string) (*types.Config, error) {
b, err := afero.ReadFile(fs, file)
if err != nil {
return nil, errors.Wrapf(err, "Could not read %s", file)
}
dict, err := loader.ParseYAML(b)
if err != nil {
return nil, errors.Wrapf(err, "Error parsing %s", file)
}
details := buildConfigDetails(filepath.Dir(file), dict)
config, err := loader.Load(*details)
if err != nil {
return nil, errors.Wrapf(err, "Error loading %s", file)
}
return config, nil
}