MCPcopy
hub / github.com/docker/compose / convert

Function convert

pkg/bridge/convert.go:83–162  ·  view source on GitHub ↗
(ctx context.Context, dockerCli command.Cli, model map[string]any, opts ConvertOptions)

Source from the content-addressed store, hash-verified

81}
82
83func convert(ctx context.Context, dockerCli command.Cli, model map[string]any, opts ConvertOptions) error {
84 raw, err := yaml.Marshal(model)
85 if err != nil {
86 return err
87 }
88
89 dir, err := os.MkdirTemp("", "compose-convert-*")
90 if err != nil {
91 return err
92 }
93 defer func() {
94 err := os.RemoveAll(dir)
95 if err != nil {
96 logrus.Warnf("failed to remove temp dir %s: %v", dir, err)
97 }
98 }()
99
100 composeYaml := filepath.Join(dir, "compose.yaml")
101 err = os.WriteFile(composeYaml, raw, 0o600)
102 if err != nil {
103 return err
104 }
105
106 out, err := filepath.Abs(opts.Output)
107 if err != nil {
108 return err
109 }
110 binds := []string{
111 fmt.Sprintf("%s:%s", dir, "/in"),
112 fmt.Sprintf("%s:%s", out, "/out"),
113 }
114 if opts.Templates != "" {
115 templateDir, err := filepath.Abs(opts.Templates)
116 if err != nil {
117 return err
118 }
119 binds = append(binds, fmt.Sprintf("%s:%s", templateDir, "/templates"))
120 }
121
122 for _, transformation := range opts.Transformations {
123 _, err = inspectWithPull(ctx, dockerCli, transformation)
124 if err != nil {
125 return err
126 }
127
128 containerConfig := &container.Config{
129 Image: transformation,
130 Env: []string{"LICENSE_AGREEMENT=true"},
131 }
132 // On POSIX systems, this is a decimal number representing the uid.
133 // On Windows, this is a security identifier (SID) in a string format and the engine isn't able to manage it
134 if runtime.GOOS != "windows" {
135 usr, err := user.Current()
136 if err != nil {
137 return err
138 }
139 containerConfig.User = usr.Uid
140 }

Callers 1

ConvertFunction · 0.85

Calls 5

inspectWithPullFunction · 0.85
RemoveAllMethod · 0.80
WriteFileMethod · 0.80
ContainerCreateMethod · 0.45
ClientMethod · 0.45

Tested by

no test coverage detected