-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompile-Containers.ps1
More file actions
76 lines (61 loc) · 2.48 KB
/
Copy pathCompile-Containers.ps1
File metadata and controls
76 lines (61 loc) · 2.48 KB
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
<#
.SYNOPSIS
Compile containers inside the folder containers with az cli
.DESCRIPTION
Compile containers inside the folder containers with az cli and sends tasks to the registry to compile the code
.EXAMPLE
PS > Compile-Containers.ps1
Compile containers inside the folder containers with az cli in resource group monitoring-rg and registry acr-monitoring
.EXAMPLE
PS > Compile-Containers.ps1 -ResourceGroupName "monitoring-rg" -RegistryName "acr-monitoring" -FolderName "containers" -TagName "latest" -SourceFolder "src"
Compiles containers inside the folder containers with az cli in resource group monitoring-rg and registry acr-monitoring
with folder name containers, tag name latest and source folder src
. LINK
http://github.com/vrhovnik
#>
[CmdletBinding(DefaultParameterSetName = "Codez")]
[Alias('azcc')]
param(
[Parameter(Mandatory = $false)]
$ResourceGroupName = "monitoring-rg",
[Parameter(Mandatory = $false)]
$RegistryName = "acr-monitoring",
[Parameter(Mandatory = $false)]
$FolderName = "containers",
[Parameter(Mandatory = $false)]
$TagName = "latest",
[Parameter(Mandatory = $false)]
$SourceFolder = "src",
[Parameter(Mandatory=$false)]
[switch]$InstallCli
)
$logPath = "$HOME/Downloads/container-build.log"
Start-Transcript -Path $logPath -Force
if ($InstallCli)
{
Start-Process ../Azure/Install-AzCli.ps1 -NoNewWindow -Wait
}
Write-Output "Reading registry $RegistryName in Azure"
$registry = Get-AzContainerRegistry -ResourceGroupName $ResourceGroupName -Name $RegistryName
$name = $registry.Name
Write-Output "Registry $name has been read"
Write-Output "Reading the folder $FolderName"
Get-ChildItem -Path $FolderName | ForEach-Object {
$imageRepo = $_.Name.Split('-')[0]
$imageName = $_.Name.Split('-')[1]
$dockerFile = $_.FullName
Write-Output "Building image $imageName with tag $TagName based on $dockerFile"
$imageNameWithTag = "$($name).azurecr.io/$($imageRepo.ToLower())/$($imageName.ToLower()):$($TagName)"
Write-Output "Taging image with $imageNameWithTag"
Write-Information "Call data with AZ cli as we don't have support in Azure PowerShell for this yet."
# you can install by providing the switch -InstallCli
az acr build --registry $registry.Name --image $imageNameWithTag -f $dockerFile $SourceFolder
}
Write-Output "Building images done"
Stop-Transcript
#read it in notepad
if ($OpenLog)
{
Write-Information "Opening log file $logPath"
Start-Process "notepad" -ArgumentList $logPath
}