Unable to publish or import psresource in cache rule
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:
- create acr
- create cache rule
- copy psresource into the acr (
oras copy,Import-AzContainerRegistryImage,az acr import) - 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:
- the acr does the pull for me (automatically or manually triggered)
- I can use
Import-AzContainerRegistryImagewithout 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
Import-AzContainerRegistryImage
az acr import
Any relevant environment information
- OS: win11
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!
Find-PSResource is now able to find the modules:
Updated issue
- Could any doc be updated to tell users to use
oras pullto populate target repo of psresource-cache-rules? - Or should
Find-PSResource&Install-PSResourcehandle the 'pull' themself instead of relying on 3rd-party tools?
- Could any doc be updated to tell users to use oras pull to populate target repo of psresource-cache-rules?
- 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.
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.
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.
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.