Update GenerateResourcesAndImage.ps1

This commit is contained in:
Maxim Lobanov
2020-10-19 18:51:09 +03:00
parent 941243a186
commit 6dd01800ff

View File

@@ -16,27 +16,42 @@ Function Get-PackerTemplatePath {
[ImageType] $ImageType
)
$relativePath = "N/A"
switch ($ImageType) {
([ImageType]::Windows2016) {
$relativePath = "\images\win\windows2016.json"
$relativeTemplatePath = Join-Path "win" "windows2016.json"
}
([ImageType]::Windows2019) {
$relativePath = "\images\win\windows2019.json"
$relativeTemplatePath = Join-Path "win" "windows2019.json"
}
([ImageType]::Ubuntu1604) {
$relativePath = "\images\linux\ubuntu1604.json"
$relativeTemplatePath = Join-Path "linux" "ubuntu1604.json"
}
([ImageType]::Ubuntu1804) {
$relativePath = "\images\linux\ubuntu1804.json"
$relativeTemplatePath = Join-Path "linux" "ubuntu1804.json"
}
([ImageType]::Ubuntu2004) {
$relativePath = "\images\linux\ubuntu2004.json"
$relativeTemplatePath = Join-Path "linux" "ubuntu2004.json"
}
default { throw "Unknown type of image" }
}
return $RepositoryRoot + $relativePath;
$imageTemplatePath = [IO.Path]::Combine($RepositoryRoot, "images", $relativeTemplatePath)
if (-not (Test-Path $imageTemplatePath)) {
throw "Template for image '$ImageType' doesn't exist on path '$imageTemplatePath'"
}
return $imageTemplatePath;
}
Function Get-LatestCommit {
[CmdletBinding()]
param()
process {
Write-Host "Latest commit:"
git --no-pager log --pretty=format:"Date: %cd; Commit: %H - %s; Author: %an <%ae>" -1
}
}
Function Get-LatestCommit {
@@ -87,12 +102,12 @@ Function GenerateResourcesAndImage {
[Parameter(Mandatory = $True)]
[string] $ResourceGroupName,
[Parameter(Mandatory = $True)]
[string] $ImageGenerationRepositoryRoot,
[Parameter(Mandatory = $True)]
[ImageType] $ImageType,
[Parameter(Mandatory = $True)]
[string] $AzureLocation,
[Parameter(Mandatory = $False)]
[string] $ImageGenerationRepositoryRoot = $pwd,
[Parameter(Mandatory = $False)]
[int] $SecondsToWaitForServicePrincipalSetup = 30,
[Parameter(Mandatory = $False)]
[string] $GithubFeedToken,
@@ -184,7 +199,12 @@ Function GenerateResourcesAndImage {
Get-LatestCommit -ErrorAction SilentlyContinue
packer.exe build -on-error=ask `
$packerBinary = Get-Command "packer"
if (-not ($packerBinary)) {
throw "'packer' binary is not found on PATH"
}
& $packerBinary build -on-error=ask `
-var "client_id=$($spClientId)" `
-var "client_secret=$($ServicePrincipalClientSecret)" `
-var "subscription_id=$($SubscriptionId)" `