@azure/container-registry 1.1.0-beta.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +174 -4
  2. package/dist/index.js +366 -154
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/src/constants.js +1 -1
  5. package/dist-esm/src/constants.js.map +1 -1
  6. package/dist-esm/src/containerRegistryClient.js +15 -12
  7. package/dist-esm/src/containerRegistryClient.js.map +1 -1
  8. package/dist-esm/src/containerRepository.js +12 -5
  9. package/dist-esm/src/containerRepository.js.map +1 -1
  10. package/dist-esm/src/{blob/containerRegistryBlobClient.js → content/containerRegistryContentClient.js} +91 -58
  11. package/dist-esm/src/content/containerRegistryContentClient.js.map +1 -0
  12. package/dist-esm/src/{blob → content}/index.js +1 -1
  13. package/dist-esm/src/content/index.js.map +1 -0
  14. package/dist-esm/src/content/models.js +17 -0
  15. package/dist-esm/src/content/models.js.map +1 -0
  16. package/dist-esm/src/generated/generatedClient.js +28 -2
  17. package/dist-esm/src/generated/generatedClient.js.map +1 -1
  18. package/dist-esm/src/generated/generatedClientContext.js +1 -1
  19. package/dist-esm/src/generated/generatedClientContext.js.map +1 -1
  20. package/dist-esm/src/generated/models/index.js +17 -0
  21. package/dist-esm/src/generated/models/index.js.map +1 -1
  22. package/dist-esm/src/generated/models/mappers.js +7 -1
  23. package/dist-esm/src/generated/models/mappers.js.map +1 -1
  24. package/dist-esm/src/generated/operations/containerRegistry.js +0 -14
  25. package/dist-esm/src/generated/operations/containerRegistry.js.map +1 -1
  26. package/dist-esm/src/generated/operations/containerRegistryBlob.js +4 -8
  27. package/dist-esm/src/generated/operations/containerRegistryBlob.js.map +1 -1
  28. package/dist-esm/src/generated/operationsInterfaces/containerRegistryBlob.js.map +1 -1
  29. package/dist-esm/src/index.js +1 -1
  30. package/dist-esm/src/index.js.map +1 -1
  31. package/dist-esm/src/models.js +4 -1
  32. package/dist-esm/src/models.js.map +1 -1
  33. package/dist-esm/src/registryArtifact.js +12 -5
  34. package/dist-esm/src/registryArtifact.js.map +1 -1
  35. package/dist-esm/src/utils/helpers.js +30 -16
  36. package/dist-esm/src/utils/helpers.js.map +1 -1
  37. package/dist-esm/src/utils/retriableReadableStream.js +116 -0
  38. package/dist-esm/src/utils/retriableReadableStream.js.map +1 -0
  39. package/package.json +8 -5
  40. package/types/container-registry.d.ts +181 -145
  41. package/dist-esm/src/blob/containerRegistryBlobClient.js.map +0 -1
  42. package/dist-esm/src/blob/index.js.map +0 -1
  43. package/dist-esm/src/blob/models.js +0 -4
  44. package/dist-esm/src/blob/models.js.map +0 -1
