@@ -4,13 +4,15 @@ import (
4
4
"bufio"
5
5
"bytes"
6
6
"fmt"
7
+ "strconv"
7
8
"strings"
8
9
9
10
"reflect"
10
11
11
12
"github.com/docker/docker/pkg/urlutil"
12
13
"github.com/docker/libcompose/utils"
13
14
composeYaml "github.com/docker/libcompose/yaml"
15
+ "github.com/sirupsen/logrus"
14
16
"gopkg.in/yaml.v2"
15
17
)
16
18
@@ -25,14 +27,27 @@ var (
25
27
}
26
28
)
27
29
28
- // CreateConfig unmarshals bytes to config and creates config based on version
30
+ func getComposeMajorVersion (version string ) (int , error ) {
31
+ return strconv .Atoi (strings .Split (version , "." )[0 ])
32
+ }
33
+
34
+ // CreateConfig unmarshals bytes of a YAML manifest file and returns a new
35
+ // Config. Initialize any defaults that can't be parsed (but are optional)
36
+ // across various file formats. Most of these can remain unused.
37
+ //
38
+ // This function only handles parsing YAML in the general case. Any other file
39
+ // format validation should be handled by the caller.
29
40
func CreateConfig (bytes []byte ) (* Config , error ) {
30
41
var config Config
31
42
if err := yaml .Unmarshal (bytes , & config ); err != nil {
32
43
return nil , err
33
44
}
34
45
35
- if config .Version != "2" {
46
+ major , err := getComposeMajorVersion (config .Version )
47
+ if err != nil {
48
+ return nil , err
49
+ }
50
+ if major < 2 {
36
51
var baseRawServices RawServiceMap
37
52
if err := yaml .Unmarshal (bytes , & baseRawServices ); err != nil {
38
53
return nil , err
@@ -102,14 +117,22 @@ func Merge(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup
102
117
}
103
118
}
104
119
120
+ major , err := getComposeMajorVersion (config .Version )
121
+ if err != nil {
122
+ return "" , nil , nil , nil , err
123
+ }
124
+
105
125
var serviceConfigs map [string ]* ServiceConfig
106
- if config .Version == "2" {
126
+ switch major {
127
+ case 3 :
128
+ logrus .Fatal ("Note: Compose file version 3 is not yet implemented" )
129
+ case 2 :
107
130
var err error
108
131
serviceConfigs , err = MergeServicesV2 (existingServices , environmentLookup , resourceLookup , file , baseRawServices , options )
109
132
if err != nil {
110
133
return "" , nil , nil , nil , err
111
134
}
112
- } else {
135
+ default :
113
136
serviceConfigsV1 , err := MergeServicesV1 (existingServices , environmentLookup , resourceLookup , file , baseRawServices , options )
114
137
if err != nil {
115
138
return "" , nil , nil , nil , err
0 commit comments