This repository was archived by the owner on Jan 24, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathpush.go
More file actions
104 lines (89 loc) · 2.74 KB
/
Copy pathpush.go
File metadata and controls
104 lines (89 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package blobber
import (
"context"
"fmt"
"io"
"io/fs"
"time"
"github.com/opencontainers/go-digest"
"github.com/meigma/blobber/core"
"github.com/meigma/blobber/internal/progress"
)
// Push uploads files from src to the given image reference.
// The ref must be fully qualified (e.g., "ghcr.io/org/repo:tag").
// Returns the digest of the pushed image.
func (c *Client) Push(ctx context.Context, ref string, src fs.FS, opts ...PushOption) (string, error) {
// Apply options
cfg := &pushConfig{
compression: GzipCompression(), // default
}
for _, opt := range opts {
opt(cfg)
}
// Build eStargz blob
result, err := c.builder.Build(ctx, src, cfg.compression)
if err != nil {
return "", fmt.Errorf("build archive: %w", err)
}
defer result.Blob.Close()
// Wrap blob reader for progress tracking if callback provided
var blobReader io.Reader = result.Blob
if cfg.progress != nil {
blobReader = progress.NewReader(result.Blob, result.BlobSize, func(transferred, total int64) {
cfg.progress(ProgressEvent{
Operation: "push",
BytesTransferred: transferred,
TotalBytes: total,
})
})
}
// Push to registry
regOpts := RegistryPushOptions{
MediaType: cfg.mediaType,
Annotations: cfg.annotations,
TOCDigest: result.TOCDigest,
DiffID: result.DiffID,
BlobDigest: result.BlobDigest,
BlobSize: result.BlobSize,
}
manifestDigest, err := c.registry.Push(ctx, ref, blobReader, ®Opts)
if err != nil {
return "", fmt.Errorf("push %s: %w", ref, err)
}
// Sign and store as referrer if signer configured
if c.signer != nil {
if err := c.signAndStoreReferrer(ctx, ref, manifestDigest); err != nil {
return "", fmt.Errorf("sign %s: %w", ref, err)
}
}
return manifestDigest, nil
}
// signAndStoreReferrer signs the manifest and stores the signature as an OCI referrer.
func (c *Client) signAndStoreReferrer(ctx context.Context, ref, manifestDigest string) error {
d, err := digest.Parse(manifestDigest)
if err != nil {
return fmt.Errorf("parse digest: %w", err)
}
// Fetch the manifest bytes for signing
manifestRef := digestReference(ref, manifestDigest)
manifestBytes, _, err := c.registry.FetchManifest(ctx, manifestRef)
if err != nil {
return fmt.Errorf("fetch manifest: %w", err)
}
// Sign the manifest
sig, err := c.signer.Sign(ctx, d, manifestBytes)
if err != nil {
return fmt.Errorf("signing: %w", err)
}
// Store signature as OCI referrer artifact
_, err = c.registry.PushReferrer(ctx, ref, manifestDigest, sig.Data, &core.ReferrerPushOptions{
ArtifactType: sig.MediaType,
Annotations: map[string]string{
"org.opencontainers.image.created": time.Now().UTC().Format(time.RFC3339),
},
})
if err != nil {
return fmt.Errorf("storing signature: %w", err)
}
return nil
}