@@ -17,14 +17,16 @@ import (
17
17
"reflect"
18
18
"strings"
19
19
20
+ "github.com/aws/amazon-ecs-cli/ecs-cli/modules/cli/compose/adapter"
20
21
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/utils/value"
22
+ "github.com/docker/cli/cli/compose/types"
21
23
"github.com/docker/libcompose/config"
22
24
"github.com/docker/libcompose/project"
23
25
log "github.com/sirupsen/logrus"
24
26
)
25
27
26
- // supported fields/options from compose YAML file
27
- var supportedComposeYamlOptions = []string {
28
+ // supported fields/options from compose 1/2 YAML file
29
+ var supportedComposeV1V2YamlOptions = []string {
28
30
"cap_add" ,
29
31
"cap_drop" ,
30
32
"command" ,
@@ -57,19 +59,47 @@ var supportedComposeYamlOptions = []string{
57
59
"working_dir" ,
58
60
}
59
61
60
- var supportedComposeYamlOptionsMap = getSupportedComposeYamlOptionsMap ()
62
+ // supported fields/options from compose 3 YAML file
63
+ var supportedFieldsInV3 = map [string ]bool {
64
+ "CapAdd" : true ,
65
+ "CapDrop" : true ,
66
+ "Command" : true ,
67
+ "DNS" : true ,
68
+ "DNSSearch" : true ,
69
+ "Entrypoint" : true ,
70
+ "Environment" : true ,
71
+ "EnvFile" : true ,
72
+ "ExtraHosts" : true ,
73
+ "Hostname" : true ,
74
+ "Image" : true ,
75
+ "Labels" : true ,
76
+ "Links" : true ,
77
+ "Logging" : true ,
78
+ "Name" : true ,
79
+ "Ports" : true ,
80
+ "Privileged" : true ,
81
+ "ReadOnly" : true ,
82
+ "SecurityOpt" : true ,
83
+ "Tmpfs" : true ,
84
+ "Ulimits" : true ,
85
+ "User" : true ,
86
+ "Volumes" : true ,
87
+ "WorkingDir" : true ,
88
+ }
89
+
90
+ var supportedComposeV1V2YamlOptionsMap = getSupportedComposeV1V2YamlOptionsMap ()
61
91
62
92
// Create set of supported YAML fields in docker compose v2 ServiceConfigs
63
- func getSupportedComposeYamlOptionsMap () map [string ]bool {
93
+ func getSupportedComposeV1V2YamlOptionsMap () map [string ]bool {
64
94
optionsMap := make (map [string ]bool )
65
- for _ , value := range supportedComposeYamlOptions {
95
+ for _ , value := range supportedComposeV1V2YamlOptions {
66
96
optionsMap [value ] = true
67
97
}
68
98
return optionsMap
69
99
}
70
100
71
- // LogUnsupportedServiceConfigFields logs a warning if there is an unsupported field specified in the docker-compose file
72
- func LogUnsupportedServiceConfigFields (serviceName string , serviceConfig * config.ServiceConfig ) {
101
+ // LogUnsupportedV1V2ServiceConfigFields logs a warning if there is an unsupported field specified in the docker-compose file
102
+ func LogUnsupportedV1V2ServiceConfigFields (serviceName string , serviceConfig * config.ServiceConfig ) {
73
103
configValue := reflect .ValueOf (serviceConfig ).Elem ()
74
104
configType := configValue .Type ()
75
105
@@ -87,19 +117,30 @@ func LogUnsupportedServiceConfigFields(serviceName string, serviceConfig *config
87
117
}
88
118
89
119
if tagName == "networks" && ! validNetworksForService (serviceConfig ) {
90
- log .WithFields (log.Fields {
91
- "option name" : tagName ,
92
- "service name" : serviceName ,
93
- }).Warn ("Skipping unsupported YAML option for service..." )
120
+ logWarningForUnsupportedServiceOption (tagName , serviceName )
94
121
}
95
122
96
123
zeroValue := value .IsZero (field )
97
124
// if value is present for the field that is not in supportedYamlTags map, log a warning
98
- if tagName != "networks" && ! zeroValue && ! supportedComposeYamlOptionsMap [tagName ] {
99
- log .WithFields (log.Fields {
100
- "option name" : tagName ,
101
- "service name" : serviceName ,
102
- }).Warn ("Skipping unsupported YAML option for service..." )
125
+ if tagName != "networks" && ! zeroValue && ! supportedComposeV1V2YamlOptionsMap [tagName ] {
126
+ logWarningForUnsupportedServiceOption (tagName , serviceName )
127
+ }
128
+ }
129
+ }
130
+
131
+ // LogUnsupportedV3ServiceConfigFields logs a warning if there is an unsupported field specified in the docker-compose file
132
+ func LogUnsupportedV3ServiceConfigFields (servConfig types.ServiceConfig ) {
133
+ configValue := reflect .ValueOf (servConfig )
134
+ configType := configValue .Type ()
135
+
136
+ for i := 0 ; i < configValue .NumField (); i ++ {
137
+ field := configValue .Field (i )
138
+ fieldType := configType .Field (i )
139
+
140
+ if supportedFieldsInV3 [fieldType .Name ] == false && ! value .IsZero (field ) {
141
+ // convert field name so it more closely resembles option in yaml file
142
+ optionName := adapter .ConvertCamelCaseToUnderScore (fieldType .Name )
143
+ logWarningForUnsupportedServiceOption (optionName , servConfig .Name )
103
144
}
104
145
}
105
146
}
@@ -114,6 +155,13 @@ func LogUnsupportedProjectFields(project *project.Project) {
114
155
}
115
156
}
116
157
158
+ func logWarningForUnsupportedServiceOption (tagName , serviceName string ) {
159
+ log .WithFields (log.Fields {
160
+ "option name" : tagName ,
161
+ "service name" : serviceName ,
162
+ }).Warn ("Skipping unsupported YAML option for service..." )
163
+ }
164
+
117
165
func validNetworksForService (config * config.ServiceConfig ) bool {
118
166
if config .Networks == nil {
119
167
return false
0 commit comments