Merge pull request #1850 from maxim-lobanov/v-malob/improve-azure-scripts
Improve GenerateResourcesAndImage.ps1 - Adapt for Unix
This commit is contained in:
@@ -16,27 +16,32 @@ Function Get-PackerTemplatePath {
|
|||||||
[ImageType] $ImageType
|
[ImageType] $ImageType
|
||||||
)
|
)
|
||||||
|
|
||||||
$relativePath = "N/A"
|
|
||||||
|
|
||||||
switch ($ImageType) {
|
switch ($ImageType) {
|
||||||
([ImageType]::Windows2016) {
|
([ImageType]::Windows2016) {
|
||||||
$relativePath = "\images\win\windows2016.json"
|
$relativeTemplatePath = Join-Path "win" "windows2016.json"
|
||||||
}
|
}
|
||||||
([ImageType]::Windows2019) {
|
([ImageType]::Windows2019) {
|
||||||
$relativePath = "\images\win\windows2019.json"
|
$relativeTemplatePath = Join-Path "win" "windows2019.json"
|
||||||
}
|
}
|
||||||
([ImageType]::Ubuntu1604) {
|
([ImageType]::Ubuntu1604) {
|
||||||
$relativePath = "\images\linux\ubuntu1604.json"
|
$relativeTemplatePath = Join-Path "linux" "ubuntu1604.json"
|
||||||
}
|
}
|
||||||
([ImageType]::Ubuntu1804) {
|
([ImageType]::Ubuntu1804) {
|
||||||
$relativePath = "\images\linux\ubuntu1804.json"
|
$relativeTemplatePath = Join-Path "linux" "ubuntu1804.json"
|
||||||
}
|
}
|
||||||
([ImageType]::Ubuntu2004) {
|
([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 {
|
Function Get-LatestCommit {
|
||||||
@@ -45,7 +50,7 @@ Function Get-LatestCommit {
|
|||||||
|
|
||||||
process {
|
process {
|
||||||
Write-Host "Latest commit:"
|
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)]
|
[Parameter(Mandatory = $True)]
|
||||||
[string] $ResourceGroupName,
|
[string] $ResourceGroupName,
|
||||||
[Parameter(Mandatory = $True)]
|
[Parameter(Mandatory = $True)]
|
||||||
[string] $ImageGenerationRepositoryRoot,
|
|
||||||
[Parameter(Mandatory = $True)]
|
|
||||||
[ImageType] $ImageType,
|
[ImageType] $ImageType,
|
||||||
[Parameter(Mandatory = $True)]
|
[Parameter(Mandatory = $True)]
|
||||||
[string] $AzureLocation,
|
[string] $AzureLocation,
|
||||||
[Parameter(Mandatory = $False)]
|
[Parameter(Mandatory = $False)]
|
||||||
|
[string] $ImageGenerationRepositoryRoot = $pwd,
|
||||||
|
[Parameter(Mandatory = $False)]
|
||||||
[int] $SecondsToWaitForServicePrincipalSetup = 30,
|
[int] $SecondsToWaitForServicePrincipalSetup = 30,
|
||||||
[Parameter(Mandatory = $False)]
|
[Parameter(Mandatory = $False)]
|
||||||
[string] $GithubFeedToken,
|
[string] $GithubFeedToken,
|
||||||
@@ -184,7 +189,12 @@ Function GenerateResourcesAndImage {
|
|||||||
|
|
||||||
Get-LatestCommit -ErrorAction SilentlyContinue
|
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_id=$($spClientId)" `
|
||||||
-var "client_secret=$($ServicePrincipalClientSecret)" `
|
-var "client_secret=$($ServicePrincipalClientSecret)" `
|
||||||
-var "subscription_id=$($SubscriptionId)" `
|
-var "subscription_id=$($SubscriptionId)" `
|
||||||
|
|||||||
Reference in New Issue
Block a user