mirror of
https://github.com/actions/runner-images.git
synced 2025-12-11 11:37:00 +00:00
Add current commit into logs for custom builds (#1419)
* Show latest commit for custom repos * Remove unused variables from templates * Add Get-LatestCommit function * Fix in synopsis * Remove SSH_Password variables from Windows Images * Rename download-customrepo * Fix in synopsis
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
Function CreateAzureVMFromPackerTemplate {
|
Function CreateAzureVMFromPackerTemplate {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.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
|
.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
|
.PARAMETER SubscriptionId
|
||||||
The Azure subscription Id where resources will be created.
|
The Azure subscription Id where resources will be created.
|
||||||
|
|||||||
@@ -39,6 +39,16 @@ Function Get-PackerTemplatePath {
|
|||||||
return $RepositoryRoot + $relativePath;
|
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 {
|
Function GenerateResourcesAndImage {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
@@ -170,6 +180,8 @@ Function GenerateResourcesAndImage {
|
|||||||
$tenantId = $sub.TenantId
|
$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`"", ""
|
# "", "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 `
|
packer.exe build -on-error=ask `
|
||||||
-var "client_id=$($spClientId)" `
|
-var "client_id=$($spClientId)" `
|
||||||
-var "client_secret=$($ServicePrincipalClientSecret)" `
|
-var "client_secret=$($ServicePrincipalClientSecret)" `
|
||||||
|
|||||||
@@ -17,13 +17,10 @@ jobs:
|
|||||||
displayName: 'Download custom repository'
|
displayName: 'Download custom repository'
|
||||||
condition: and(ne(variables['CUSTOM_REPOSITORY_URL'], ''), ne(variables['CUSTOM_REPOSITORY_BRANCH'], ''))
|
condition: and(ne(variables['CUSTOM_REPOSITORY_URL'], ''), ne(variables['CUSTOM_REPOSITORY_BRANCH'], ''))
|
||||||
inputs:
|
inputs:
|
||||||
targetType: 'inline'
|
targetType: 'filePath'
|
||||||
script: |
|
filePath: ./images.CI/download-repo.ps1
|
||||||
Write-Host "Clean up default repository"
|
arguments: -RepoUrl $(CUSTOM_REPOSITORY_URL) `
|
||||||
Remove-Item -path './*' -Recurse -Force
|
-RepoBranch $(CUSTOM_REPOSITORY_BRANCH)
|
||||||
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
|
|
||||||
|
|
||||||
- task: PowerShell@2
|
- task: PowerShell@2
|
||||||
displayName: 'Build VM'
|
displayName: 'Build VM'
|
||||||
|
|||||||
14
images.CI/download-repo.ps1
Normal file
14
images.CI/download-repo.ps1
Normal file
@@ -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
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"variables": {
|
"variables": {
|
||||||
"commit_url": "{{env `COMMIT_URL`}}",
|
|
||||||
"client_id": "{{env `ARM_CLIENT_ID`}}",
|
"client_id": "{{env `ARM_CLIENT_ID`}}",
|
||||||
"client_secret": "{{env `ARM_CLIENT_SECRET`}}",
|
"client_secret": "{{env `ARM_CLIENT_SECRET`}}",
|
||||||
"subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
|
"subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
|
||||||
@@ -14,7 +13,6 @@
|
|||||||
"virtual_network_subnet_name": "{{env `VNET_SUBNET`}}",
|
"virtual_network_subnet_name": "{{env `VNET_SUBNET`}}",
|
||||||
"private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}",
|
"private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}",
|
||||||
"image_folder": "/imagegeneration",
|
"image_folder": "/imagegeneration",
|
||||||
"commit_file": "/imagegeneration/commit.txt",
|
|
||||||
"imagedata_file": "/imagegeneration/imagedata.json",
|
"imagedata_file": "/imagegeneration/imagedata.json",
|
||||||
"metadata_file": "/imagegeneration/metadatafile",
|
"metadata_file": "/imagegeneration/metadatafile",
|
||||||
"installer_script_folder": "/imagegeneration/installers",
|
"installer_script_folder": "/imagegeneration/installers",
|
||||||
@@ -59,9 +57,7 @@
|
|||||||
"type": "shell",
|
"type": "shell",
|
||||||
"inline": [
|
"inline": [
|
||||||
"mkdir {{user `image_folder`}}",
|
"mkdir {{user `image_folder`}}",
|
||||||
"chmod 777 {{user `image_folder`}}",
|
"chmod 777 {{user `image_folder`}}"
|
||||||
"echo {{user `commit_url`}} > {{user `commit_file`}}",
|
|
||||||
"chmod +r {{user `commit_file`}}"
|
|
||||||
],
|
],
|
||||||
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'"
|
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"variables": {
|
"variables": {
|
||||||
"commit_url": "{{env `COMMIT_URL`}}",
|
|
||||||
"client_id": "{{env `ARM_CLIENT_ID`}}",
|
"client_id": "{{env `ARM_CLIENT_ID`}}",
|
||||||
"client_secret": "{{env `ARM_CLIENT_SECRET`}}",
|
"client_secret": "{{env `ARM_CLIENT_SECRET`}}",
|
||||||
"subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
|
"subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
|
||||||
@@ -14,7 +13,6 @@
|
|||||||
"virtual_network_subnet_name": "{{env `VNET_SUBNET`}}",
|
"virtual_network_subnet_name": "{{env `VNET_SUBNET`}}",
|
||||||
"private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}",
|
"private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}",
|
||||||
"image_folder": "/imagegeneration",
|
"image_folder": "/imagegeneration",
|
||||||
"commit_file": "/imagegeneration/commit.txt",
|
|
||||||
"imagedata_file": "/imagegeneration/imagedata.json",
|
"imagedata_file": "/imagegeneration/imagedata.json",
|
||||||
"metadata_file": "/imagegeneration/metadatafile",
|
"metadata_file": "/imagegeneration/metadatafile",
|
||||||
"installer_script_folder": "/imagegeneration/installers",
|
"installer_script_folder": "/imagegeneration/installers",
|
||||||
@@ -59,9 +57,7 @@
|
|||||||
"type": "shell",
|
"type": "shell",
|
||||||
"inline": [
|
"inline": [
|
||||||
"mkdir {{user `image_folder`}}",
|
"mkdir {{user `image_folder`}}",
|
||||||
"chmod 777 {{user `image_folder`}}",
|
"chmod 777 {{user `image_folder`}}"
|
||||||
"echo {{user `commit_url`}} > {{user `commit_file`}}",
|
|
||||||
"chmod +r {{user `commit_file`}}"
|
|
||||||
],
|
],
|
||||||
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'"
|
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"variables": {
|
"variables": {
|
||||||
"commit_url": "{{env `COMMIT_URL`}}",
|
|
||||||
"client_id": "{{env `ARM_CLIENT_ID`}}",
|
"client_id": "{{env `ARM_CLIENT_ID`}}",
|
||||||
"client_secret": "{{env `ARM_CLIENT_SECRET`}}",
|
"client_secret": "{{env `ARM_CLIENT_SECRET`}}",
|
||||||
"subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
|
"subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
|
||||||
@@ -14,7 +13,6 @@
|
|||||||
"virtual_network_subnet_name": "{{env `VNET_SUBNET`}}",
|
"virtual_network_subnet_name": "{{env `VNET_SUBNET`}}",
|
||||||
"private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}",
|
"private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}",
|
||||||
"image_folder": "/imagegeneration",
|
"image_folder": "/imagegeneration",
|
||||||
"commit_file": "/imagegeneration/commit.txt",
|
|
||||||
"imagedata_file": "/imagegeneration/imagedata.json",
|
"imagedata_file": "/imagegeneration/imagedata.json",
|
||||||
"metadata_file": "/imagegeneration/metadatafile",
|
"metadata_file": "/imagegeneration/metadatafile",
|
||||||
"installer_script_folder": "/imagegeneration/installers",
|
"installer_script_folder": "/imagegeneration/installers",
|
||||||
@@ -61,9 +59,7 @@
|
|||||||
"type": "shell",
|
"type": "shell",
|
||||||
"inline": [
|
"inline": [
|
||||||
"mkdir {{user `image_folder`}}",
|
"mkdir {{user `image_folder`}}",
|
||||||
"chmod 777 {{user `image_folder`}}",
|
"chmod 777 {{user `image_folder`}}"
|
||||||
"echo {{user `commit_url`}} > {{user `commit_file`}}",
|
|
||||||
"chmod +r {{user `commit_file`}}"
|
|
||||||
],
|
],
|
||||||
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'"
|
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
"storage_account": "{{env `ARM_STORAGE_ACCOUNT`}}",
|
"storage_account": "{{env `ARM_STORAGE_ACCOUNT`}}",
|
||||||
"temp_resource_group_name": "{{env `TEMP_RESOURCE_GROUP_NAME`}}",
|
"temp_resource_group_name": "{{env `TEMP_RESOURCE_GROUP_NAME`}}",
|
||||||
"location": "{{env `ARM_RESOURCE_LOCATION`}}",
|
"location": "{{env `ARM_RESOURCE_LOCATION`}}",
|
||||||
"ssh_password": "{{env `SSH_PASSWORD`}}",
|
|
||||||
"virtual_network_name": "{{env `VNET_NAME`}}",
|
"virtual_network_name": "{{env `VNET_NAME`}}",
|
||||||
"virtual_network_resource_group_name": "{{env `VNET_RESOURCE_GROUP`}}",
|
"virtual_network_resource_group_name": "{{env `VNET_RESOURCE_GROUP`}}",
|
||||||
"virtual_network_subnet_name": "{{env `VNET_SUBNET`}}",
|
"virtual_network_subnet_name": "{{env `VNET_SUBNET`}}",
|
||||||
@@ -20,12 +19,9 @@
|
|||||||
"root_folder": "C:",
|
"root_folder": "C:",
|
||||||
"toolset_json_path": "{{env `TEMP`}}\\toolset.json",
|
"toolset_json_path": "{{env `TEMP`}}\\toolset.json",
|
||||||
"image_folder": "C:\\image",
|
"image_folder": "C:\\image",
|
||||||
"commit_file": "C:\\image\\commit.txt",
|
|
||||||
"imagedata_file": "C:\\imagedata.json",
|
"imagedata_file": "C:\\imagedata.json",
|
||||||
"metadata_file": "C:\\image\\metadata.txt",
|
|
||||||
"helper_script_folder": "C:\\Program Files\\WindowsPowerShell\\Modules\\",
|
"helper_script_folder": "C:\\Program Files\\WindowsPowerShell\\Modules\\",
|
||||||
"psmodules_root_folder": "C:\\Modules",
|
"psmodules_root_folder": "C:\\Modules",
|
||||||
"commit_url": "LATEST",
|
|
||||||
"install_user": "installer",
|
"install_user": "installer",
|
||||||
"install_password": null,
|
"install_password": null,
|
||||||
"capture_name_prefix": "packer",
|
"capture_name_prefix": "packer",
|
||||||
@@ -34,7 +30,7 @@
|
|||||||
"github_feed_token": "{{env `GITHUB_FEED_TOKEN`}}",
|
"github_feed_token": "{{env `GITHUB_FEED_TOKEN`}}",
|
||||||
"announcements": "{{env `ANNOUNCEMENTS`}}"
|
"announcements": "{{env `ANNOUNCEMENTS`}}"
|
||||||
},
|
},
|
||||||
"sensitive-variables": ["install_password", "ssh_password", "client_secret", "github_feed_token"],
|
"sensitive-variables": ["install_password", "client_secret", "github_feed_token"],
|
||||||
"builders": [
|
"builders": [
|
||||||
{
|
{
|
||||||
"name": "vhd",
|
"name": "vhd",
|
||||||
@@ -70,9 +66,7 @@
|
|||||||
{
|
{
|
||||||
"type": "powershell",
|
"type": "powershell",
|
||||||
"inline":[
|
"inline":[
|
||||||
"New-Item -Path {{user `image_folder`}} -ItemType Directory -Force",
|
"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`}})"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
"storage_account": "{{env `ARM_STORAGE_ACCOUNT`}}",
|
"storage_account": "{{env `ARM_STORAGE_ACCOUNT`}}",
|
||||||
"temp_resource_group_name": "{{env `TEMP_RESOURCE_GROUP_NAME`}}",
|
"temp_resource_group_name": "{{env `TEMP_RESOURCE_GROUP_NAME`}}",
|
||||||
"location": "{{env `ARM_RESOURCE_LOCATION`}}",
|
"location": "{{env `ARM_RESOURCE_LOCATION`}}",
|
||||||
"ssh_password": "{{env `SSH_PASSWORD`}}",
|
|
||||||
"virtual_network_name": "{{env `VNET_NAME`}}",
|
"virtual_network_name": "{{env `VNET_NAME`}}",
|
||||||
"virtual_network_resource_group_name": "{{env `VNET_RESOURCE_GROUP`}}",
|
"virtual_network_resource_group_name": "{{env `VNET_RESOURCE_GROUP`}}",
|
||||||
"virtual_network_subnet_name": "{{env `VNET_SUBNET`}}",
|
"virtual_network_subnet_name": "{{env `VNET_SUBNET`}}",
|
||||||
@@ -20,12 +19,9 @@
|
|||||||
"root_folder": "C:",
|
"root_folder": "C:",
|
||||||
"toolset_json_path": "{{env `TEMP`}}\\toolset.json",
|
"toolset_json_path": "{{env `TEMP`}}\\toolset.json",
|
||||||
"image_folder": "C:\\image",
|
"image_folder": "C:\\image",
|
||||||
"commit_file": "C:\\image\\commit.txt",
|
|
||||||
"imagedata_file": "C:\\imagedata.json",
|
"imagedata_file": "C:\\imagedata.json",
|
||||||
"metadata_file": "C:\\image\\metadata.txt",
|
|
||||||
"helper_script_folder": "C:\\Program Files\\WindowsPowerShell\\Modules\\",
|
"helper_script_folder": "C:\\Program Files\\WindowsPowerShell\\Modules\\",
|
||||||
"psmodules_root_folder": "C:\\Modules",
|
"psmodules_root_folder": "C:\\Modules",
|
||||||
"commit_id": "LATEST",
|
|
||||||
"install_user": "installer",
|
"install_user": "installer",
|
||||||
"install_password": null,
|
"install_password": null,
|
||||||
"capture_name_prefix": "packer",
|
"capture_name_prefix": "packer",
|
||||||
@@ -34,7 +30,7 @@
|
|||||||
"github_feed_token": "{{env `GITHUB_FEED_TOKEN`}}",
|
"github_feed_token": "{{env `GITHUB_FEED_TOKEN`}}",
|
||||||
"announcements": "{{env `ANNOUNCEMENTS`}}"
|
"announcements": "{{env `ANNOUNCEMENTS`}}"
|
||||||
},
|
},
|
||||||
"sensitive-variables": ["install_password", "ssh_password", "client_secret", "github_feed_token"],
|
"sensitive-variables": ["install_password", "client_secret", "github_feed_token"],
|
||||||
"builders": [
|
"builders": [
|
||||||
{
|
{
|
||||||
"name": "vhd",
|
"name": "vhd",
|
||||||
@@ -70,9 +66,7 @@
|
|||||||
{
|
{
|
||||||
"type": "powershell",
|
"type": "powershell",
|
||||||
"inline":[
|
"inline":[
|
||||||
"New-Item -Path {{user `image_folder`}} -ItemType Directory -Force",
|
"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`}})"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user