Skip to content

Commit aef90e4

Browse files
docs: document PackManifestOptions to make PackManifest reproducible (#749)
Resolves #748 Signed-off-by: Xiaoxuan Wang <[email protected]>
1 parent c071bed commit aef90e4

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

example_pack_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func ExamplePackManifest_imageV11() {
3434
// 1. Set optional parameters
3535
opts := oras.PackManifestOptions{
3636
ManifestAnnotations: map[string]string{
37-
// this timestamp will be automatically generated if not specified
38-
// use a fixed value here in order to test the output
37+
// this time stamp will be automatically generated if not specified
38+
// use a fixed value here to make the pack result reproducible
3939
ocispec.AnnotationCreated: "2000-01-01T00:00:00Z",
4040
},
4141
}
@@ -70,8 +70,8 @@ func ExamplePackManifest_imageV10() {
7070
// 1. Set optional parameters
7171
opts := oras.PackManifestOptions{
7272
ManifestAnnotations: map[string]string{
73-
// this timestamp will be automatically generated if not specified
74-
// use a fixed value here in order to test the output
73+
// this time stamp will be automatically generated if not specified
74+
// use a fixed value here to make the pack result reproducible
7575
ocispec.AnnotationCreated: "2000-01-01T00:00:00Z",
7676
},
7777
}

pack.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const (
4848

4949
var (
5050
// ErrInvalidDateTimeFormat is returned by [Pack] and [PackManifest] when
51-
// AnnotationArtifactCreated or AnnotationCreated is provided, but its value
52-
// is not in RFC 3339 format.
51+
// "org.opencontainers.artifact.created" or "org.opencontainers.image.created"
52+
// is provided, but its value is not in RFC 3339 format.
5353
// Reference: https://www.rfc-editor.org/rfc/rfc3339#section-5.6
5454
ErrInvalidDateTimeFormat = errors.New("invalid date and time format")
5555

@@ -93,7 +93,10 @@ type PackManifestOptions struct {
9393
// Layers is the layers of the manifest.
9494
Layers []ocispec.Descriptor
9595

96-
// ManifestAnnotations is the annotation map of the manifest.
96+
// ManifestAnnotations is the annotation map of the manifest. In order to
97+
// make [PackManifest] reproducible, set the key ocispec.AnnotationCreated
98+
// (i.e. "org.opencontainers.image.created") to a fixed value. The value
99+
// must conform to RFC 3339.
97100
ManifestAnnotations map[string]string
98101

99102
// ConfigDescriptor is a pointer to the descriptor of the config blob.
@@ -126,6 +129,12 @@ var mediaTypeRegexp = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9!#$&-^_.+]{0,126
126129
//
127130
// artifactType and opts.ConfigDescriptor.MediaType MUST comply with RFC 6838.
128131
//
132+
// Each time when PackManifest is called, if a time stamp is not specified, a new time
133+
// stamp is generated in the manifest annotations with the key ocispec.AnnotationCreated
134+
// (i.e. "org.opencontainers.image.created"). To make [PackManifest] reproducible,
135+
// set the key ocispec.AnnotationCreated to a fixed value in
136+
// opts.ManifestAnnotations. The value MUST conform to RFC 3339.
137+
//
129138
// If succeeded, returns a descriptor of the packed manifest.
130139
func PackManifest(ctx context.Context, pusher content.Pusher, packManifestVersion PackManifestVersion, artifactType string, opts PackManifestOptions) (ocispec.Descriptor, error) {
131140
switch packManifestVersion {

0 commit comments

Comments
 (0)