From 6dd01800fffe28c945d6907b0326e7ba442dffde Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Mon, 19 Oct 2020 18:51:09 +0300 Subject: [PATCH 1/2] Update GenerateResourcesAndImage.ps1 --- helpers/GenerateResourcesAndImage.ps1 | 42 ++++++++++++++++++++------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index 57c4675d2..737406302 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -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)" ` From d8b4ad72848d0ca4df3128fcd029ca50a0d96902 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Mon, 19 Oct 2020 18:53:17 +0300 Subject: [PATCH 2/2] Update GenerateResourcesAndImage.ps1 --- helpers/GenerateResourcesAndImage.ps1 | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index 737406302..67858841f 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -54,16 +54,6 @@ Function Get-LatestCommit { } } -Function Get-LatestCommit { - [CmdletBinding()] - param() - - process { - Write-Host "Latest commit:" - git log --pretty=format:"Date: %cd; Commit: %H - %s; Author: %an <%ae>" -1 - } -} - Function GenerateResourcesAndImage { <# .SYNOPSIS