@@ -17,14 +17,16 @@ import (
1717 "reflect"
1818 "strings"
1919
20+ "github.com/aws/amazon-ecs-cli/ecs-cli/modules/cli/compose/adapter"
2021 "github.com/aws/amazon-ecs-cli/ecs-cli/modules/utils/value"
22+ "github.com/docker/cli/cli/compose/types"
2123 "github.com/docker/libcompose/config"
2224 "github.com/docker/libcompose/project"
2325 log "github.com/sirupsen/logrus"
2426)
2527
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 {
2830 "cap_add" ,
2931 "cap_drop" ,
3032 "command" ,
@@ -57,19 +59,47 @@ var supportedComposeYamlOptions = []string{
5759 "working_dir" ,
5860}
5961
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 ()
6191
6292// Create set of supported YAML fields in docker compose v2 ServiceConfigs
63- func getSupportedComposeYamlOptionsMap () map [string ]bool {
93+ func getSupportedComposeV1V2YamlOptionsMap () map [string ]bool {
6494 optionsMap := make (map [string ]bool )
65- for _ , value := range supportedComposeYamlOptions {
95+ for _ , value := range supportedComposeV1V2YamlOptions {
6696 optionsMap [value ] = true
6797 }
6898 return optionsMap
6999}
70100
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 ) {
73103 configValue := reflect .ValueOf (serviceConfig ).Elem ()
74104 configType := configValue .Type ()
75105
@@ -87,19 +117,30 @@ func LogUnsupportedServiceConfigFields(serviceName string, serviceConfig *config
87117 }
88118
89119 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 )
94121 }
95122
96123 zeroValue := value .IsZero (field )
97124 // 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 )
103144 }
104145 }
105146}
@@ -114,6 +155,13 @@ func LogUnsupportedProjectFields(project *project.Project) {
114155 }
115156}
116157
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+
117165func validNetworksForService (config * config.ServiceConfig ) bool {
118166 if config .Networks == nil {
119167 return false
0 commit comments