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

Function Push

pkg/remote/push.go:17–54  ·  view source on GitHub ↗

Push pushes an artifact from the content store to an OCI registry

(ctx context.Context, reference string)

Source from the content-addressed store, hash-verified

15
16// Push pushes an artifact from the content store to an OCI registry
17func Push(ctx context.Context, reference string) error {
18 store, err := content.NewStore()
19 if err != nil {
20 return fmt.Errorf("creating content store: %w", err)
21 }
22
23 img, err := store.GetArtifactImage(reference)
24 if err != nil {
25 return fmt.Errorf("loading artifact from store: %w", err)
26 }
27
28 // Get metadata to restore annotations
29 metadata, err := store.GetArtifactMetadata(reference)
30 if err != nil {
31 return fmt.Errorf("loading artifact metadata: %w", err)
32 }
33
34 // Convert to OCI format and restore annotations if present
35 if len(metadata.Annotations) > 0 {
36 img = mutate.MediaType(img, types.OCIManifestSchema1)
37 img = mutate.Annotations(img, metadata.Annotations).(v1.Image)
38 }
39
40 // Wrap as a spec-compliant OCI artifact so the pushed manifest includes
41 // artifactType and an empty config descriptor.
42 img = content.NewArtifactImage(img, "application/vnd.docker.agent.config.v1+json")
43
44 ref, err := name.ParseReference(reference)
45 if err != nil {
46 return fmt.Errorf("parsing registry reference %s: %w", reference, err)
47 }
48
49 if err := crane.Push(img, ref.String(), crane.WithContext(ctx), crane.WithTransport(NewTransport(ctx))); err != nil {
50 return fmt.Errorf("pushing image to registry %s: %w", reference, err)
51 }
52
53 return nil
54}

Callers 4

runPushCommandFunction · 0.92
TestPushFunction · 0.85
TestPullIntegrationFunction · 0.85

Calls 6

GetArtifactImageMethod · 0.95
GetArtifactMetadataMethod · 0.95
NewStoreFunction · 0.92
NewArtifactImageFunction · 0.92
NewTransportFunction · 0.85
StringMethod · 0.45

Tested by 3

TestPushFunction · 0.68
TestPullIntegrationFunction · 0.68