package/README.md CHANGED
@@ -104,7 +104,9 @@ For more information please see [Container Registry Concepts](https://docs.micro
104
104
 
105
105
  ## Examples
106
106
 
107
- ### Listing repositories
107
+ ### Registry operations
108
+
109
+ #### Listing repositories
108
110
 
109
111
  Iterate through the collection of repositories in the registry.
110
112
 
@@ -135,7 +137,7 @@ main().catch((err) => {
135
137
  });
136
138
  ```
137
139
 
138
- ### List tags with anonymous access
140
+ #### List tags with anonymous access
139
141
 
140
142
  ```javascript
141
143
  const {
@@ -170,7 +172,7 @@ main().catch((err) => {
170
172
  });
171
173
  ```
172
174
 
173
- ### Set artifact properties
175
+ #### Set artifact properties
174
176
 
175
177
  ```javascript
176
178
  const {
@@ -198,7 +200,7 @@ main().catch((err) => {
198
200
  });
199
201
  ```
200
202
 
201
- ### Delete images
203
+ #### Delete images
202
204
 
203
205
  ```javascript
204
206
  const {
@@ -247,6 +249,174 @@ main().catch((err) => {
247
249
  });
248
250
  ```
249
251
 
252
+ ### Blob and manifest operations
253
+
254
+ #### Upload images
255
+
256
+ ```javascript
257
+ const { ContainerRegistryContentClient } = require("@azure/container-registry");
258
+ const { DefaultAzureCredential } = require("@azure/identity");
259
+ require("dotenv").config();
260
+
261
+ async function main() {
262
+ // endpoint should be in the form of "https://myregistryname.azurecr.io"
263
+ // where "myregistryname" is the actual name of your registry
264
+ const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
265
+ const repository = process.env.CONTAINER_REGISTRY_REPOSITORY || "library/hello-world";
266
+ const client = new ContainerRegistryContentClient(
267
+ endpoint,
268
+ repository,
269
+ new DefaultAzureCredential()
270
+ );
271
+
272
+ const config = Buffer.from("Sample config");
273
+ const { digest: configDigest, sizeInBytes: configSize } = await client.uploadBlob(config);
274
+
275
+ const layer = Buffer.from("Sample layer");
276
+ const { digest: layerDigest, sizeInBytes: layerSize } = await client.uploadBlob(layer);
277
+
278
+ const manifest = {
279
+ schemaVersion: 2,
280
+ config: {
281
+ digest: configDigest,
282
+ size: configSize,
283
+ mediaType: "application/vnd.oci.image.config.v1+json",
284
+ },
285
+ layers: [
286
+ {
287
+ digest: layerDigest,
288
+ size: layerSize,
289
+ mediaType: "application/vnd.oci.image.layer.v1.tar",
290
+ },
291
+ ],
292
+ };
293
+
294
+ await client.setManifest(manifest, { tag: "demo" });
295
+ }
296
+
297
+ main().catch((err) => {
298
+ console.error("The sample encountered an error:", err);
299
+ });
300
+ ```
301
+
302
+ #### Download images
303
+
304
+ ```javascript
305
+ const {
306
+ ContainerRegistryContentClient,
307
+ KnownManifestMediaType,
308
+ } = require("@azure/container-registry");
309
+ const { DefaultAzureCredential } = require("@azure/identity");
310
+ const dotenv = require("dotenv");
311
+ const fs = require("fs");
312
+ dotenv.config();
313
+
314
+ function trimSha(digest) {
315
+ const index = digest.indexOf(":");
316
+ return index === -1 ? digest : digest.substring(index);
317
+ }
318
+
319
+ async function main() {
320
+ // endpoint should be in the form of "https://myregistryname.azurecr.io"
321
+ // where "myregistryname" is the actual name of your registry
322
+ const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
323
+ const repository = process.env.CONTAINER_REGISTRY_REPOSITORY || "library/hello-world";
324
+ const client = new ContainerRegistryContentClient(
325
+ endpoint,
326
+ repository,
327
+ new DefaultAzureCredential()
328
+ );
329
+
330
+ // Download the manifest to obtain the list of files in the image based on the tag
331
+ const result = await client.getManifest("demo");
332
+
333
+ if (result.mediaType !== KnownManifestMediaType.OciImageManifest) {
334
+ throw new Error("Expected an OCI image manifest");
335
+ }
336
+
337
+ const manifest = result.manifest;
338
+
339
+ // Manifests of all media types have a buffer containing their content; this can be written to a file.
340
+ fs.writeFileSync("manifest.json", result.content);
341
+
342
+ const configResult = await client.downloadBlob(manifest.config.digest);
343
+ const configFile = fs.createWriteStream("config.json");
344
+ configResult.content.pipe(configFile);
345
+
346
+ // Download and write out the layers
347
+ for (const layer of manifest.layers) {
348
+ const fileName = trimSha(layer.digest);
349
+ const layerStream = fs.createWriteStream(fileName);
350
+ const downloadLayerResult = await client.downloadBlob(layer.digest);
351
+ downloadLayerResult.content.pipe(layerStream);
352
+ }
353
+ }
354
+
355
+ main().catch((err) => {
356
+ console.error("The sample encountered an error:", err);
357
+ });
358
+ ```
359
+
360
+ #### Delete manifest
361
+
362
+ ```javascript
363
+ const { ContainerRegistryContentClient } = require("@azure/container-registry");
364
+ const { DefaultAzureCredential } = require("@azure/identity");
365
+ require("dotenv").config();
366
+
367
+ async function main() {
368
+ // Get the service endpoint from the environment
369
+ const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
370
+ const repository = process.env.CONTAINER_REGISTRY_REPOSITORY || "library/hello-world";
371
+ // Create a new ContainerRegistryClient
372
+ const client = new ContainerRegistryContentClient(
373
+ endpoint,
374
+ repository,
375
+ new DefaultAzureCredential()
376
+ );
377
+
378
+ const downloadResult = await client.getManifest("latest");
379
+ await client.deleteManifest(downloadResult.digest);
380
+ }
381
+
382
+ main().catch((err) => {
383
+ console.error("The sample encountered an error:", err);
384
+ });
385
+ ```
386
+
387
+ #### Delete blob
388
+
389
+ ```javascript
390
+ const {
391
+ ContainerRegistryContentClient,
392
+ KnownManifestMediaType,
393
+ } = require("@azure/container-registry");
394
+ const { DefaultAzureCredential } = require("@azure/identity");
395
+ require("dotenv").config();
396
+
397
+ async function main() {
398
+ // Get the service endpoint from the environment
399
+ const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
400
+ const repository = process.env.CONTAINER_REGISTRY_REPOSITORY || "library/hello-world";
401
+ // Create a new ContainerRegistryClient
402
+ const client = new ContainerRegistryContentClient(
403
+ endpoint,
404
+ repository,
405
+ new DefaultAzureCredential()
406
+ );
407
+
408
+ const downloadResult = await client.getManifest("latest");
409
+
410
+ if (downloadResult.mediaType !== KnownManifestMediaType.OciImageManifest) {
411
+ throw new Error("Expected an OCI image manifest");
412
+ }
413
+
414
+ for (const layer of downloadResult.manifest.layers) {
415
+ await client.deleteBlob(layer.digest);
416
+ }
417
+ }
418
+ ```
419
+
250
420
  ## Troubleshooting
251
421
 
252
422
  For infomation about troubleshooting, refer to the [troubleshooting guide].