Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update Azure Container Registry cache-rule to support unauthenticated repositories and wildcards #3764

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f5cef3e
Make `credentialSetResourceId` optional
seesharprun Nov 11, 2024
7ffc7ba
Fix `name` parameter to replace wildcard (asterisk) symbol
seesharprun Nov 11, 2024
b05f277
Make `credentialSetResourceId` nullable
seesharprun Nov 11, 2024
1a8dbef
Add unit tests
seesharprun Nov 11, 2024
89d0db2
Run generation of readme and JSON files
seesharprun Nov 11, 2024
cc0a93b
Run `Set-AVMModule` on all sub-modules
seesharprun Nov 11, 2024
6574d66
Use a unique string for the cache-rule name instead of fragile `repla…
seesharprun Nov 11, 2024
23abaca
Fixed `replace` logic
seesharprun Nov 12, 2024
9646b1b
Try not setting `credentialSetResourceId`
seesharprun Nov 12, 2024
cb5e18d
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 12, 2024
2397f9c
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 14, 2024
697ae65
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 15, 2024
5d36196
Push to Bicep `0.31.92.45157`
seesharprun Nov 18, 2024
b854404
Remove credential set conflict
seesharprun Nov 18, 2024
1ad088c
Rework tests
seesharprun Nov 20, 2024
0007f7f
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 20, 2024
37fe901
Fix bug with unique key vault names in test
seesharprun Nov 20, 2024
c49924e
Fix credential set deployment
seesharprun Nov 21, 2024
69dcd66
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 21, 2024
ce9774e
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 21, 2024
6dc2aa3
Merge branch 'Azure:main' into fix-container-registry-cache-rules-params
seesharprun Nov 25, 2024
ed897fd
Merge branch 'main' into fix-container-registry-cache-rules-params
AlexanderSehr Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 7 additions & 45 deletions avm/res/container-registry/registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,9 @@ module registry 'br/public:avm/res/container-registry/registry:<version>' = {
sourceRepository: 'docker.io/library/hello-world'
targetRepository: 'cached-docker-hub/hello-world'
}
]
credentialSets: [
{
authCredentials: [
{
name: 'Credential1'
passwordSecretIdentifier: '<passwordSecretIdentifier>'
usernameSecretIdentifier: '<usernameSecretIdentifier>'
}
]
loginServer: 'docker.io'
managedIdentities: {
systemAssigned: true
}
name: 'default'
sourceRepository: 'mcr.microsoft.com/*'
targetRepository: 'cached-mcr/*'
}
]
location: '<location>'
Expand Down Expand Up @@ -119,24 +107,10 @@ module registry 'br/public:avm/res/container-registry/registry:<version>' = {
"name": "customRule",
"sourceRepository": "docker.io/library/hello-world",
"targetRepository": "cached-docker-hub/hello-world"
}
]
},
"credentialSets": {
"value": [
},
{
"authCredentials": [
{
"name": "Credential1",
"passwordSecretIdentifier": "<passwordSecretIdentifier>",
"usernameSecretIdentifier": "<usernameSecretIdentifier>"
}
],
"loginServer": "docker.io",
"managedIdentities": {
"systemAssigned": true
},
"name": "default"
"sourceRepository": "mcr.microsoft.com/*",
"targetRepository": "cached-mcr/*"
}
]
},
Expand Down Expand Up @@ -169,21 +143,9 @@ param cacheRules = [
sourceRepository: 'docker.io/library/hello-world'
targetRepository: 'cached-docker-hub/hello-world'
}
]
param credentialSets = [
{
authCredentials: [
{
name: 'Credential1'
passwordSecretIdentifier: '<passwordSecretIdentifier>'
usernameSecretIdentifier: '<usernameSecretIdentifier>'
}
]
loginServer: 'docker.io'
managedIdentities: {
systemAssigned: true
}
name: 'default'
sourceRepository: 'mcr.microsoft.com/*'
targetRepository: 'cached-mcr/*'
}
]
param location = '<location>'
Expand Down
18 changes: 9 additions & 9 deletions avm/res/container-registry/registry/cache-rule/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,17 @@ Cache for Azure Container Registry (Preview) feature allows users to cache conta

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`credentialSetResourceId`](#parameter-credentialsetresourceid) | string | The resource ID of the credential store which is associated with the cache rule. |
| [`registryName`](#parameter-registryname) | string | The name of the parent registry. Required if the template is used in a standalone deployment. |
| [`sourceRepository`](#parameter-sourcerepository) | string | Source repository pulled from upstream. |

**Optional parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`credentialSetResourceId`](#parameter-credentialsetresourceid) | string | The resource ID of the credential store which is associated with the cache rule. |
| [`name`](#parameter-name) | string | The name of the cache rule. Will be derived from the source repository name if not defined. |
| [`targetRepository`](#parameter-targetrepository) | string | Target repository specified in docker pull command. E.g.: docker pull myregistry.azurecr.io/{targetRepository}:{tag}. |

### Parameter: `credentialSetResourceId`

The resource ID of the credential store which is associated with the cache rule.

- Required: Yes
- Type: string

### Parameter: `registryName`

The name of the parent registry. Required if the template is used in a standalone deployment.
Expand All @@ -52,13 +45,20 @@ Source repository pulled from upstream.
- Required: Yes
- Type: string

### Parameter: `credentialSetResourceId`

The resource ID of the credential store which is associated with the cache rule.

- Required: No
- Type: string

### Parameter: `name`

The name of the cache rule. Will be derived from the source repository name if not defined.

- Required: No
- Type: string
- Default: `[replace(replace(parameters('sourceRepository'), '/', '-'), '.', '-')]`
- Default: `[replace(replace(replace(parameters('sourceRepository'), '/', '-'), '.', '-'), '*', '')]`

### Parameter: `targetRepository`

Expand Down
6 changes: 3 additions & 3 deletions avm/res/container-registry/registry/cache-rule/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ metadata owner = 'Azure/module-maintainers'
param registryName string

@description('Optional. The name of the cache rule. Will be derived from the source repository name if not defined.')
param name string = replace(replace(sourceRepository, '/', '-'), '.', '-')
param name string = replace(replace(replace(sourceRepository, '/', '-'), '.', '-'), '*', '')

@description('Required. Source repository pulled from upstream.')
param sourceRepository string

@description('Optional. Target repository specified in docker pull command. E.g.: docker pull myregistry.azurecr.io/{targetRepository}:{tag}.')
param targetRepository string = sourceRepository

@description('Required. The resource ID of the credential store which is associated with the cache rule.')
param credentialSetResourceId string
@description('Optional. The resource ID of the credential store which is associated with the cache rule.')
param credentialSetResourceId string?

resource registry 'Microsoft.ContainerRegistry/registries@2023-06-01-preview' existing = {
name: registryName
Expand Down
27 changes: 19 additions & 8 deletions avm/res/container-registry/registry/cache-rule/main.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"languageVersion": "2.0",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.3.12046",
"templateHash": "17205938486061573561"
"version": "0.31.92.45157",
"templateHash": "17904436773568970815"
},
"name": "Container Registries Cache",
"description": "Cache for Azure Container Registry (Preview) feature allows users to cache container images in a private container registry. Cache for ACR, is a preview feature available in Basic, Standard, and Premium service tiers ([ref](https://learn.microsoft.com/en-us/azure/container-registry/tutorial-registry-cache)).",
Expand All @@ -20,7 +21,7 @@
},
"name": {
"type": "string",
"defaultValue": "[replace(replace(parameters('sourceRepository'), '/', '-'), '.', '-')]",
"defaultValue": "[replace(replace(replace(parameters('sourceRepository'), '/', '-'), '.', '-'), '*', '')]",
"metadata": {
"description": "Optional. The name of the cache rule. Will be derived from the source repository name if not defined."
}
Expand All @@ -40,23 +41,33 @@
},
"credentialSetResourceId": {
"type": "string",
"nullable": true,
"metadata": {
"description": "Required. The resource ID of the credential store which is associated with the cache rule."
"description": "Optional. The resource ID of the credential store which is associated with the cache rule."
}
}
},
"resources": [
{
"resources": {
"registry": {
"existing": true,
"type": "Microsoft.ContainerRegistry/registries",
"apiVersion": "2023-06-01-preview",
"name": "[parameters('registryName')]"
},
"cacheRule": {
"type": "Microsoft.ContainerRegistry/registries/cacheRules",
"apiVersion": "2023-06-01-preview",
"name": "[format('{0}/{1}', parameters('registryName'), parameters('name'))]",
"properties": {
"sourceRepository": "[parameters('sourceRepository')]",
"targetRepository": "[parameters('targetRepository')]",
"credentialSetResourceId": "[parameters('credentialSetResourceId')]"
}
},
"dependsOn": [
"registry"
]
}
],
},
"outputs": {
"name": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.3.12046",
"templateHash": "13281764602355848660"
"version": "0.31.92.45157",
"templateHash": "6279725946439884689"
},
"name": "Container Registries Credential Sets",
"description": "This module deploys an ACR Credential Set.",
Expand Down
4 changes: 2 additions & 2 deletions avm/res/container-registry/registry/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ module registry_cacheRules 'cache-rule/main.bicep' = [
params: {
registryName: registry.name
sourceRepository: cacheRule.sourceRepository
name: cacheRule.?name ?? replace(replace(cacheRule.sourceRepository, '/', '-'), '.', '-')
name: cacheRule.?name ?? replace(replace(replace(cacheRule.sourceRepository, '/', '-'), '.', '-'), '*', '')
targetRepository: cacheRule.?targetRepository ?? cacheRule.sourceRepository
credentialSetResourceId: cacheRule.?credentialSetResourceId
credentialSetResourceId: !empty(cacheRule.?credentialSetResourceId) ? cacheRule.?credentialSetResourceId : null // Must only be set if condition is set
}
dependsOn: [
registry_credentialSets
Expand Down
53 changes: 31 additions & 22 deletions avm/res/container-registry/registry/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.23.60470",
"templateHash": "2277340268999354626"
"version": "0.31.92.45157",
"templateHash": "10825632871667902997"
},
"name": "Azure Container Registries (ACR)",
"description": "This module deploys an Azure Container Registry (ACR).",
Expand Down Expand Up @@ -1028,8 +1028,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.23.60470",
"templateHash": "17963190751439748514"
"version": "0.31.92.45157",
"templateHash": "2013383059353814727"
},
"name": "Container Registries scopeMaps",
"description": "This module deploys an Azure Container Registry (ACR) scopeMap.",
Expand Down Expand Up @@ -1155,8 +1155,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.23.60470",
"templateHash": "4997004041066797666"
"version": "0.31.92.45157",
"templateHash": "15634919072704510138"
},
"name": "Azure Container Registry (ACR) Replications",
"description": "This module deploys an Azure Container Registry (ACR) Replication.",
Expand Down Expand Up @@ -1303,8 +1303,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.23.60470",
"templateHash": "7759513970094711275"
"version": "0.31.92.45157",
"templateHash": "6279725946439884689"
},
"name": "Container Registries Credential Sets",
"description": "This module deploys an ACR Credential Set.",
Expand Down Expand Up @@ -1463,23 +1463,22 @@
"value": "[coalesce(parameters('cacheRules'), createArray())[copyIndex()].sourceRepository]"
},
"name": {
"value": "[coalesce(tryGet(coalesce(parameters('cacheRules'), createArray())[copyIndex()], 'name'), replace(replace(coalesce(parameters('cacheRules'), createArray())[copyIndex()].sourceRepository, '/', '-'), '.', '-'))]"
"value": "[coalesce(tryGet(coalesce(parameters('cacheRules'), createArray())[copyIndex()], 'name'), replace(replace(replace(coalesce(parameters('cacheRules'), createArray())[copyIndex()].sourceRepository, '/', '-'), '.', '-'), '*', ''))]"
},
"targetRepository": {
"value": "[coalesce(tryGet(coalesce(parameters('cacheRules'), createArray())[copyIndex()], 'targetRepository'), coalesce(parameters('cacheRules'), createArray())[copyIndex()].sourceRepository)]"
},
"credentialSetResourceId": {
"value": "[tryGet(coalesce(parameters('cacheRules'), createArray())[copyIndex()], 'credentialSetResourceId')]"
}
"credentialSetResourceId": "[if(not(empty(tryGet(coalesce(parameters('cacheRules'), createArray())[copyIndex()], 'credentialSetResourceId'))), createObject('value', tryGet(coalesce(parameters('cacheRules'), createArray())[copyIndex()], 'credentialSetResourceId')), createObject('value', null()))]"
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"languageVersion": "2.0",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.23.60470",
"templateHash": "1396902957012921251"
"version": "0.31.92.45157",
"templateHash": "17904436773568970815"
},
"name": "Container Registries Cache",
"description": "Cache for Azure Container Registry (Preview) feature allows users to cache container images in a private container registry. Cache for ACR, is a preview feature available in Basic, Standard, and Premium service tiers ([ref](https://learn.microsoft.com/en-us/azure/container-registry/tutorial-registry-cache)).",
Expand All @@ -1494,7 +1493,7 @@
},
"name": {
"type": "string",
"defaultValue": "[replace(replace(parameters('sourceRepository'), '/', '-'), '.', '-')]",
"defaultValue": "[replace(replace(replace(parameters('sourceRepository'), '/', '-'), '.', '-'), '*', '')]",
"metadata": {
"description": "Optional. The name of the cache rule. Will be derived from the source repository name if not defined."
}
Expand All @@ -1514,23 +1513,33 @@
},
"credentialSetResourceId": {
"type": "string",
"nullable": true,
"metadata": {
"description": "Required. The resource ID of the credential store which is associated with the cache rule."
"description": "Optional. The resource ID of the credential store which is associated with the cache rule."
}
}
},
"resources": [
{
"resources": {
"registry": {
"existing": true,
"type": "Microsoft.ContainerRegistry/registries",
"apiVersion": "2023-06-01-preview",
"name": "[parameters('registryName')]"
},
"cacheRule": {
"type": "Microsoft.ContainerRegistry/registries/cacheRules",
"apiVersion": "2023-06-01-preview",
"name": "[format('{0}/{1}', parameters('registryName'), parameters('name'))]",
"properties": {
"sourceRepository": "[parameters('sourceRepository')]",
"targetRepository": "[parameters('targetRepository')]",
"credentialSetResourceId": "[parameters('credentialSetResourceId')]"
}
},
"dependsOn": [
"registry"
]
}
],
},
"outputs": {
"name": {
"type": "string",
Expand Down Expand Up @@ -1610,8 +1619,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.23.60470",
"templateHash": "10216591470402784498"
"version": "0.31.92.45157",
"templateHash": "14778812339643154349"
},
"name": "Azure Container Registry (ACR) Webhooks",
"description": "This module deploys an Azure Container Registry (ACR) Webhook.",
Expand Down
4 changes: 2 additions & 2 deletions avm/res/container-registry/registry/replication/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.3.12046",
"templateHash": "11507205381257602922"
"version": "0.31.92.45157",
"templateHash": "15634919072704510138"
},
"name": "Azure Container Registry (ACR) Replications",
"description": "This module deploys an Azure Container Registry (ACR) Replication.",
Expand Down
4 changes: 2 additions & 2 deletions avm/res/container-registry/registry/scope-map/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.3.12046",
"templateHash": "17045733538280748766"
"version": "0.31.92.45157",
"templateHash": "2013383059353814727"
},
"name": "Container Registries scopeMaps",
"description": "This module deploys an Azure Container Registry (ACR) scopeMap.",
Expand Down
Loading