Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: added test sample #14048

Draft
wants to merge 69 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
c947dda
added test sample
May 29, 2024
5b0fd2a
DeploymentScriptOutputs; comment out readme links
May 29, 2024
11e2c85
reuse readme links
May 29, 2024
b36dd72
restore readme to use blank template resources
May 29, 2024
8fe4fb2
output deployment logs
May 29, 2024
4960095
output testKey string
May 29, 2024
f8210c9
-r-n for logs
May 29, 2024
2beae75
remove azuredeploy*.json
May 29, 2024
a8f2560
Revert "remove azuredeploy*.json"
May 29, 2024
e854789
azuredeploy.json
May 29, 2024
37db971
logsStr
May 29, 2024
3f7f962
BEGIN/END
May 29, 2024
45d515f
Revert "BEGIN/END"
May 29, 2024
ed6a1c6
TEST INJECT STEP
Jun 1, 2024
ed429d3
Revert "TEST INJECT STEP"
Jun 1, 2024
3c20797
added download-artifacts
Jun 7, 2024
a342ff7
added renamed to artifacts
Jun 7, 2024
1ccedbc
run-artifacts
Jun 7, 2024
eab7ea9
run-artifact-test
Jun 7, 2024
b2b707d
min-image
Jun 7, 2024
ef56326
build min image
Jun 8, 2024
6d060ed
added prereqs
Jun 8, 2024
ad51390
removed dash from gallery name
Jun 8, 2024
daa6448
added .settings.json
Jun 9, 2024
7d47bf3
run-image-build.ps1
Jun 9, 2024
d030c12
Get-AzImageBuilderTemplate
Jun 9, 2024
283d9a8
more logging in run-image-build
Jun 9, 2024
ad3b3f2
more logging in run-image-build
Jun 9, 2024
f40e1ee
Get-AzImageBuilderTemplateRunOutput
Jun 9, 2024
9aca1b9
LastRunStatusMessage2
Jun 9, 2024
6180fe2
stagingResourceGroup
Jun 9, 2024
c3adc04
info
Jun 9, 2024
5f39986
stg
Jun 9, 2024
a603a72
| Format-List
Jun 9, 2024
6bc5fb9
'-stg'
Jun 9, 2024
560d689
fixed stagingResourceGroup
Jun 9, 2024
c44e689
-aib-stg
Jun 9, 2024
ef7b960
Revert "-aib-stg"
Jun 9, 2024
166139c
Write-Output
Jun 9, 2024
dee9ded
evert "Write-Output"
Jun 9, 2024
cae477c
ConvertTo-Json
Jun 9, 2024
50526bf
logsStorage
Jun 9, 2024
c64aa9c
logsStorage
Jun 9, 2024
1495c74
logsStorageAccountName
Jun 9, 2024
68f68a1
logsStorageRoleAssignment
Jun 9, 2024
0df6976
log before
Jun 9, 2024
4ee5300
-Permission 'Container'
Jun 9, 2024
12dc514
fixed permission
Jun 9, 2024
d49d702
file.log
Jun 9, 2024
c2b03d6
customizations log
Jun 9, 2024
6a8e78c
unique
Jun 9, 2024
27c41aa
resource-aib-staging
Jun 9, 2024
11ff2cf
added resource-aib-staging
Jun 9, 2024
e1351f6
aibImageStagingAccess
Jun 9, 2024
001b57b
deploymentScripts RG scope name
Jun 9, 2024
2fcf5b5
removed buildImageTemplateScript comment
Jun 9, 2024
b37191c
depends on aibImageStagingAccess
Jun 9, 2024
c0d5a34
customization.log
Jun 9, 2024
134b1a4
stagingStorageAccountKey
Jun 10, 2024
2deafee
use like
Jun 10, 2024
e0a7410
removed staging
Jun 10, 2024
f952d90
Standard_D8_v4
Jun 10, 2024
7fd488c
last lines
Jun 10, 2024
f56bafb
comment out last lines
Jun 10, 2024
4a2f3a0
renamed to get-customizations-log.ps1
Jun 10, 2024
96f0475
renamed to get-customizations-log.ps1
Jun 10, 2024
02e3f8c
getCustomizationsLog
Jun 10, 2024
40e6eca
Merge remote-tracking branch 'origin/master' into test-infra
Jun 24, 2024
8655efa
test a failure
Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions quickstarts/microsoft.devcenter/devbox-test-image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
description: Dev Box image quick test sample.
page_type: sample
products:
- azure
- azure-resource-manager
urlFragment: dev-box-image-quick-test
languages:
- json
- bicep
---
# Blank Template

