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

Method Generate

pkg/compose/generate.go:35–66  ·  view source on GitHub ↗
(ctx context.Context, options api.GenerateOptions)

Source from the content-addressed store, hash-verified

33)
34
35func (s *composeService) Generate(ctx context.Context, options api.GenerateOptions) (*types.Project, error) {
36 res, err := s.apiClient().ContainerList(ctx, client.ContainerListOptions{
37 Filters: make(client.Filters).Add("name", options.Containers...),
38 All: true,
39 })
40 if err != nil {
41 return nil, err
42 }
43 containers := res.Items
44
45 containersByIds, err := s.apiClient().ContainerList(ctx, client.ContainerListOptions{
46 Filters: make(client.Filters).Add("id", options.Containers...),
47 All: true,
48 })
49 if err != nil {
50 return nil, err
51 }
52
53 for _, ctr := range containersByIds.Items {
54 if !slices.ContainsFunc(containers, func(summary container.Summary) bool {
55 return summary.ID == ctr.ID
56 }) {
57 containers = append(containers, ctr)
58 }
59 }
60
61 if len(containers) == 0 {
62 return nil, fmt.Errorf("no container(s) found with the following name(s): %s", strings.Join(options.Containers, ","))
63 }
64
65 return s.createProjectFromContainers(containers, options.ProjectName)
66}
67
68func (s *composeService) createProjectFromContainers(containers []container.Summary, projectName string) (*types.Project, error) {
69 project := &types.Project{}

Callers

nothing calls this directly

Calls 4

apiClientMethod · 0.95
ContainerListMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected