MCPcopy
hub / github.com/docker/docker-agent / runPullCommand

Method runPullCommand

cmd/root/pull.go:37–74  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

35}
36
37func (f *pullFlags) runPullCommand(cmd *cobra.Command, args []string) (commandErr error) {
38 ctx := cmd.Context()
39 telemetry.TrackCommand(ctx, "share", append([]string{"pull"}, args...))
40 defer func() { // do not inline this defer so that commandErr is not resolved early
41 telemetry.TrackCommandError(ctx, "share", append([]string{"pull"}, args...), commandErr)
42 }()
43
44 out := cli.NewPrinter(cmd.OutOrStdout())
45 registryRef := args[0]
46 slog.DebugContext(ctx, "Starting pull", "registry_ref", registryRef)
47
48 out.Println("Pulling agent", registryRef)
49
50 _, err := remote.Pull(ctx, registryRef, f.force)
51 if err != nil {
52 return fmt.Errorf("failed to pull artifact: %w", err)
53 }
54
55 store, err := content.NewStore()
56 if err != nil {
57 return fmt.Errorf("failed to open content store: %w", err)
58 }
59 yamlFile, err := store.GetArtifact(registryRef)
60 if err != nil {
61 return fmt.Errorf("failed to get agent yaml: %w", err)
62 }
63
64 agentName := strings.ReplaceAll(registryRef, "/", "_")
65 fileName := agentName + ".yaml"
66
67 if err := os.WriteFile(fileName, []byte(yamlFile), 0o644); err != nil { //nolint:gosec // pulled agent yaml is meant to be readable
68 return err
69 }
70
71 out.Printf("Agent saved to %s\n", fileName)
72
73 return nil
74}

Callers

nothing calls this directly

Calls 9

PrintlnMethod · 0.95
GetArtifactMethod · 0.95
PrintfMethod · 0.95
TrackCommandFunction · 0.92
TrackCommandErrorFunction · 0.92
NewPrinterFunction · 0.92
PullFunction · 0.92
NewStoreFunction · 0.92
ContextMethod · 0.80

Tested by

no test coverage detected