acr icon indicating copy to clipboard operation
acr copied to clipboard

Unable to publish or import psresource in cache rule

Open picccard opened this issue 5 months ago • 3 comments

Describe the bug After creating a ACR for psresources with a cache rule against MAR, there is no way to get the module into the ACR. The cache rule blocks pushes for the target-repo in the cache rule.

I need a way for my acr to pull the pwsh module referenced in the cache rule OR be allowed to push/copy this module into the acr.

To Reproduce Steps to reproduce the behavior:

  1. create acr
  2. create cache rule
  3. copy psresource into the acr (oras copy, Import-AzContainerRegistryImage, az acr import)
  4. get error
$resourceGroupName = 'rg-pwshacr'
$registryName = 'acrtest736'
Connect-AzAccount
New-AzContainerRegistry -Name $registryName -ResourceGroupName $resourceGroupName -Sku 'Basic' -Location 'swedencentral'

$body = @{
  properties = @{
    sourceRepository = 'mcr.microsoft.com/psresource/az.ssh'
    targetRepository = "az.ssh"
  }
}
$subId = (Get-AzContext).Subscription.Id
$uri = "https://management.azure.com/subscriptions/$subId/resourceGroups/$resourceGroupName/providers/Microsoft.ContainerRegistry/registries/$registryName/cacheRules/nameforcacherule?api-version=2023-01-01-preview"
Invoke-AzRestMethod -Uri $uri -Method PUT -Payload ($body | ConvertTo-Json)


$splat = @{
  RegistryName = $registryName
  ResourceGroupName = $resourceGroupName
  SourceRegistryUri = 'mcr.microsoft.com'
  SourceImage = 'psresource/az.ssh:0.2.1'
  TargetTag = 'az.ssh:0.2.1'
}
Import-AzContainerRegistryImage @splat

Expected behavior Two possible behaviors:

  1. the acr does the pull for me (automatically or manually triggered)
  2. I can use Import-AzContainerRegistryImage without error, as long as the source registry and source image matches the cache rule. e.g. I should not be able to have a cache rule for a MAR-module and push my local module to that acr- repository

Screenshots

oras copy

Image

Import-AzContainerRegistryImage

Image

az acr import

Image

Any relevant environment information

  • OS: win11
Image

picccard avatar Jul 23 '25 14:07 picccard

Ok so with the cache rule in place you are not allowed to push anything to the acr-target-repo, hence the oras copy wont work. The docs for acr cache says

Cache only occurs after at least one image pull is complete on the available container image.

For every new image available, a new image pull must be complete.

Currently, artifact cache doesn't automatically pull new tags of images when a new tag is available.

So by doing oras pull acrname729.azurecr.io/az.ssh:0.2.1 I am able to populate the cache!

Image

Find-PSResource is now able to find the modules:

Image

Updated issue

  1. Could any doc be updated to tell users to use oras pull to populate target repo of psresource-cache-rules?
  2. Or should Find-PSResource & Install-PSResource handle the 'pull' themself instead of relying on 3rd-party tools?

picccard avatar Jul 25 '25 01:07 picccard

  1. Could any doc be updated to tell users to use oras pull to populate target repo of psresource-cache-rules?
  1. Or should Find-PSResource & Install-PSResource handle the 'pull' themself instead of relying on 3rd-party tools?

Hi @picccard , thanks for the feedback.

I think the 2nd approach makes more sense since oras is more like a workaround here. We want to make sure ACR Cache work as expected. @JXavierMSFT could you please help look into it?

Note that oras as a CNCF project is also maintained by Microsoft.

FeynmanZhou avatar Jul 26 '25 00:07 FeynmanZhou

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Oct 25 '25 02:10 github-actions[bot]

Looking at some stale issues. @picccard, I am trying to understand why did you create a cache rule in the first place if you are interested in pushing the module manually? I may be missing something but the cache rule defines a "pull-through cache" - when a client pulls an artifact from the repository that the cache rule is defined for only then that artifact will be cached in the repository.

toddysm avatar Dec 19 '25 00:12 toddysm

Thank you for having a look at this.

I want to host the pwsh Az modules in my own acr. I do not want to handle anything manually so I create a cache-rule, but it does not automatically populate the cache. To populate the cache one would need to send the acr a pull request and then it will fetch from the upstream. BUT the pwsh cmdlets Install-PSResource did not make the acr fetch from the upstream! (at the time of creating the issue, atleast)

So populating the cache had to be done manually. I tried to push manually without luck. Using the oras cli to pull from the acr DID however populate the cache.

Edit: This issue might be more an pwsh/Install-PSResource issue.

picccard avatar Dec 19 '25 06:12 picccard