From 5e897e989e3fdd476349d170410e5e89b24498bb Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 23 Jan 2020 14:14:05 +0300 Subject: [PATCH 1/5] update docs and pass github access token --- help/CreateImageAndAzureResources.md | 11 +++++++++++ helpers/GenerateResourcesAndImage.ps1 | 24 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 help/CreateImageAndAzureResources.md diff --git a/help/CreateImageAndAzureResources.md b/help/CreateImageAndAzureResources.md new file mode 100644 index 00000000..3684dfba --- /dev/null +++ b/help/CreateImageAndAzureResources.md @@ -0,0 +1,11 @@ +# Build an image. + +## Create required Azure resources and generate an image + +1. Generating required Azure resources and running a packer build for a targeted image is automated [here](../helpers/GenerateResourcesAndImage.ps1). + +## Create a VM based on the template created by Packer + +1. At the end of the output from running Packer above is a URL to the VM resource template with a read access token. It ends with `.json` plus a query string. Note this URL. For now, it seems like there is an [Az CLI bug](https://github.com/Azure/azure-cli/issues/5899) with specifying the template through a URI. So download the template locally and note the path of the template file. +1. Generating the required Azure resources and creating the VM is automated [here](../helpers/CreateAzureVMFromPackerTemplate.ps1). +1. After the VM is created, remote into it using its public IP address. You can test the installed tools or install the Azure Pipelines agent and connect it to your Azure DevOps organization. \ No newline at end of file diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index bc0e649f..cf683ece 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -61,6 +61,9 @@ Function GenerateResourcesAndImage { .PARAMETER Force Delete the resource group if it exists without user confirmation. + .PARAMETER GithubFeedToken + GitHub PAT to download tool packages from GitHub Package Registry + .EXAMPLE GenerateResourcesAndImage -SubscriptionId {YourSubscriptionId} -ResourceGroupName "shsamytest1" -ImageGenerationRepositoryRoot "C:\virtual-environments" -ImageType Ubuntu1604 -AzureLocation "East US" #> @@ -77,10 +80,18 @@ Function GenerateResourcesAndImage { [string] $AzureLocation, [Parameter(Mandatory = $False)] [int] $SecondsToWaitForServicePrincipalSetup = 30, + [Parameter(Mandatory = $True)] + [string] $GithubFeedToken, [Parameter(Mandatory = $False)] [Switch] $Force ) + if (([string]::IsNullOrEmpty($version))) + { + Write-Error "You have to specify valid GitHub PAT to dowload tool packages from GitHub Package Registry" + exit 0 + } + $builderScriptPath = Get-PackerTemplatePath -RepositoryRoot $ImageGenerationRepositoryRoot -ImageType $ImageType $ServicePrincipalClientSecret = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper(); $InstallPassword = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper(); @@ -155,5 +166,16 @@ Function GenerateResourcesAndImage { $tenantId = $sub.TenantId # "", "Note this variable-setting script for running Packer with these Azure resources in the future:", "==============================================================================================", "`$spClientId = `"$spClientId`"", "`$ServicePrincipalClientSecret = `"$ServicePrincipalClientSecret`"", "`$SubscriptionId = `"$SubscriptionId`"", "`$tenantId = `"$tenantId`"", "`$spObjectId = `"$spObjectId`"", "`$AzureLocation = `"$AzureLocation`"", "`$ResourceGroupName = `"$ResourceGroupName`"", "`$storageAccountName = `"$storageAccountName`"", "`$install_password = `"$install_password`"", "" - packer.exe build -on-error=ask -var "client_id=$($spClientId)" -var "client_secret=$($ServicePrincipalClientSecret)" -var "subscription_id=$($SubscriptionId)" -var "tenant_id=$($tenantId)" -var "object_id=$($spObjectId)" -var "location=$($AzureLocation)" -var "resource_group=$($ResourceGroupName)" -var "storage_account=$($storageAccountName)" -var "install_password=$($InstallPassword)" $builderScriptPath + packer.exe build -on-error=ask ` + -var "client_id=$($spClientId)" ` + -var "client_secret=$($ServicePrincipalClientSecret)" ` + -var "subscription_id=$($SubscriptionId)" ` + -var "tenant_id=$($tenantId)" ` + -var "object_id=$($spObjectId)" ` + -var "location=$($AzureLocation)" ` + -var "resource_group=$($ResourceGroupName)" ` + -var "storage_account=$($storageAccountName)" ` + -var "install_password=$($InstallPassword)" ` + -var "github_feed_token=$($GithubFeedToken)" ` + $builderScriptPath } From 87a3b79da547ccc59db8c7bd8a5d7a31c0110081 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Fri, 24 Jan 2020 10:49:02 +0300 Subject: [PATCH 2/5] minor changes --- helpers/GenerateResourcesAndImage.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index cf683ece..58fdc476 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -86,10 +86,10 @@ Function GenerateResourcesAndImage { [Switch] $Force ) - if (([string]::IsNullOrEmpty($version))) + if (([string]::IsNullOrEmpty($GithubFeedToken))) { - Write-Error "You have to specify valid GitHub PAT to dowload tool packages from GitHub Package Registry" - exit 0 + Write-Error "You have to specify valid GitHub PAT to download tool packages from GitHub Package Registry" + exit 1 } $builderScriptPath = Get-PackerTemplatePath -RepositoryRoot $ImageGenerationRepositoryRoot -ImageType $ImageType From 5480c496499dd4d8f4e9031953ec8482e962634e Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Fri, 24 Jan 2020 10:55:32 +0300 Subject: [PATCH 3/5] fix output --- helpers/GenerateResourcesAndImage.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index 58fdc476..9fd19fd4 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -80,7 +80,7 @@ Function GenerateResourcesAndImage { [string] $AzureLocation, [Parameter(Mandatory = $False)] [int] $SecondsToWaitForServicePrincipalSetup = 30, - [Parameter(Mandatory = $True)] + [Parameter(Mandatory = $False)] [string] $GithubFeedToken, [Parameter(Mandatory = $False)] [Switch] $Force @@ -88,7 +88,7 @@ Function GenerateResourcesAndImage { if (([string]::IsNullOrEmpty($GithubFeedToken))) { - Write-Error "You have to specify valid GitHub PAT to download tool packages from GitHub Package Registry" + Write-Error "'-GithubFeedToken' parameter is not specified. You have to specify valid GitHub PAT to download tool packages from GitHub Package Registry" exit 1 } From e3da53b47d78f19295bb75d322f1da7090ece1ac Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Fri, 24 Jan 2020 14:39:47 +0300 Subject: [PATCH 4/5] updating docs --- README.md | 2 ++ help/CreateImageAndAzureResources.md | 1 + 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 647416e8..cf8a7eb0 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ Please use the issue templates to submit requests and bug reports related to the If you need help with how to set up your workflow file or use a specific tool, check out the [GitHub Actions Community Forum](https://github.community/t5/GitHub-Actions/bd-p/actions). +If you need help with how to build VM machine from source code, check out the [documentation](./help/CreateImageAndAzureResources.md). + ## OS's offered We currently offer Linux, macOS, and Windows virtual environments: diff --git a/help/CreateImageAndAzureResources.md b/help/CreateImageAndAzureResources.md index 3684dfba..6c6fd21f 100644 --- a/help/CreateImageAndAzureResources.md +++ b/help/CreateImageAndAzureResources.md @@ -8,4 +8,5 @@ 1. At the end of the output from running Packer above is a URL to the VM resource template with a read access token. It ends with `.json` plus a query string. Note this URL. For now, it seems like there is an [Az CLI bug](https://github.com/Azure/azure-cli/issues/5899) with specifying the template through a URI. So download the template locally and note the path of the template file. 1. Generating the required Azure resources and creating the VM is automated [here](../helpers/CreateAzureVMFromPackerTemplate.ps1). +1. Building VM machines based on packer template is automated [here](../helpers/GenerateResourcesAndImage.ps1). 1. After the VM is created, remote into it using its public IP address. You can test the installed tools or install the Azure Pipelines agent and connect it to your Azure DevOps organization. \ No newline at end of file From 77f6c5465e578c2d0e6036c37ac046f8814bc12d Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Fri, 24 Jan 2020 15:55:10 +0300 Subject: [PATCH 5/5] remove extra string --- help/CreateImageAndAzureResources.md | 1 - 1 file changed, 1 deletion(-) diff --git a/help/CreateImageAndAzureResources.md b/help/CreateImageAndAzureResources.md index 6c6fd21f..3684dfba 100644 --- a/help/CreateImageAndAzureResources.md +++ b/help/CreateImageAndAzureResources.md @@ -8,5 +8,4 @@ 1. At the end of the output from running Packer above is a URL to the VM resource template with a read access token. It ends with `.json` plus a query string. Note this URL. For now, it seems like there is an [Az CLI bug](https://github.com/Azure/azure-cli/issues/5899) with specifying the template through a URI. So download the template locally and note the path of the template file. 1. Generating the required Azure resources and creating the VM is automated [here](../helpers/CreateAzureVMFromPackerTemplate.ps1). -1. Building VM machines based on packer template is automated [here](../helpers/GenerateResourcesAndImage.ps1). 1. After the VM is created, remote into it using its public IP address. You can test the installed tools or install the Azure Pipelines agent and connect it to your Azure DevOps organization. \ No newline at end of file