Merge pull request #1850 from maxim-lobanov/v-malob/improve-azure-scripts

Improve GenerateResourcesAndImage.ps1 - Adapt for Unix
This commit is contained in:
Maxim Lobanov
2020-10-22 08:04:13 +03:00
committed by GitHub

View File

@@ -16,27 +16,32 @@ 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 {
@@ -45,7 +50,7 @@ Function Get-LatestCommit {
process {
Write-Host "Latest commit:"
git log --pretty=format:"Date: %cd; Commit: %H - %s; Author: %an <%ae>" -1
git --no-pager log --pretty=format:"Date: %cd; Commit: %H - %s; Author: %an <%ae>" -1
}
}
@@ -87,12 +92,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 +189,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)" `