AzureContainerRegistryExtensions Methods

ClassMethods5 members
Provides extension methods for adding Azure Container Registry resources to the application model.
AddAzureContainerRegistry(IDistributedApplicationBuilder, string)Section titled AddAzureContainerRegistry(IDistributedApplicationBuilder, string)extensionIResourceBuilder<AzureContainerRegistryResource>
Adds an Azure Container Registry resource to the application model.
public static class AzureContainerRegistryExtensions
{
public static IResourceBuilder<AzureContainerRegistryResource> AddAzureContainerRegistry(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builderIDistributedApplicationBuilderThe builder for the distributed application.
namestringThe name of the resource.
IResourceBuilder<AzureContainerRegistryResource>A reference to the ApplicationModel.IResourceBuilder`1 builder.
ArgumentNullExceptionThrown when builder is null.
ArgumentExceptionThrown when name is null or empty.
GetAzureContainerRegistry(IResourceBuilder<T>)Section titled GetAzureContainerRegistry(IResourceBuilder<T>)extensionIResourceBuilder<AzureContainerRegistryResource>
Gets the AzureContainerRegistryResource associated with the specified Azure compute environment resource.
public static class AzureContainerRegistryExtensions
{
public static IResourceBuilder<AzureContainerRegistryResource> GetAzureContainerRegistry<T>(
this IResourceBuilder<T> builder)
{
// ...
}
}
builderIResourceBuilder<T>The resource builder for the compute environment resource.
IResourceBuilder<AzureContainerRegistryResource>A reference to the ApplicationModel.IResourceBuilder`1 for the associated registry.
ArgumentNullExceptionThrown when builder is null.
InvalidOperationExceptionThrown when the resource does not have an associated Azure Container Registry, or when the associated container registry is not an AzureContainerRegistryResource.
WithAzureContainerRegistry(IResourceBuilder<T>, IResourceBuilder<AzureContainerRegistryResource>)Section titled WithAzureContainerRegistry(IResourceBuilder<T>, IResourceBuilder<AzureContainerRegistryResource>)extensionIResourceBuilder<T>
Configures a resource that implements ApplicationModel.IContainerRegistry to use the specified Azure Container Registry.
public static class AzureContainerRegistryExtensions
{
public static IResourceBuilder<T> WithAzureContainerRegistry<T>(
this IResourceBuilder<T> builder,
IResourceBuilder<AzureContainerRegistryResource> registryBuilder)
{
// ...
}
}
builderIResourceBuilder<T>The resource builder for a resource that implements ApplicationModel.IContainerRegistry.
registryBuilderIResourceBuilder<AzureContainerRegistryResource>The resource builder for the AzureContainerRegistryResource to use.
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1.
ArgumentNullExceptionThrown when builder or registryBuilder is null.
WithPurgeTask(IResourceBuilder<AzureContainerRegistryResource>, string, string?, TimeSpan?, int, string?)Section titled WithPurgeTask(IResourceBuilder<AzureContainerRegistryResource>, string, string?, TimeSpan?, int, string?)extensionIResourceBuilder<AzureContainerRegistryResource>
Adds a scheduled ACR purge task to remove image tags and eligible untagged manifests.
public static class AzureContainerRegistryExtensions
{
public static IResourceBuilder<AzureContainerRegistryResource> WithPurgeTask(
this IResourceBuilder<AzureContainerRegistryResource> builder,
string schedule,
string? filter = null,
TimeSpan? ago = null,
int keep = 3,
string? taskName = null)
{
// ...
}
}
builderIResourceBuilder<AzureContainerRegistryResource>The resource builder for the AzureContainerRegistryResource.
schedulestringThe cron schedule for the purge task timer trigger. Must be a five-part cron expression ( minute hour day-of-month month day-of-week); seconds are not supported.
filterstring?optionalAn optional filter for the acr purge --filter parameter. Only repositories matching this filter will be purged. Defaults to ".*:.*" (all repositories and tags) when null.
agoTimeSpan?optionalThe age threshold for acr purge --ago. Tags last modified before this duration are eligible for removal unless protected by keep. Defaults to zero when null.
keepintoptionalThe minimum number of newest matching tags to retain per repository, regardless of age. Must be greater than zero. Defaults to 3.
taskNamestring?optionalAn optional name for the ACR task resource. If not provided, a name is auto-generated based on existing purge tasks to avoid conflicts. If a task with the specified name already exists, an ArgumentException is thrown.
IResourceBuilder<AzureContainerRegistryResource>A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
ArgumentNullExceptionThrown when builder is null.
ArgumentExceptionThrown when schedule is null, empty, or whitespace, or when taskName conflicts with an existing task.
ArgumentOutOfRangeExceptionThrown when keep is less than 1, or ago is negative or less than 1 minute (when non-zero).
Tag removal alone does not reclaim storage. The task also deletes eligible previously untagged manifests and can break digest-based pulls and rollbacks. Tags younger than ago are also retained, so more than keep tags can remain. Eligible untagged manifests are deleted regardless of age. Locked artifacts and dependencies of retained images are protected.

This example schedules a daily purge of tags older than 7 days, protecting the 5 newest matching tags per repository and removing eligible untagged manifests:

var acr = builder.AddAzureContainerRegistry("myregistry")
.WithPurgeTask("0 1 * * *", ago: TimeSpan.FromDays(7), keep: 5);
WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureContainerRegistryResource>, ContainerRegistryBuiltInRole[])Section titled WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureContainerRegistryResource>, ContainerRegistryBuiltInRole[])extensionIResourceBuilder<T>
Adds role assignments to the specified Azure Container Registry resource.
public static class AzureContainerRegistryExtensions
{
public static IResourceBuilder<T> WithRoleAssignments<T>(
this IResourceBuilder<T> builder,
IResourceBuilder<AzureContainerRegistryResource> target,
params ContainerRegistryBuiltInRole[] roles)
{
// ...
}
}
builderIResourceBuilder<T>The resource builder for the resource that will have role assignments.
targetIResourceBuilder<AzureContainerRegistryResource>The target Azure Container Registry resource.
rolesContainerRegistryBuiltInRole[]The roles to assign to the resource.
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1.
This overload is not available in polyglot AppHosts. Use AzureContainerRegistryExtensions.WithRoleAssignments instead.