Class ContainerRegistryContentClient
java.lang.Object
com.azure.containers.containerregistry.ContainerRegistryContentClient
This class provides a client that exposes operations to push and pull images into container registry.
It exposes methods that upload, download and delete artifacts from the registry i.e. images and manifests.
View this
for additional ways to construct the client.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteBlob
(String digest) Delete the image identified by the given digestcom.azure.core.http.rest.Response
<Void> deleteBlobWithResponse
(String digest, com.azure.core.util.Context context) Delete the image identified by the given digestvoid
deleteManifest
(String digest) Delete the manifest identified by the given digest.com.azure.core.http.rest.Response
<Void> deleteManifestWithResponse
(String digest, com.azure.core.util.Context context) Delete the manifest identified by the given digest.void
downloadStream
(String digest, WritableByteChannel channel) Download the blob identified by the given digest.void
downloadStream
(String digest, WritableByteChannel channel, com.azure.core.util.Context context) Download the blob identified by the given digest.This method returns the complete registry endpoint.getManifest
(String tagOrDigest) Download the manifest identified by the given tag or digest.com.azure.core.http.rest.Response
<GetManifestResult> getManifestWithResponse
(String tagOrDigest, com.azure.core.util.Context context) Download the manifest of custom type identified by the given tag or digest.This method returns the registry's repository on which operations are being performed.setManifest
(OciImageManifest manifest, String tag) Upload the OCI manifest to the repository.com.azure.core.http.rest.Response
<SetManifestResult> setManifestWithResponse
(SetManifestOptions options, com.azure.core.util.Context context) Uploads a manifest to the repository.uploadBlob
(com.azure.core.util.BinaryData content) Uploads a blob to the repository in chunks of 4MB.uploadBlob
(com.azure.core.util.BinaryData content, com.azure.core.util.Context context) Uploads a blob to the repository in chunks of 4MB.
-
Method Details
-
getRepositoryName
This method returns the registry's repository on which operations are being performed.- Returns:
- The name of the repository
-
getEndpoint
This method returns the complete registry endpoint.- Returns:
- The registry endpoint including the authority.
-
setManifest
Upload the OCI manifest to the repository.Code Samples:
contentClient.setManifest(manifest, "v1");
- Parameters:
manifest
- TheOciImageManifest
that needs to be updated.tag
- Tag to apply on uploaded manifest. Ifnull
is passed, no tags will be applied.- Returns:
- upload result.
- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if themanifest
is null.- See Also:
-
setManifestWithResponse
public com.azure.core.http.rest.Response<SetManifestResult> setManifestWithResponse(SetManifestOptions options, com.azure.core.util.Context context) Uploads a manifest to the repository.Code Samples:
SetManifestOptions options = new SetManifestOptions(manifestList, DOCKER_MANIFEST_LIST_TYPE); Response<SetManifestResult> response = contentClient.setManifestWithResponse(options, Context.NONE); System.out.println("Manifest uploaded, digest - " + response.getValue().getDigest());
- Parameters:
options
- The options for the upload manifest operation.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The rest response containing the upload result.
- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thedata
is null.
-
uploadBlob
Uploads a blob to the repository in chunks of 4MB.Code Samples
BinaryData configContent = BinaryData.fromObject(Collections.singletonMap("hello", "world")); UploadRegistryBlobResult uploadResult = contentClient.uploadBlob(configContent); System.out.printf("Uploaded blob: digest - '%s', size - %s\n", uploadResult.getDigest(), uploadResult.getSizeInBytes());
BinaryData configContent = BinaryData.fromObject(Collections.singletonMap("hello", "world")); try { UploadRegistryBlobResult uploadResult = contentClient.uploadBlob(configContent); System.out.printf("Uploaded blob: digest - '%s', size - %s\n", uploadResult.getDigest(), uploadResult.getSizeInBytes()); } catch (HttpResponseException ex) { if (ex.getValue() instanceof ResponseError) { ResponseError error = (ResponseError) ex.getValue(); System.out.printf("Upload failed: code '%s'\n", error.getCode()); if ("BLOB_UPLOAD_INVALID".equals(error.getCode())) { System.out.println("Transient upload issue, starting upload over"); // retry upload } } }
- Parameters:
content
- The blob content. The content may be loaded into memory depending on howBinaryData
is created.- Returns:
- The upload response.
- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thedata
isnull
.
-
uploadBlob
public UploadRegistryBlobResult uploadBlob(com.azure.core.util.BinaryData content, com.azure.core.util.Context context) Uploads a blob to the repository in chunks of 4MB.Code Samples
BinaryData content = BinaryData.fromFile(Paths.get("artifact.tar.gz", CHUNK_SIZE)); UploadRegistryBlobResult uploadResult = contentClient.uploadBlob(content, Context.NONE); System.out.printf("Uploaded blob: digest - '%s', size - %s\n", uploadResult.getDigest(), uploadResult.getSizeInBytes());
- Parameters:
content
- The blob content.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The upload response.
- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thestream
isnull
.
-
getManifest
Download the manifest identified by the given tag or digest.Code Samples:
Download manifest with tag:GetManifestResult latestResult = contentClient.getManifest("latest"); if (ManifestMediaType.DOCKER_MANIFEST.equals(latestResult.getManifestMediaType()) || ManifestMediaType.OCI_IMAGE_MANIFEST.equals(latestResult.getManifestMediaType())) { OciImageManifest manifest = latestResult.getManifest().toObject(OciImageManifest.class); } else { throw new IllegalArgumentException("Unexpected manifest type: " + latestResult.getManifestMediaType()); }
Download manifest with digest:GetManifestResult getManifestResult = contentClient.getManifest( "sha256:6581596932dc735fd0df8cc240e6c28845a66829126da5ce25b983cf244e2311");
- Parameters:
tagOrDigest
- Manifest tag or digest.- Returns:
- The manifest identified by the given tag or digest.
- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thetagOrDigest
is null.
-
getManifestWithResponse
public com.azure.core.http.rest.Response<GetManifestResult> getManifestWithResponse(String tagOrDigest, com.azure.core.util.Context context) Download the manifest of custom type identified by the given tag or digest.Code Samples:
Response<GetManifestResult> downloadResponse = contentClient.getManifestWithResponse("latest", Context.NONE); System.out.printf("Received manifest: digest - %s, response code: %s\n", downloadResponse.getValue().getDigest(), downloadResponse.getStatusCode());
- Parameters:
tagOrDigest
- Manifest reference which can be tag or digest.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The response for the manifest identified by the given tag or digest.
- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thetagOrDigest
is null.
-
downloadStream
Download the blob identified by the given digest.Code Samples:
Path file = Files.createTempFile(digest, ".tmp"); SeekableByteChannel channel = Files.newByteChannel(file, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE); contentClient.downloadStream(digest, channel);
- Parameters:
digest
- The digest for the given image layer.channel
- The channel to write content to.- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thedigest
is null.com.azure.core.exception.ServiceResponseException
- thrown if content hash does not match requested digest.
-
downloadStream
public void downloadStream(String digest, WritableByteChannel channel, com.azure.core.util.Context context) Download the blob identified by the given digest.- Parameters:
digest
- The digest for the given image layer.channel
- The channel to write content to.context
- Additional context that is passed through the Http pipeline during the service call.- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thedigest
is null.com.azure.core.exception.ServiceResponseException
- thrown if content hash does not match requested digest.
-
deleteBlob
Delete the image identified by the given digestCode Samples:
GetManifestResult manifestResult = contentClient.getManifest("latest"); OciImageManifest manifest = manifestResult.getManifest().toObject(OciImageManifest.class); for (OciDescriptor layer : manifest.getLayers()) { contentClient.deleteBlob(layer.getDigest()); }
- Parameters:
digest
- The digest for the given image layer.- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thedigest
is null.
-
deleteBlobWithResponse
public com.azure.core.http.rest.Response<Void> deleteBlobWithResponse(String digest, com.azure.core.util.Context context) Delete the image identified by the given digest- Parameters:
digest
- The digest for the given image layer.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The REST response for the completion.
- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thedigest
is null.
-
deleteManifest
Delete the manifest identified by the given digest.Code Samples:
GetManifestResult manifestResult = contentClient.getManifest("latest"); contentClient.deleteManifest(manifestResult.getDigest());
- Parameters:
digest
- The digest of the manifest.- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thedigest
is null.
-
deleteManifestWithResponse
public com.azure.core.http.rest.Response<Void> deleteManifestWithResponse(String digest, com.azure.core.util.Context context) Delete the manifest identified by the given digest.- Parameters:
digest
- The digest of the manifest.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The REST response for completion.
- Throws:
com.azure.core.exception.ClientAuthenticationException
- thrown if the client's credentials do not have access to modify the namespace.NullPointerException
- thrown if thedigest
is null.
-