(ctx context.Context, dockerCli command.Cli, project *types.Project, opts ConvertOptions)
| 49 | } |
| 50 | |
| 51 | func Convert(ctx context.Context, dockerCli command.Cli, project *types.Project, opts ConvertOptions) error { |
| 52 | if len(opts.Transformations) == 0 { |
| 53 | opts.Transformations = []string{DefaultTransformerImage} |
| 54 | } |
| 55 | // Load image references, secrets and configs, also expose ports |
| 56 | project, err := LoadAdditionalResources(ctx, dockerCli, project) |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | // for user to rely on compose.yaml attribute names, not go struct ones, we marshall back into YAML |
| 61 | raw, err := project.MarshalYAML(types.WithSecretContent) |
| 62 | // Marshall to YAML |
| 63 | if err != nil { |
| 64 | return fmt.Errorf("cannot render project into yaml: %w", err) |
| 65 | } |
| 66 | var model map[string]any |
| 67 | err = yaml.Unmarshal(raw, &model) |
| 68 | if err != nil { |
| 69 | return fmt.Errorf("cannot render project into yaml: %w", err) |
| 70 | } |
| 71 | |
| 72 | if opts.Output != "" { |
| 73 | _ = os.RemoveAll(opts.Output) |
| 74 | err := os.MkdirAll(opts.Output, 0o744) |
| 75 | if err != nil && !os.IsExist(err) { |
| 76 | return fmt.Errorf("cannot create output folder: %w", err) |
| 77 | } |
| 78 | } |
| 79 | // Run Transformers images |
| 80 | return convert(ctx, dockerCli, model, opts) |
| 81 | } |
| 82 | |
| 83 | func convert(ctx context.Context, dockerCli command.Cli, model map[string]any, opts ConvertOptions) error { |
| 84 | raw, err := yaml.Marshal(model) |
no test coverage detected