@@ -21,30 +21,50 @@ import (
2121 "strings"
2222
2323 interp "github.com/compose-spec/compose-go/interpolation"
24+ "github.com/compose-spec/compose-go/types"
2425 "github.com/pkg/errors"
2526)
2627
2728var interpolateTypeCastMapping = map [interp.Path ]interp.Cast {
2829 servicePath ("configs" , interp .PathMatchList , "mode" ): toInt ,
29- servicePath ("secrets" , interp .PathMatchList , "mode" ): toInt ,
30- servicePath ("healthcheck" , "retries" ): toInt ,
31- servicePath ("healthcheck" , "disable" ): toBoolean ,
30+ servicePath ("cpu_count" ): toInt64 ,
31+ servicePath ("cpu_percent" ): toFloat ,
32+ servicePath ("cpu_period" ): toInt64 ,
33+ servicePath ("cpu_quota" ): toInt64 ,
34+ servicePath ("cpu_rt_period" ): toInt64 ,
35+ servicePath ("cpu_rt_runtime" ): toInt64 ,
36+ servicePath ("cpus" ): toFloat32 ,
37+ servicePath ("cpu_shares" ): toInt64 ,
38+ servicePath ("init" ): toBoolean ,
3239 servicePath ("deploy" , "replicas" ): toInt ,
3340 servicePath ("deploy" , "update_config" , "parallelism" ): toInt ,
3441 servicePath ("deploy" , "update_config" , "max_failure_ratio" ): toFloat ,
3542 servicePath ("deploy" , "rollback_config" , "parallelism" ): toInt ,
3643 servicePath ("deploy" , "rollback_config" , "max_failure_ratio" ): toFloat ,
3744 servicePath ("deploy" , "restart_policy" , "max_attempts" ): toInt ,
3845 servicePath ("deploy" , "placement" , "max_replicas_per_node" ): toInt ,
46+ servicePath ("healthcheck" , "retries" ): toInt ,
47+ servicePath ("healthcheck" , "disable" ): toBoolean ,
48+ servicePath ("mem_limit" ): toUnitBytes ,
49+ servicePath ("mem_reservation" ): toUnitBytes ,
50+ servicePath ("memswap_limit" ): toUnitBytes ,
51+ servicePath ("mem_swappiness" ): toUnitBytes ,
52+ servicePath ("oom_kill_disable" ): toBoolean ,
53+ servicePath ("oom_score_adj" ): toInt64 ,
54+ servicePath ("pids_limit" ): toInt64 ,
3955 servicePath ("ports" , interp .PathMatchList , "target" ): toInt ,
4056 servicePath ("ports" , interp .PathMatchList , "published" ): toInt ,
41- servicePath ("ulimits" , interp .PathMatchAll ): toInt ,
42- servicePath ("ulimits" , interp .PathMatchAll , "hard" ): toInt ,
43- servicePath ("ulimits" , interp .PathMatchAll , "soft" ): toInt ,
4457 servicePath ("privileged" ): toBoolean ,
4558 servicePath ("read_only" ): toBoolean ,
59+ servicePath ("scale" ): toInt ,
60+ servicePath ("secrets" , interp .PathMatchList , "mode" ): toInt ,
61+ servicePath ("shm_size" ): toUnitBytes ,
4662 servicePath ("stdin_open" ): toBoolean ,
63+ servicePath ("stop_grace_period" ): toDuration ,
4764 servicePath ("tty" ): toBoolean ,
65+ servicePath ("ulimits" , interp .PathMatchAll ): toInt ,
66+ servicePath ("ulimits" , interp .PathMatchAll , "hard" ): toInt ,
67+ servicePath ("ulimits" , interp .PathMatchAll , "soft" ): toInt ,
4868 servicePath ("volumes" , interp .PathMatchList , "read_only" ): toBoolean ,
4969 servicePath ("volumes" , interp .PathMatchList , "volume" , "nocopy" ): toBoolean ,
5070 iPath ("networks" , interp .PathMatchAll , "external" ): toBoolean ,
@@ -67,10 +87,38 @@ func toInt(value string) (interface{}, error) {
6787 return strconv .Atoi (value )
6888}
6989
90+ func toInt64 (value string ) (interface {}, error ) {
91+ return strconv .ParseInt (value , 10 , 64 )
92+ }
93+
94+ func toUnitBytes (value string ) (interface {}, error ) {
95+ i , err := strconv .ParseInt (value , 10 , 64 )
96+ if err != nil {
97+ return nil , err
98+ }
99+ return types .UnitBytes (i ), nil
100+ }
101+
102+ func toDuration (value string ) (interface {}, error ) {
103+ i , err := strconv .ParseInt (value , 10 , 64 )
104+ if err != nil {
105+ return nil , err
106+ }
107+ return types .Duration (i ), nil
108+ }
109+
70110func toFloat (value string ) (interface {}, error ) {
71111 return strconv .ParseFloat (value , 64 )
72112}
73113
114+ func toFloat32 (value string ) (interface {}, error ) {
115+ f , err := strconv .ParseFloat (value , 32 )
116+ if err != nil {
117+ return nil , err
118+ }
119+ return float32 (f ), nil
120+ }
121+
74122// should match http://yaml.org/type/bool.html
75123func toBoolean (value string ) (interface {}, error ) {
76124 switch strings .ToLower (value ) {
0 commit comments