@@ -189,7 +189,7 @@ func TestMain(m *testing.M) {
189
189
os .Exit (m .Run ())
190
190
}
191
191
192
- func ExampleCopy_remoteToRemote () {
192
+ func ExampleCopy_repositoryToRepository () {
193
193
reg , err := remote .NewRegistry (remoteHost )
194
194
if err != nil {
195
195
panic (err ) // Handle error
@@ -199,7 +199,7 @@ func ExampleCopy_remoteToRemote() {
199
199
if err != nil {
200
200
panic (err ) // Handle error
201
201
}
202
- dst , err := reg .Repository (ctx , "target " )
202
+ dst , err := reg .Repository (ctx , "destination " )
203
203
if err != nil {
204
204
panic (err ) // Handle error
205
205
}
@@ -215,7 +215,7 @@ func ExampleCopy_remoteToRemote() {
215
215
// sha256:7cbb44b44e8ede5a89cf193db3f5f2fd019d89697e6b87e8ed2589e60649b0d1
216
216
}
217
217
218
- func ExampleCopy_remoteToRemoteWithMount () {
218
+ func ExampleCopy_repositoryToRepositoryWithMount () {
219
219
reg , err := remote .NewRegistry (remoteHost )
220
220
if err != nil {
221
221
panic (err ) // Handle error
@@ -225,7 +225,7 @@ func ExampleCopy_remoteToRemoteWithMount() {
225
225
if err != nil {
226
226
panic (err ) // Handle error
227
227
}
228
- dst , err := reg .Repository (ctx , "target " )
228
+ dst , err := reg .Repository (ctx , "destination " )
229
229
if err != nil {
230
230
panic (err ) // Handle error
231
231
}
@@ -241,7 +241,7 @@ func ExampleCopy_remoteToRemoteWithMount() {
241
241
242
242
// Enable cross-repository blob mounting
243
243
opts .MountFrom = func (ctx context.Context , desc ocispec.Descriptor ) ([]string , error ) {
244
- // the slice of source repositores may also come from a database of known locations of blobs
244
+ // the slice of source repositories may also come from a database of known locations of blobs
245
245
return []string {"source/repository/name" }, nil
246
246
}
247
247
@@ -255,7 +255,7 @@ func ExampleCopy_remoteToRemoteWithMount() {
255
255
// Final sha256:7cbb44b44e8ede5a89cf193db3f5f2fd019d89697e6b87e8ed2589e60649b0d1
256
256
}
257
257
258
- func ExampleCopy_remoteToLocal () {
258
+ func ExampleCopy_repositoryToMemory () {
259
259
reg , err := remote .NewRegistry (remoteHost )
260
260
if err != nil {
261
261
panic (err ) // Handle error
@@ -279,7 +279,7 @@ func ExampleCopy_remoteToLocal() {
279
279
// sha256:7cbb44b44e8ede5a89cf193db3f5f2fd019d89697e6b87e8ed2589e60649b0d1
280
280
}
281
281
282
- func ExampleCopy_localToLocal () {
282
+ func ExampleCopy_memoryToMemory () {
283
283
src := exampleMemoryStore
284
284
dst := memory .New ()
285
285
@@ -295,7 +295,7 @@ func ExampleCopy_localToLocal() {
295
295
// sha256:7cbb44b44e8ede5a89cf193db3f5f2fd019d89697e6b87e8ed2589e60649b0d1
296
296
}
297
297
298
- func ExampleCopy_localToOciFile () {
298
+ func ExampleCopy_memoryToOCIStore () {
299
299
src := exampleMemoryStore
300
300
tempDir , err := os .MkdirTemp ("" , "oras_oci_example_*" )
301
301
if err != nil {
@@ -319,14 +319,14 @@ func ExampleCopy_localToOciFile() {
319
319
// sha256:7cbb44b44e8ede5a89cf193db3f5f2fd019d89697e6b87e8ed2589e60649b0d1
320
320
}
321
321
322
- func ExampleCopy_localToRemote () {
322
+ func ExampleCopy_memoryToRepository () {
323
323
src := exampleMemoryStore
324
324
reg , err := remote .NewRegistry (remoteHost )
325
325
if err != nil {
326
326
panic (err ) // Handle error
327
327
}
328
328
ctx := context .Background ()
329
- dst , err := reg .Repository (ctx , "target " )
329
+ dst , err := reg .Repository (ctx , "destination " )
330
330
if err != nil {
331
331
panic (err ) // Handle error
332
332
}
@@ -342,27 +342,34 @@ func ExampleCopy_localToRemote() {
342
342
// sha256:7cbb44b44e8ede5a89cf193db3f5f2fd019d89697e6b87e8ed2589e60649b0d1
343
343
}
344
344
345
- // ExampleCopyArtifactManifestRemoteToLocal gives an example of copying
346
- // an artifact manifest from a remote repository into memory.
347
- func Example_copyArtifactManifestRemoteToLocal () {
348
- src , err := remote .NewRepository (fmt .Sprintf ("%s/source" , remoteHost ))
345
+ // ExampleCopyArtifactFromRepository gives an example of copying
346
+ // an artifact from a remote repository into memory.
347
+ func Example_copyArtifactFromRepository () {
348
+ // 0. Connect to a remote repository
349
+ repositoryName := "source"
350
+ src , err := remote .NewRepository (fmt .Sprintf ("%s/%s" , remoteHost , repositoryName ))
349
351
if err != nil {
350
352
panic (err )
351
353
}
354
+
355
+ // 1. Create a memory store
352
356
dst := memory .New ()
353
357
ctx := context .Background ()
354
358
359
+ // 2. Resolve the descriptor of the artifact from the digest
355
360
exampleDigest := "sha256:70c29a81e235dda5c2cebb8ec06eafd3cca346cbd91f15ac74cefd98681c5b3d"
356
361
descriptor , err := src .Resolve (ctx , exampleDigest )
357
362
if err != nil {
358
363
panic (err )
359
364
}
365
+
366
+ // 3. Copy the artifact from the remote repository
360
367
err = oras .CopyGraph (ctx , src , dst , descriptor , oras .DefaultCopyGraphOptions )
361
368
if err != nil {
362
369
panic (err )
363
370
}
364
371
365
- // verify that the artifact manifest described by the descriptor exists in dst
372
+ // 4. Verify that the artifact manifest described by the descriptor exists in dst
366
373
contentExists , err := dst .Exists (ctx , descriptor )
367
374
if err != nil {
368
375
panic (err )
@@ -373,17 +380,22 @@ func Example_copyArtifactManifestRemoteToLocal() {
373
380
// true
374
381
}
375
382
376
- // ExampleExtendedCopyArtifactAndReferrersRemoteToLocal gives an example of
383
+ // ExampleExtendedCopyArtifactAndReferrersFromRepository gives an example of
377
384
// copying an artifact along with its referrers from a remote repository into
378
385
// memory.
379
- func Example_extendedCopyArtifactAndReferrersRemoteToLocal () {
380
- src , err := remote .NewRepository (fmt .Sprintf ("%s/source" , remoteHost ))
386
+ func Example_extendedCopyArtifactAndReferrersFromRepository () {
387
+ // 0. Connect to a remote repository
388
+ repositoryName := "source"
389
+ src , err := remote .NewRepository (fmt .Sprintf ("%s/%s" , remoteHost , repositoryName ))
381
390
if err != nil {
382
391
panic (err )
383
392
}
393
+
394
+ // 1. Create a memory store
384
395
dst := memory .New ()
385
396
ctx := context .Background ()
386
397
398
+ // 2. Copy the artifact and its referrers from the remote repository
387
399
tagName := "latest"
388
400
// ExtendedCopy will copy the artifact tagged by "latest" along with all of its
389
401
// referrers from src to dst.
0 commit comments