Skip to content

Commit 0c12035

Browse files
authored
docs: improve docs for OCI store (#941)
1. Add more detailed docs for `oci.Tag()` and `oci.Untag()` 2. Format existing docs Resolves: #920 Signed-off-by: Lixia (Sylvia) Lei <[email protected]>
1 parent 7963626 commit 0c12035

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

content/oci/oci.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ func (s *Store) Exists(ctx context.Context, target ocispec.Descriptor) (bool, er
157157

158158
// Delete deletes the content matching the descriptor from the store. Delete may
159159
// fail on certain systems (i.e. NTFS), if there is a process (i.e. an unclosed
160-
// Reader) using target. If s.AutoGC is set to true, Delete will recursively
161-
// remove the dangling blobs caused by the current delete. If s.AutoDeleteReferrers
162-
// is set to true, Delete will recursively remove the referrers of the manifests
163-
// being deleted.
160+
// Reader) using target.
161+
// - If s.AutoGC is set to true, Delete will recursively
162+
// remove the dangling blobs caused by the current delete.
163+
// - If s.AutoDeleteReferrers is set to true, Delete will recursively remove
164+
// the referrers of the manifests being deleted.
164165
func (s *Store) Delete(ctx context.Context, target ocispec.Descriptor) error {
165166
s.sync.Lock()
166167
defer s.sync.Unlock()
@@ -220,8 +221,17 @@ func (s *Store) delete(ctx context.Context, target ocispec.Descriptor) ([]ocispe
220221
return danglings, nil
221222
}
222223

223-
// Tag tags a descriptor with a reference string.
224-
// reference should be a valid tag (e.g. "latest").
224+
// Tag associates a reference string (e.g. "latest") with the descriptor.
225+
// The reference string is recorded in the "org.opencontainers.image.ref.name"
226+
// annotation of the descriptor. When saved, the updated descriptor is persisted
227+
// in the `index.json` file.
228+
//
229+
// - If the same reference string is tagged multiple times on different
230+
// descriptors, the descriptor from the last call will be stored.
231+
// - If the same descriptor is tagged multiple times with different reference
232+
// strings, multiple copies of the descriptor with different reference tags
233+
// will be stored in the `index.json` file.
234+
//
225235
// Reference: https://github.com/opencontainers/image-spec/blob/v1.1.1/image-layout.md#indexjson-file
226236
func (s *Store) Tag(ctx context.Context, desc ocispec.Descriptor, reference string) error {
227237
s.sync.RLock()
@@ -260,11 +270,11 @@ func (s *Store) tag(ctx context.Context, desc ocispec.Descriptor, reference stri
260270
return nil
261271
}
262272

263-
// Resolve resolves a reference to a descriptor. If the reference to be resolved
264-
// is a tag, the returned descriptor will be a full descriptor declared by
265-
// github.com/opencontainers/image-spec/specs-go/v1. If the reference is a
266-
// digest the returned descriptor will be a plain descriptor (containing only
267-
// the digest, media type and size).
273+
// Resolve resolves a reference to a descriptor.
274+
// - If the reference to be resolved is a tag, the returned descriptor will be
275+
// a full descriptor declared by github.com/opencontainers/image-spec/specs-go/v1.
276+
// - If the reference is a digest, the returned descriptor will be a
277+
// plain descriptor (containing only the digest, media type and size).
268278
func (s *Store) Resolve(ctx context.Context, reference string) (ocispec.Descriptor, error) {
269279
s.sync.RLock()
270280
defer s.sync.RUnlock()
@@ -290,6 +300,13 @@ func (s *Store) Resolve(ctx context.Context, reference string) (ocispec.Descript
290300
return desc, nil
291301
}
292302

303+
// Untag disassociates a reference string from its descriptor.
304+
// When saved, the descriptor entry cotanining the reference in the
305+
// "org.opencontainers.image.ref.name" annotation is removed from the
306+
// `index.json` file.
307+
// The actual content identified by the descriptor is NOT deleted.
308+
//
309+
// Reference: https://github.com/opencontainers/image-spec/blob/v1.1.1/image-layout.md#indexjson-file
293310
func (s *Store) Untag(ctx context.Context, reference string) error {
294311
if reference == "" {
295312
return errdef.ErrMissingReference

content/oci/readonlyoci.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ func (s *ReadOnlyStore) Exists(ctx context.Context, target ocispec.Descriptor) (
8383
return s.storage.Exists(ctx, target)
8484
}
8585

86-
// Resolve resolves a reference to a descriptor. If the reference to be resolved
87-
// is a tag, the returned descriptor will be a full descriptor declared by
88-
// github.com/opencontainers/image-spec/specs-go/v1. If the reference is a
89-
// digest the returned descriptor will be a plain descriptor (containing only
90-
// the digest, media type and size).
86+
// Resolve resolves a reference to a descriptor.
87+
// - If the reference to be resolved is a tag, the returned descriptor will be
88+
// a full descriptor declared by github.com/opencontainers/image-spec/specs-go/v1.
89+
// - If the reference is a digest, the returned descriptor will be a
90+
// plain descriptor (containing only the digest, media type and size).
9191
func (s *ReadOnlyStore) Resolve(ctx context.Context, reference string) (ocispec.Descriptor, error) {
9292
if reference == "" {
9393
return ocispec.Descriptor{}, errdef.ErrMissingReference

0 commit comments

Comments
 (0)