Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSehr committed Feb 27, 2022
0 parents commit 5bc3527
Show file tree
Hide file tree
Showing 197 changed files with 14,051 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
parameters:
- name: environment
default:
- name: deploymentsToPerform
default:
- name: serviceConnection
default:
- name: waitForscalesetBuild
default:

jobs:
- deployment: deploy_job
displayName: Deploy Resources
environment: ${{ parameters.environment }}
timeoutInMinutes: 120
pool:
vmImage: '$(vmImage_${{ parameters.environment }})'
name: '$(poolName_${{ parameters.environment }})'
strategy:
runOnce:
deploy:
steps:
- checkout: self
# [Deployment] task(s)
#---------------------
- task: AzurePowerShell@4
displayName: 'Deploy [scaleset.deploy.bicep] via service connection [$(serviceConnection_${{ parameters.environment }})]'
name: deploy_task
inputs:
azureSubscription: '$(serviceConnection_${{ parameters.environment }})'
ScriptType: InlineScript
inline: |
# Load used functions
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'New-ModuleDeployment.ps1')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'Test-TemplateWithParameterFile.ps1')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'Set-CustomParameter')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(orchestrationFunctionsPath)' 'image' 'Select-Image.ps1')
# Check the provide image
$parameterFilePath = Join-Path '$(parametersPath)' '${{ parameters.environment }}.scaleset.parameters.json'
$parameterFileContent = ConvertFrom-Json (Get-Content $parameterFilePath -Raw) -AsHashTable
if($imageVersionReference = Select-Image -imageReference $parameterFileContent.parameters.vmssParam.value.imageReference -Verbose) {
$customValueMap += @{
path = 'vmssParam.value.imageReference.id'
value = $imageVersionReference
}
}
# Overwrite parameter file if necessary
if($customValueMap.Count -gt 0) {
$overwriteInputObject = @{
parameterFilePath = $parameterFilePath
valueMap = $customValueMap
}
Set-CustomParameter @overwriteInputObject
}
# ----------------- #
# INVOKE DEPLOYMENT #
# ----------------- #
$functionInput = @{
templateFilePath = Join-Path '$(templatesPath)' 'scaleset.deploy.bicep'
parameterFilePath = $parameterFilePath
location = '$(location)'
subscriptionId = (Get-AzContext).Subscription.Id
}
# Inject control parmaeters from pipeline
$functionInput['additionalParameters'] = @{
deploymentsToPerform = '${{ parameters.deploymentsToPerform }}'
}
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
# Validate deployment
Test-TemplateWithParameterFile @functionInput
# Invoke deployment
New-ModuleDeployment @functionInput -Verbose
errorActionPreference: stop
azurePowerShellVersion: LatestVersion
50 changes: 50 additions & 0 deletions .azuredevops/azureDevOpsScaleSet/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: 'ScaleSet Deployment'

parameters:
- name: startEnvironment
displayName: Environment to start from
type: string
default: sbx
values:
- sbx
- dev
- prd
- name: deploymentsToPerform
displayName: Scope of deployment
type: string
default: Only Scale Set
values:
- All
- Only Scale Set
variables:
- template: variables.yml

trigger: none

stages:
- stage: SBX_Deployments
displayName: Deploy to SBX
condition: and(succeeded(), eq('${{ parameters.startEnvironment }}', 'sbx'))
jobs:
- template: .templates/pipeline.scaleset.jobs.yml
parameters:
environment: 'sbx'
deploymentsToPerform: '${{ parameters.deploymentsToPerform }}'

- stage: DEV_Deployments
displayName: Deploy to DEV
condition: and(succeeded(), in('${{ parameters.startEnvironment }}', 'sbx', 'dev'))
jobs:
- template: .templates/pipeline.scaleset.jobs.yml
parameters:
environment: 'dev'
deploymentsToPerform: '${{ parameters.deploymentsToPerform }}'

- stage: PRD_Deployments
displayName: Deploy to PRD
condition: and(succeeded(),in('${{ parameters.startEnvironment }}', 'sbx', 'dev', 'prd'))
jobs:
- template: .templates/pipeline.scaleset.jobs.yml
parameters:
environment: 'prd'
deploymentsToPerform: '${{ parameters.deploymentsToPerform }}'
34 changes: 34 additions & 0 deletions .azuredevops/azureDevOpsScaleSet/variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#######################################################################
## NOTE ##
## ------------------------------------------------------------------##
## - These variables are used to configure the pipeline and provide ##
## variables to pipeline scripts ##
## - Parameters used for resource deployments are located in the ##
## parameter files in the '.\Parameters' folder ##
#######################################################################

