@@ -100,28 +100,57 @@ type Dependency struct {
100100 Container * Container `yaml:"container"`
101101}
102102
103- // UnmarshalYAML is a custom unmarshaler that lets you handle both string and map forms.
103+ // getDefaultConfig retrieves a copy of the default config (if present),
104+ // then applies the provided version to the Image.
105+ func getDefaultConfig (baseName , version string ) (* Dependency , bool ) {
106+ baseName = strings .ToLower (baseName )
107+ dep , found := defaultConfigs [baseName ]
108+ if ! found {
109+ return nil , false
110+ }
111+ parts := strings .Split (dep .Image , ":" )
112+ if len (parts ) == 2 {
113+ dep .Image = parts [0 ] + ":" + version
114+ } else {
115+ dep .Image += ":" + version
116+ }
117+ return & dep , true
118+ }
119+
120+ // UnmarshalYAML is a custom unmarshaler that lets you handle both string-based
121+ // and map-based dependencies.
104122func (d * Dependency ) UnmarshalYAML (node * yaml.Node ) error {
105123 switch node .Tag {
106124 case "!!str" :
107125 // If the node is just a string (e.g. "postgres:16"), parse it.
108- // You can define your own logic here: how to set Name vs. Image, etc.
109- // For instance, if you want Name = the first part, and Image = the entire string:
110126 value := node .Value
111127 parts := strings .SplitN (value , ":" , 2 )
112- if len (parts ) > 1 {
113- d .Name = parts [0 ]
114- d .Image = value // e.g. "postgres:16"
128+
129+ if len (parts ) == 2 {
130+ // We have a base name + version
131+ base , version := parts [0 ], parts [1 ]
132+ if defaultDep , ok := getDefaultConfig (base , version ); ok {
133+ * d = * defaultDep
134+ } else {
135+ // fallback for unknown base (e.g., "foobar:1.0")
136+ d .Name = base
137+ d .Image = value
138+ }
115139 } else {
116- // If there's no colon, define your fallback:
117- // e.g. "postgres" => use "postgres" for both Name and Image
118- d .Name = value
119- d .Image = value
140+ // Only a base name (e.g., "redis")
141+ base := parts [0 ]
142+ if defaultDep , ok := getDefaultConfig (base , "latest" ); ok {
143+ * d = * defaultDep
144+ } else {
145+ // fallback for unknown base (e.g., "foobar")
146+ d .Name = base
147+ d .Image = base
148+ }
120149 }
121150 return nil
122151
123152 case "!!map" :
124- // If the node is a map, just decode into the struct in the usual way.
153+ // If the node is a map, decode into the struct in the usual way.
125154 type dependencyAlias Dependency
126155 var tmp dependencyAlias
127156 if err := node .Decode (& tmp ); err != nil {
0 commit comments