diff --git a/helpers/CreateAzureVMFromPackerTemplate.ps1 b/helpers/CreateAzureVMFromPackerTemplate.ps1 index 0aa95b04f37f..683f2cf51bb1 100644 --- a/helpers/CreateAzureVMFromPackerTemplate.ps1 +++ b/helpers/CreateAzureVMFromPackerTemplate.ps1 @@ -1,10 +1,10 @@ Function CreateAzureVMFromPackerTemplate { <# .SYNOPSIS - Creates an Azure VM from a template. Also generates network resources in Azure to make the VM accessible. + A helper function to deploy a VM from a generated image. .DESCRIPTION - Creates Azure resources and kicks off a packer image generation for the selected image type. + Creates an Azure VM from a template. Also generates network resources in Azure to make the VM accessible. .PARAMETER SubscriptionId The Azure subscription Id where resources will be created. diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index 26d621787d3c..32177094980c 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -39,6 +39,16 @@ Function Get-PackerTemplatePath { return $RepositoryRoot + $relativePath; } +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 @@ -170,6 +180,8 @@ 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`"", "" + Get-LatestCommit -ErrorAction SilentlyContinue + packer.exe build -on-error=ask ` -var "client_id=$($spClientId)" ` -var "client_secret=$($ServicePrincipalClientSecret)" ` diff --git a/images.CI/azure-pipelines/image-generation.yml b/images.CI/azure-pipelines/image-generation.yml index d2adc15ae87a..70db48f1c525 100644 --- a/images.CI/azure-pipelines/image-generation.yml +++ b/images.CI/azure-pipelines/image-generation.yml @@ -17,13 +17,10 @@ jobs: displayName: 'Download custom repository' condition: and(ne(variables['CUSTOM_REPOSITORY_URL'], ''), ne(variables['CUSTOM_REPOSITORY_BRANCH'], '')) inputs: - targetType: 'inline' - script: | - Write-Host "Clean up default repository" - Remove-Item -path './*' -Recurse -Force - Write-Host "Download $(CUSTOM_REPOSITORY_BRANCH) branch from $(CUSTOM_REPOSITORY_URL)" - $env:GIT_REDIRECT_STDERR = '2>&1' - git clone $(CUSTOM_REPOSITORY_URL) . -b $(CUSTOM_REPOSITORY_BRANCH) --single-branch --depth 1 + targetType: 'filePath' + filePath: ./images.CI/download-repo.ps1 + arguments: -RepoUrl $(CUSTOM_REPOSITORY_URL) ` + -RepoBranch $(CUSTOM_REPOSITORY_BRANCH) - task: PowerShell@2 displayName: 'Build VM' diff --git a/images.CI/download-repo.ps1 b/images.CI/download-repo.ps1 new file mode 100644 index 000000000000..40270769ee80 --- /dev/null +++ b/images.CI/download-repo.ps1 @@ -0,0 +1,14 @@ +param( + [String] [Parameter (Mandatory=$true)] $RepoUrl, + [String] [Parameter (Mandatory=$true)] $RepoBranch +) + +Write-Host "Clean up default repository" +Remove-Item -path './*' -Recurse -Force + +Write-Host "Download ${RepoBranch} branch from ${RepoUrl}" +$env:GIT_REDIRECT_STDERR = '2>&1' +git clone $RepoUrl . -b $RepoBranch --single-branch --depth 1 + +Write-Host "Latest commit:" +git log --pretty=format:"Date: %cd; Commit: %H - %s; Author: %an <%ae>" -1 \ No newline at end of file diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index 74bc621366f7..4a5c5be13279 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -1,6 +1,5 @@ { "variables": { - "commit_url": "{{env `COMMIT_URL`}}", "client_id": "{{env `ARM_CLIENT_ID`}}", "client_secret": "{{env `ARM_CLIENT_SECRET`}}", "subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}", @@ -14,7 +13,6 @@ "virtual_network_subnet_name": "{{env `VNET_SUBNET`}}", "private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}", "image_folder": "/imagegeneration", - "commit_file": "/imagegeneration/commit.txt", "imagedata_file": "/imagegeneration/imagedata.json", "metadata_file": "/imagegeneration/metadatafile", "installer_script_folder": "/imagegeneration/installers", @@ -59,9 +57,7 @@ "type": "shell", "inline": [ "mkdir {{user `image_folder`}}", - "chmod 777 {{user `image_folder`}}", - "echo {{user `commit_url`}} > {{user `commit_file`}}", - "chmod +r {{user `commit_file`}}" + "chmod 777 {{user `image_folder`}}" ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index c5545cc12c75..91f468f36be2 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -1,6 +1,5 @@ { "variables": { - "commit_url": "{{env `COMMIT_URL`}}", "client_id": "{{env `ARM_CLIENT_ID`}}", "client_secret": "{{env `ARM_CLIENT_SECRET`}}", "subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}", @@ -14,7 +13,6 @@ "virtual_network_subnet_name": "{{env `VNET_SUBNET`}}", "private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}", "image_folder": "/imagegeneration", - "commit_file": "/imagegeneration/commit.txt", "imagedata_file": "/imagegeneration/imagedata.json", "metadata_file": "/imagegeneration/metadatafile", "installer_script_folder": "/imagegeneration/installers", @@ -59,9 +57,7 @@ "type": "shell", "inline": [ "mkdir {{user `image_folder`}}", - "chmod 777 {{user `image_folder`}}", - "echo {{user `commit_url`}} > {{user `commit_file`}}", - "chmod +r {{user `commit_file`}}" + "chmod 777 {{user `image_folder`}}" ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, diff --git a/images/linux/ubuntu2004.json b/images/linux/ubuntu2004.json index dd91fb7bc542..f3b7a68ac896 100644 --- a/images/linux/ubuntu2004.json +++ b/images/linux/ubuntu2004.json @@ -1,6 +1,5 @@ { "variables": { - "commit_url": "{{env `COMMIT_URL`}}", "client_id": "{{env `ARM_CLIENT_ID`}}", "client_secret": "{{env `ARM_CLIENT_SECRET`}}", "subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}", @@ -14,7 +13,6 @@ "virtual_network_subnet_name": "{{env `VNET_SUBNET`}}", "private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}", "image_folder": "/imagegeneration", - "commit_file": "/imagegeneration/commit.txt", "imagedata_file": "/imagegeneration/imagedata.json", "metadata_file": "/imagegeneration/metadatafile", "installer_script_folder": "/imagegeneration/installers", @@ -61,9 +59,7 @@ "type": "shell", "inline": [ "mkdir {{user `image_folder`}}", - "chmod 777 {{user `image_folder`}}", - "echo {{user `commit_url`}} > {{user `commit_file`}}", - "chmod +r {{user `commit_file`}}" + "chmod 777 {{user `image_folder`}}" ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index e4a3893d382d..cbfbcbaddcd5 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -9,7 +9,6 @@ "storage_account": "{{env `ARM_STORAGE_ACCOUNT`}}", "temp_resource_group_name": "{{env `TEMP_RESOURCE_GROUP_NAME`}}", "location": "{{env `ARM_RESOURCE_LOCATION`}}", - "ssh_password": "{{env `SSH_PASSWORD`}}", "virtual_network_name": "{{env `VNET_NAME`}}", "virtual_network_resource_group_name": "{{env `VNET_RESOURCE_GROUP`}}", "virtual_network_subnet_name": "{{env `VNET_SUBNET`}}", @@ -20,12 +19,9 @@ "root_folder": "C:", "toolset_json_path": "{{env `TEMP`}}\\toolset.json", "image_folder": "C:\\image", - "commit_file": "C:\\image\\commit.txt", "imagedata_file": "C:\\imagedata.json", - "metadata_file": "C:\\image\\metadata.txt", "helper_script_folder": "C:\\Program Files\\WindowsPowerShell\\Modules\\", "psmodules_root_folder": "C:\\Modules", - "commit_url": "LATEST", "install_user": "installer", "install_password": null, "capture_name_prefix": "packer", @@ -34,7 +30,7 @@ "github_feed_token": "{{env `GITHUB_FEED_TOKEN`}}", "announcements": "{{env `ANNOUNCEMENTS`}}" }, - "sensitive-variables": ["install_password", "ssh_password", "client_secret", "github_feed_token"], + "sensitive-variables": ["install_password", "client_secret", "github_feed_token"], "builders": [ { "name": "vhd", @@ -70,9 +66,7 @@ { "type": "powershell", "inline":[ - "New-Item -Path {{user `image_folder`}} -ItemType Directory -Force", - "Write-Output {{user `commit_url`}} > {{user `commit_file` }}", - "Write-Host (Get-Content -Path {{user `commit_file`}})" + "New-Item -Path {{user `image_folder`}} -ItemType Directory -Force" ] }, { diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index 8cd69ef8a5c9..e3eb9571e8a1 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -9,7 +9,6 @@ "storage_account": "{{env `ARM_STORAGE_ACCOUNT`}}", "temp_resource_group_name": "{{env `TEMP_RESOURCE_GROUP_NAME`}}", "location": "{{env `ARM_RESOURCE_LOCATION`}}", - "ssh_password": "{{env `SSH_PASSWORD`}}", "virtual_network_name": "{{env `VNET_NAME`}}", "virtual_network_resource_group_name": "{{env `VNET_RESOURCE_GROUP`}}", "virtual_network_subnet_name": "{{env `VNET_SUBNET`}}", @@ -20,12 +19,9 @@ "root_folder": "C:", "toolset_json_path": "{{env `TEMP`}}\\toolset.json", "image_folder": "C:\\image", - "commit_file": "C:\\image\\commit.txt", "imagedata_file": "C:\\imagedata.json", - "metadata_file": "C:\\image\\metadata.txt", "helper_script_folder": "C:\\Program Files\\WindowsPowerShell\\Modules\\", "psmodules_root_folder": "C:\\Modules", - "commit_id": "LATEST", "install_user": "installer", "install_password": null, "capture_name_prefix": "packer", @@ -34,7 +30,7 @@ "github_feed_token": "{{env `GITHUB_FEED_TOKEN`}}", "announcements": "{{env `ANNOUNCEMENTS`}}" }, - "sensitive-variables": ["install_password", "ssh_password", "client_secret", "github_feed_token"], + "sensitive-variables": ["install_password", "client_secret", "github_feed_token"], "builders": [ { "name": "vhd", @@ -70,9 +66,7 @@ { "type": "powershell", "inline":[ - "New-Item -Path {{user `image_folder`}} -ItemType Directory -Force", - "Write-Output {{user `commit_id`}} > {{user `commit_file`}}", - "Write-Host (Get-Content -Path {{user `commit_file`}})" + "New-Item -Path {{user `image_folder`}} -ItemType Directory -Force" ] }, {