variables:
#############
## GENERAL ##
#############
#region shared
vmImage_sbx: 'ubuntu-latest' # Use this for microsoft-hosted agents
vmImage_dev: 'ubuntu-latest' # Use this for microsoft-hosted agents
vmImage_prd: 'ubuntu-latest' # Use this for microsoft-hosted agents

poolName_sbx: '' # Use this for self-hosted agents
poolName_dev: '' # Use this for self-hosted agents
poolName_prd: '' # Use this for self-hosted agents

serviceConnection_sbx: 'CARML-CSU-Tenant-Connection'
serviceConnection_dev: 'CARML-CSU-Tenant-Connection'
serviceConnection_prd: 'CARML-CSU-Tenant-Connection'
#endregion

#region specific
templatesPath: 'constructs/azureDevOpsScaleSet/templates'
parametersPath: 'constructs/azureDevOpsScaleSet/parameters'
orchestrationFunctionsPath: 'constructs/azureDevOpsScaleSet/scripts'
sharedOrchestrationFunctionsPath: 'sharedScripts'
location: westeurope
#endregion
216 changes: 216 additions & 0 deletions .azuredevops/azureImageBuilder/.templates/pipeline.image.jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
parameters:
- name: environment
default:
- name: deploymentsToPerform
default:
- name: waitForImageBuild
default:
- name: removeImageTemplateResources
default: true

jobs:
- deployment: cleanup_job
displayName: Remove previous Image Template resources
environment: ${{ parameters.environment }}
timeoutInMinutes: 120
condition: |
and(
succeeded(),
eq('${{ parameters.removeImageTemplateResources }}', 'true')
)
pool:
vmImage: '$(vmImage_${{ parameters.environment }})'
name: '$(poolName_${{ parameters.environment }})'
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: AzurePowerShell@4
displayName: 'Remove previous image template resources'
name: Remove_ImageTemplates_Task
inputs:
azureSubscription: '$(serviceConnection_${{ parameters.environment }})'
ScriptType: InlineScript
inline: |
Write-Verbose "Load function" -Verbose
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(orchestrationFunctionsPath)' 'image' 'Remove-ImageTemplate.ps1')
$parameterFilePath = Join-Path '$(parametersPath)' '${{ parameters.environment }}.imageTemplate.parameters.json'
$parameters = (ConvertFrom-Json (Get-Content -Path $parameterFilePath -Raw)).parameters
$functionInput = @{
resourcegroupName = $parameters.rgParam.value.name
imageTemplateName = $parameters.itParam.value.name
}
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
Remove-ImageTemplate @functionInput -Verbose
errorActionPreference: stop
azurePowerShellVersion: LatestVersion
- deployment: deploy_job
displayName: Deploy Resources
environment: ${{ parameters.environment }}
condition: in('${{ parameters.deploymentsToPerform }}', 'All', 'Only infrastructure', 'Only storage & image', 'Only image', '')
timeoutInMinutes: 120
pool:
vmImage: '$(vmImage_${{ parameters.environment }})'
name: '$(poolName_${{ parameters.environment }})'
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: AzurePowerShell@4
displayName: 'Deploy [imageInfra.deploy.bicep] via service connection [$(serviceConnection_${{ parameters.environment }})]'
condition: |
and(
succeeded(),
in('${{ parameters.deploymentsToPerform }}', 'All', 'Only infrastructure', 'Only storage & image')
)
inputs:
azureSubscription: '$(serviceConnection_${{ parameters.environment }})'
ScriptType: InlineScript
inline: |
# Load used functions
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'New-ModuleDeployment.ps1')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'Test-TemplateWithParameterFile')
# ----------------- #
# INVOKE DEPLOYMENT #
# ----------------- #
$functionInput = @{
templateFilePath = Join-Path '$(templatesPath)' 'imageInfra.deploy.bicep'
parameterFilePath = Join-Path '$(parametersPath)' '${{ parameters.environment }}.imageInfra.parameters.json'
location = '$(location)'
subscriptionId = (Get-AzContext).Subscription.Id
}
# Inject control parmaeters from pipeline
$functionInput['additionalParameters'] = @{
deploymentsToPerform = '${{ parameters.deploymentsToPerform }}'
}
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
# Validate deployment
Test-TemplateWithParameterFile @functionInput
# Invoke deployment
New-ModuleDeployment @functionInput -Verbose
errorActionPreference: stop
azurePowerShellVersion: LatestVersion

