loadComposeFile parse the composefile specified in the cli and returns its configOptions and version.
(streams command.Streams, opts deployOptions)
| 22 | |
| 23 | // loadComposeFile parse the composefile specified in the cli and returns its configOptions and version. |
| 24 | func loadComposeFile(streams command.Streams, opts deployOptions) (*composetypes.Config, error) { |
| 25 | configDetails, err := getConfigDetails(opts.composefiles, streams.In()) |
| 26 | if err != nil { |
| 27 | return nil, err |
| 28 | } |
| 29 | |
| 30 | config, err := loader.Load(configDetails) |
| 31 | if err != nil { |
| 32 | var fpe *loader.ForbiddenPropertiesError |
| 33 | if errors.As(err, &fpe) { |
| 34 | // this error is intentionally formatted multi-line |
| 35 | return nil, fmt.Errorf("compose file contains unsupported options:\n\n%s\n", propertyWarnings(fpe.Properties)) //nolint:staticcheck // ignore ST1005 |
| 36 | } |
| 37 | |
| 38 | return nil, err |
| 39 | } |
| 40 | |
| 41 | dicts := getDictsFrom(configDetails.ConfigFiles) |
| 42 | unsupportedProperties := loader.GetUnsupportedProperties(dicts...) |
| 43 | if len(unsupportedProperties) > 0 { |
| 44 | _, _ = fmt.Fprintf(streams.Err(), "Ignoring unsupported options: %s\n\n", |
| 45 | strings.Join(unsupportedProperties, ", ")) |
| 46 | } |
| 47 | |
| 48 | deprecatedProperties := loader.GetDeprecatedProperties(dicts...) |
| 49 | if len(deprecatedProperties) > 0 { |
| 50 | _, _ = fmt.Fprintf(streams.Err(), "Ignoring deprecated options:\n\n%s\n\n", |
| 51 | propertyWarnings(deprecatedProperties)) |
| 52 | } |
| 53 | |
| 54 | // Validate if each service has a valid image-reference. |
| 55 | for _, svc := range config.Services { |
| 56 | if svc.Image == "" { |
| 57 | return nil, fmt.Errorf("invalid image reference for service %s: no image specified", svc.Name) |
| 58 | } |
| 59 | if _, err := reference.ParseAnyReference(svc.Image); err != nil { |
| 60 | return nil, fmt.Errorf("invalid image reference for service %s: %w", svc.Name, err) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return config, nil |
| 65 | } |
| 66 | |
| 67 | func getDictsFrom(configFiles []composetypes.ConfigFile) []map[string]any { |
| 68 | dicts := make([]map[string]any, 0, len(configFiles)) |
no test coverage detected
searching dependent graphs…