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

Method export

pkg/compose/export.go:38–95  ·  pkg/compose/export.go::composeService.export
(ctx context.Context, projectName string, options api.ExportOptions)

Source from the content-addressed store, hash-verified

36}
37
38func (s *composeService) export(ctx context.Context, projectName string, options api.ExportOptions) error {
39 projectName = strings.ToLower(projectName)
40
41 container, err := s.getSpecifiedContainer(ctx, projectName, oneOffInclude, false, options.Service, options.Index)
42 if err != nil {
43 return err
44 }
45
46 if options.Output == "" {
47 if s.stdout().IsTerminal() {
48 return fmt.Errorf("output option is required when exporting to terminal")
49 }
50 } else if err := command.ValidateOutputPath(options.Output); err != nil {
51 return fmt.Errorf("failed to export container: %w", err)
52 }
53
54 name := getCanonicalContainerName(container)
55 s.events.On(api.Resource{
56 ID: name,
57 Text: api.StatusExporting,
58 Status: api.Working,
59 })
60
61 responseBody, err := s.apiClient().ContainerExport(ctx, container.ID, client.ContainerExportOptions{})
62 if err != nil {
63 return err
64 }
65
66 defer func() {
67 if err := responseBody.Close(); err != nil {
68 s.events.On(errorEventf(name, "Failed to close response body: %s", err.Error()))
69 }
70 }()
71
72 if !s.dryRun {
73 if options.Output == "" {
74 _, err := io.Copy(s.stdout(), responseBody)
75 return err
76 } else {
77 writer, err := atomicwriter.New(options.Output, 0o600)
78 if err != nil {
79 return err
80 }
81 defer func() { _ = writer.Close() }()
82
83 _, err = io.Copy(writer, responseBody)
84 return err
85 }
86 }
87
88 s.events.On(api.Resource{
89 ID: name,
90 Text: api.StatusExported,
91 Status: api.Done,
92 })
93
94 return nil
95}

Callers 1

ExportMethod · 0.95

Calls 10

getSpecifiedContainerMethod · 0.95
stdoutMethod · 0.95
apiClientMethod · 0.95
errorEventfFunction · 0.85
ErrorMethod · 0.80
OnMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.65
ContainerExportMethod · 0.45

Tested by

no test coverage detected