- task: AzurePowerShell@4
displayName: "Trigger Storage Account post-deployment"
condition: |
and(
succeeded(),
in('${{ parameters.deploymentsToPerform }}', 'All', 'Only infrastructure', 'Only storage & image')
)
inputs:
azureSubscription: '$(serviceConnection_${{ parameters.environment }})'
ScriptType: InlineScript
inline: |
Write-Verbose "Load function" -Verbose
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(orchestrationFunctionsPath)' 'storage' 'Invoke-StorageAccountPostDeployment.ps1')
$parameterFilePath = Join-Path '$(parametersPath)' '${{ parameters.environment }}.imageInfra.parameters.json'
$parameters = (ConvertFrom-Json (Get-Content -Path $parameterFilePath -Raw)).parameters
$functionInput = @{
storageAccountName = $parameters.saParam.value.name
}
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
Invoke-StorageAccountPostDeployment @functionInput -Verbose
errorActionPreference: stop
azurePowerShellVersion: LatestVersion

- task: AzurePowerShell@4
displayName: 'Deploy [imageTemplate.deploy.bicep] via service connection [$(serviceConnection_${{ parameters.environment }})]'
condition: |
and(
succeeded(),
in('${{ parameters.deploymentsToPerform }}', 'All', 'Only storage & image', 'Only image')
)
inputs:
azureSubscription: '$(serviceConnection_${{ parameters.environment }})'
ScriptType: InlineScript
inline: |
# Load used functions
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'New-ModuleDeployment.ps1')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'Test-TemplateWithParameterFile')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(orchestrationFunctionsPath)' 'storage' 'Set-SasKeysInFile.ps1')
# ----------------- #
# INVOKE DEPLOYMENT #
# ----------------- #
$parameterFilePath = Join-Path '$(parametersPath)' '${{ parameters.environment }}.imageTemplate.parameters.json'
$functionInput = @{
templateFilePath = Join-Path '$(templatesPath)' 'imageTemplate.deploy.bicep'
parameterFilePath = $parameterFilePath
location = '$(location)'
subscriptionId = (Get-AzContext).Subscription.Id
}
# Inject control parmaeters from pipeline
$functionInput['additionalParameters'] = @{
deploymentsToPerform = '${{ parameters.deploymentsToPerform }}'
}
# Set SAS keys for storage references
Set-SasKeysInFile -filePath $parameterFilePath -Verbose
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
# Validate deployment
Test-TemplateWithParameterFile @functionInput
# Invoke deployment
$res = New-ModuleDeployment @functionInput -Verbose
Write-Verbose ($res | ConvertTo-Json | Out-String) -Verbose
foreach ($outputKey in $res.deploymentOutput.Keys) {
Write-Output ('##vso[task.setvariable variable={0}]{1}' -f $outputKey, $res.deploymentOutput[$outputKey].Value)
}
errorActionPreference: stop
azurePowerShellVersion: LatestVersion

- task: AzurePowerShell@4
displayName: "Wait for image build"
condition: |
and(
succeeded(),
eq('${{ parameters.waitForImageBuild }}', 'true'),
in('${{ parameters.deploymentsToPerform }}', 'All', 'Only infrastructure', 'Only storage & image', 'Only image')
)
name: PostDeploy_ImageTemplates_Task
inputs:
azureSubscription: '$(serviceConnection_${{ parameters.environment }})'
ScriptType: InlineScript
inline: |
Write-Verbose "Load function" -Verbose
. '$(Build.Repository.LocalPath)/$(orchestrationFunctionsPath)/image/Wait-ForImageBuild.ps1'
$parameterFilePath = Join-Path '$(parametersPath)' '${{ parameters.environment }}.imageTemplate.parameters.json'
$parameters = (ConvertFrom-Json (Get-Content -Path $parameterFilePath -Raw)).parameters
$functionInput = @{
ResourceGroupName = $parameters.rgParam.value.name
ImageTemplateName = $env:IMAGETEMPATENAME # template deployment output
}
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
Wait-ForImageBuild @functionInput -Verbose
errorActionPreference: stop
azurePowerShellVersion: LatestVersion
Loading

0 comments on commit 5bc3527

Please sign in to comment.