-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbicepscript.ps1
78 lines (61 loc) · 2.35 KB
/
bicepscript.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
param (
[Parameter(Mandatory = $false)]
[string]$moduleName,
[Parameter(Mandatory = $true)]
[string]$containerRegistryName,
[Parameter(Mandatory = $true)]
[string]$containerRegistryResourceGroup,
[Parameter(Mandatory = $true)]
[string]$storageAccountName,
[Parameter(Mandatory = $true)]
[string]$storageAccountResourceGroup,
[Parameter(Mandatory = $true)]
[string]$storageAccountContainerName,
[Parameter(Mandatory = $false)]
[bool]$skipSchemaUpdate = $false
)
# Push Bicep Module to ACR
$azureContext = Get-AzContext
$azureContainerRegistry = Get-AzContainerRegistry `
-Name $containerRegistryName `
-ResourceGroupName $containerRegistryResourceGroup
$azureContainerRegistryUrl = $azureContainerRegistry.LoginServer
#region 1. ACR Push
Get-ChildItem "./modules/$moduleName/*" -Include '*.bicep' | ForEach-Object {
$moduleFilePath = $_.FullName
$name = $_.BaseName
$modulePath = "br:$azureContainerRegistryUrl/modules/$name" + ":" + "v1.0"
Write-Host "Pushing $modulePath" -ForegroundColor Green
Publish-AzBicepModule -FilePath $moduleFilePath -Target $modulePath -DefaultProfile $azureContext -Force
}
#endregion
#region 2. Schema Push
if ($skipSchemaUpdate -eq $false) {
# Push/Update JSON Parameter Schemas
$storageAccount = Get-AzStorageAccount `
-ResourceGroupName $storageAccountResourceGroup `
-Name $storageAccountName
# Get the Module Schema
$schema = Get-Item "./modules/$moduleName/parameters.json"
$index = $schema.FullName.IndexOf('modules') + 'modules'.Length + 1
$path = 'bicep' + '\' + $schema.FullName.Substring($index , $schema.FullName.Length - $index)
Set-AzStorageBlobContent `
-Container $storageAccountContainerName `
-Context $storageAccount.Context `
-Blob $path `
-File $schema.FullName `
-Force `
-Verbose
# Get the Root Schema
$schema = Get-Item "./modules/schema.json"
$index = $schema.FullName.IndexOf('modules') + 'modules'.Length + 1
$path = 'bicep' + '\' + $schema.FullName.Substring($index , $schema.FullName.Length - $index)
Set-AzStorageBlobContent `
-Container $storageAccountContainerName `
-Context $storageAccount.Context `
-Blob $path `
-File $schema.FullName `
-Force `
-Verbose
}
#endregion