![Azure Public Test Date](https://azurequickstartsservice.blob.core.windows.net/badges/100-blank-template/PublicLastTestDate.svg)
![Azure Public Test Result](https://azurequickstartsservice.blob.core.windows.net/badges/100-blank-template/PublicDeployment.svg)

![Azure US Gov Last Test Date](https://azurequickstartsservice.blob.core.windows.net/badges/100-blank-template/FairfaxLastTestDate.svg)
![Azure US Gov Last Test Result](https://azurequickstartsservice.blob.core.windows.net/badges/100-blank-template/FairfaxDeployment.svg)

![Best Practice Check](https://azurequickstartsservice.blob.core.windows.net/badges/100-blank-template/BestPracticeResult.svg)
![Cred Scan Check](https://azurequickstartsservice.blob.core.windows.net/badges/100-blank-template/CredScanResult.svg)

![Bicep Version](https://azurequickstartsservice.blob.core.windows.net/badges/100-blank-template/BicepVersion.svg)

[![Deploy To Azure](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/deploytoazure.svg?sanitize=true)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F100-blank-template%2Fazuredeploy.json)
[![Deploy To Azure US Gov](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/deploytoazuregov.svg?sanitize=true)](https://portal.azure.us/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F100-blank-template%2Fazuredeploy.json)
[![Visualize](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/visualizebutton.svg?sanitize=true)](http://armviz.io/#/?load=https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F100-blank-template%2Fazuredeploy.json)

`Tags: empty, blank`
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"builderIdentity": {
"value": "GET-PREREQ-builderIdentityId"
},
"imageIdentity": {
"value": "GET-PREREQ-imageIdentityId"
},
"galleryName": {
"value": "GET-PREREQ-galleryName"
},
"galleryResourceGroup": {
"value": "GET-PREREQ-galleryResourceGroup"
},
"gallerySubscriptionId": {
"value": "GET-PREREQ-gallerySubscriptionId"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
param location string = resourceGroup().location
param imageName string
param builderIdentity string
param imageIdentity string
param galleryName string
param galleryResourceGroup string = resourceGroup().name
param gallerySubscriptionId string = subscription().subscriptionId
param revision string = '${utcNow('yyyy-MM-dd-HH-mm-ss')}Z'

module config '../modules/artifacts-config.bicep' = {
name: 'config-${uniqueString(deployment().name, resourceGroup().name)}'
params: {
imageBuildProfile: {}
createSeparateSourcesDrive: false
}
}

module publishProfile '../modules/publish-profile.bicep' = {
name: 'publishProfile-${uniqueString(deployment().name, resourceGroup().name)}'
params: {
location: location
imageName: imageName
galleryName: galleryName
galleryResourceGroup: galleryResourceGroup
gallerySubscriptionId: gallerySubscriptionId
imageGalleries: []
targetRegions: []
imagePublishingProfile: {}
}
}

var artifacts = [
{
name: 'windows-setenvvar'
parameters: {
Variable: 'BUILT_WITH_AIB'
Value: 'true'
PrintValue: 'true'
}
}
]

module aibImage '../modules/resource-aib.bicep' = {
name: 'aibImage-${uniqueString(deployment().name, resourceGroup().name)}'
params: {
imageName: imageName
location: location
builderIdentity: builderIdentity
imageIdentity: imageIdentity
baseImage: config.outputs.baseImageFull
buildProfile: config.outputs.imageBuildProfile
artifacts: artifacts
publishingProfile: publishProfile.outputs.publishingProfile
revision: revision
}
}

output imageBuildLog string = aibImage.outputs.imageBuildLog
output stagingResourceGroupName string = aibImage.outputs.stagingResourceGroupName
98 changes: 98 additions & 0 deletions quickstarts/microsoft.devcenter/devbox-test-image/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
param location string = resourceGroup().location
param builderIdentity string
param imageIdentity string
param galleryName string
param galleryResourceGroup string = resourceGroup().name
param gallerySubscriptionId string = subscription().subscriptionId

// module image 'images/minimal.bicep' = {
// name: 'minimal'
// params: {
// location: location
// imageName: 'minimal'
// builderIdentity: builderIdentity
// imageIdentity: imageIdentity
// galleryName: galleryName
// galleryResourceGroup: galleryResourceGroup
// gallerySubscriptionId: gallerySubscriptionId
// }
// }

// module getCustomizationsLog 'modules/customizations-log.bicep' = {
// name: 'get-customizations-log-${uniqueString(deployment().name, resourceGroup().name)}'
// params: {
// location: location
// builderIdentity: builderIdentity
// imageBuildStagingResourceGroupName: image.outputs.stagingResourceGroupName
// }
// }

// output stagingResourceGroupName string = image.outputs.stagingResourceGroupName
// output imageBuildLog string = image.outputs.imageBuildLog
// output getCustomizationsLog string = getCustomizationsLog.outputs.copyCustomizationsLogScriptResult

param guidId string = newGuid()

resource deploymentScriptSuccess 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'test-deployment-script-success'
location: location
kind: 'AzurePowerShell'
properties: {
forceUpdateTag: guidId
azPowerShellVersion: '9.7'
scriptContent: '''
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest

Write-Host 'Writing to Host: TEST SUCCESS'
Write-Output 'Writing to Output: TEST SUCCESS'

$PSVersionTable

$DeploymentScriptOutputs = @{}
$DeploymentScriptOutputs['testKey'] = 'test key value'

Start-Sleep -Seconds 15
'''
cleanupPreference: 'OnSuccess'
retentionInterval: 'PT1H'
}
}

resource successLogs 'Microsoft.Resources/deploymentScripts/logs@2020-10-01' existing = {
parent: deploymentScriptSuccess
name: 'default'
}

resource deploymentScriptFailure 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'test-deployment-script-failure'
location: location
kind: 'AzurePowerShell'
dependsOn: [deploymentScriptSuccess]
properties: {
forceUpdateTag: guidId
azPowerShellVersion: '9.7'
scriptContent: '''
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest

Write-Host 'Writing to Host: TEST FAILURE'
Write-Output 'Writing to Output: TEST FAILURE'
Start-Sleep -Seconds 15

Write-Error '!!! TESTING FAILURE'

'''
cleanupPreference: 'OnSuccess'
retentionInterval: 'PT1H'
}
}

resource failureLogs 'Microsoft.Resources/deploymentScripts/logs@2020-10-01' existing = {
parent: deploymentScriptFailure
name: 'default'
}

output successLlogs string = successLogs.properties.log
output testKey string = deploymentScriptSuccess.properties.outputs.testKey
output failureLogs string = failureLogs.properties.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://aka.ms/azure-quickstart-templates-metadata-schema#",
"type": "QuickStart",
"itemDisplayName": "Dev Box image quick test",
"description": "Dev Box image quick test sample",
"summary": "Use for quick testing of Dev Box image creation quick testing.",
"githubUsername": "dmgonch",
"dateUpdated": "2024-05-29"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
param imageBuildProfile object
param createSeparateSourcesDrive bool

// Always use the upper case letter because this is how it shows up in paths when Windows file system is enumerated.
// Some case-sensitive tools care about the drive latter case even on Windows (for example git.exe when looking for safe.directory match)
param ntfsDriveRoot string = 'C:\\'
param sourcesDriveRoot string = createSeparateSourcesDrive ? 'Q:\\' : ntfsDriveRoot

var sourcesDirWithoutDriveLetter = 'src'
var sourcesDir = '${sourcesDriveRoot}${sourcesDirWithoutDriveLetter}'

var shortcutDriveRoot = sourcesDriveRoot

output ntfsDriveRoot string = ntfsDriveRoot
output sourcesDriveRoot string = sourcesDriveRoot
output shortcutDriveRoot string = shortcutDriveRoot

output sourcesDirWithoutDriveLetter string = sourcesDirWithoutDriveLetter

output defenderExclusionPathList string = sourcesDir

output ntfsSourcesDirExclusionPath string = '${ntfsDriveRoot}${sourcesDirWithoutDriveLetter}'

// Location for tools and caches redirected from various places under %USERPROFILE% so they can be used by the end user.
output toolsRoot string = '${sourcesDriveRoot}.tools'

output baseImageFull string = '/MicrosoftVisualStudio/visualstudioplustools/vs-2022-ent-general-win11-m365-gen2/latest'

var defaultImageBuildProfile = {
diskSize: 512
}

output imageBuildProfile object = union(defaultImageBuildProfile, imageBuildProfile)
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
param guidId string = newGuid()
param location string = resourceGroup().location
param builderIdentity string
param imageBuildStagingResourceGroupName string

var builderIdentityParts = split(builderIdentity, '/')
var builderIdentitySubscription = builderIdentityParts[2]
var builderIdentityResourceGroup = builderIdentityParts[4]
var builderIdentityName = last(builderIdentityParts)

resource builderIdentityResource 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
name: builderIdentityName
scope: resourceGroup(builderIdentitySubscription, builderIdentityResourceGroup)
}

// Get unique suffix from the builder identity id that is in the format of identity-builder-<uniqueSuffix>
var uniqueSuffix = split(builderIdentityName, '-')[2]

resource logsStorage 'Microsoft.Storage/storageAccounts@2023-04-01' = {
name: 'logs${uniqueSuffix}'
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
minimumTlsVersion: 'TLS1_2'
allowBlobPublicAccess: true
supportsHttpsTrafficOnly: true
publicNetworkAccess: 'Enabled'
}
}

var storageBlobDataContributorRoleDefinitionId = resourceId(
'Microsoft.Authorization/roleDefinitions',
'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
)

resource logsStorageRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(builderIdentity, storageBlobDataContributorRoleDefinitionId, resourceGroup().id, subscription().id)
scope: logsStorage
properties: {
principalId: builderIdentityResource.properties.principalId
principalType: 'ServicePrincipal'
roleDefinitionId: storageBlobDataContributorRoleDefinitionId
}
}

resource copyCustomizationsLogScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'copy-customizations-log-script-${uniqueString(resourceGroup().name)}'
location: location
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${builderIdentity}': {}
}
}
dependsOn: [
logsStorageRoleAssignment
]
properties: {
forceUpdateTag: guidId
azPowerShellVersion: '9.7'
environmentVariables: [
{
name: 'imageBuildStagingResourceGroupName'
value: imageBuildStagingResourceGroupName
}
{
name: 'logsStorageAccountName'
value: logsStorage.name
}
]
scriptContent: loadTextContent('../tools/get-customizations-log.ps1')
cleanupPreference: 'OnSuccess'
retentionInterval: 'PT1H'
}
}

resource logs 'Microsoft.Resources/deploymentScripts/logs@2020-10-01' existing = {
parent: copyCustomizationsLogScript
name: 'default'
}

output copyCustomizationsLogScriptResult string = logs.properties.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
param imageName string
param location string = resourceGroup().location
param imageGalleries array = []

// Get resource IDs for Compute Gallery VM Image Defintions
module modules 'publish-gallery.bicep' = [for (imageGalleryItem, i) in imageGalleries: {
name: 'publish-gallery-${i}-${uniqueString(deployment().name, resourceGroup().name)}'
scope: resourceGroup(imageGalleryItem.gallerySubscriptionId, imageGalleryItem.galleryResourceGroup)
params: {
galleryName: imageGalleryItem.galleryName
imageName: imageName
location: location
}
}]

output galleryIds array = [for i in range(0, length(imageGalleries)): {
Id: modules[i].outputs.computeGalleryId
}]
Loading
Loading