* working container app support

* Install Az.App in github actions

* Add callout for installation of az.app

* Edit tests for inconsistencies

* Update to one line test

* Remove comments
This commit is contained in:
Mary Sha 2023-03-30 13:17:11 -07:00 коммит произвёл GitHub
Родитель 6226a8f8e4
Коммит a8eff62505
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 267 добавлений и 0 удалений

1
.github/workflows/ci.yml поставляемый
Просмотреть файл

@ -55,6 +55,7 @@ jobs:
shell: pwsh
run: |
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
Install-Module -Name Az.App -Scope CurrentUser -Repository PSGallery -Force
Publish-Module -Path ./BenchPress.Azure -Repository LocalFeedPSRepo -Verbose
- name: Install AzBP Module from the repository
shell: pwsh

1
.github/workflows/pr-powershell.yml поставляемый
Просмотреть файл

@ -24,6 +24,7 @@ jobs:
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az -ErrorAction Stop
Install-Module Az.App -ErrorAction Stop
Install-Module Pester -ErrorAction Stop
- name: Run PowerShell Unit Tests
shell: pwsh

Просмотреть файл

@ -16,6 +16,7 @@
"Confirm-AppInsights",
"Confirm-AppServicePlan",
"Confirm-BicepFile",
"Confirm-ContainerApp",
"Confirm-ContainerRegistry",
"Confirm-CosmosDBAccount",
"Confirm-CosmosDBGremlinDatabase",

Просмотреть файл

@ -3,6 +3,7 @@ enum ResourceType{
AksCluster
AppInsights
AppServicePlan
ContainerApp
CosmosDBAccount
CosmosDBGremlinDatabase
CosmosDBMongoDBDatabase

Просмотреть файл

@ -0,0 +1,49 @@
# INLINE_SKIP
using module ./../Classes/ConfirmResult.psm1
. $PSScriptRoot/../Private/Connect-Account.ps1
# end INLINE_SKIP
function Confirm-ContainerApp {
<#
.SYNOPSIS
Confirms that a Container Application exists.
.DESCRIPTION
The Confirm-AzBPContainerApp cmdlet gets a Container Application using the specified Container Application and
Resource Group name.
.PARAMETER Name
The name of the Container Application
.PARAMETER ResourceGroupName
The name of the Resource Group
.EXAMPLE
Confirm-AzBPContainerApp -Name "benchpresstest" -ResourceGroupName "rgbenchpresstest"
.INPUTS
System.String
.OUTPUTS
ConfirmResult
#>
[CmdletBinding()]
[OutputType([ConfirmResult])]
param (
[Parameter(Mandatory=$true)]
[string]$Name,
[Parameter(Mandatory=$true)]
[string]$ResourceGroupName
)
Begin {
$ConnectResults = Connect-Account
}
Process {
$Resource = Get-AzContainerApp -ResourceGroupName $ResourceGroupName -Name $Name
[ConfirmResult]::new($Resource, $ConnectResults.AuthenticationData)
}
End { }
}

Просмотреть файл

@ -138,6 +138,9 @@ function Get-ResourceByType {
"AppServicePlan" {
return Confirm-AppServicePlan -AppServicePlanName $ResourceName -ResourceGroupName $ResourceGroupName
}
"ContainerApp" {
return Confirm-ContainerApp -ResourceGroupName $ResourceGroupName -Name $ResourceName
}
"ContainerRegistry" {
return Confirm-ContainerRegistry -Name $ResourceName -ResourceGroupName $ResourceGroupName
}

Просмотреть файл

@ -0,0 +1,23 @@
BeforeAll {
. $PSScriptRoot/../../Public/Confirm-ContainerApp.ps1
. $PSScriptRoot/../../Private/Connect-Account.ps1
Import-Module Az
}
Describe "Confirm-ContainerApp" {
Context "unit tests" -Tag "Unit" {
BeforeEach {
Mock Connect-Account{}
}
It "Calls Get-AzContainerApp" {
Mock Get-AzContainerApp{}
Confirm-ContainerApp -Name "ca" -ResourceGroupName "rgn"
Should -Invoke -CommandName "Get-AzContainerApp" -Times 1
}
}
}
AfterAll {
Remove-Module Az
}

Просмотреть файл

@ -18,6 +18,9 @@ as their testing framework and runner. To use BenchPress, have the following ins
- [PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows)
(PowerShell 7+ recommended)
- [Az PowerShell module](https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-9.3.0)
- [Az.App PowerShell module](https://learn.microsoft.com/en-us/powershell/module/az.app/?view=azps-9.5.0) for any
testing of Container Applications. Az.App is not GA yet which is why it is not included with the main Az
PowerShell module.
- [Pester](https://pester.dev/docs/introduction/installation)
- [Bicep](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/install#azure-powershell)
- [Service Principal](https://learn.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal)

Просмотреть файл

@ -0,0 +1,69 @@
BeforeAll {
Import-Module Az.InfrastructureTesting
$Script:rgName = 'rg-test'
$Script:conAppName = 'conAppBenchPressTest'
$Script:location = 'westus3'
}
Describe 'Verify Container Application' {
BeforeAll {
$Script:noContainerAppName = 'nocontainerapp'
}
It "Should contain a Container Application named $conAppName - Confirm-AzBPResource" {
$params = @{
ResourceType = "ContainerApp"
ResourceName = $conAppName
ResourceGroupName = $rgName
}
(Confirm-AzBPResource @params).Success | Should -Be $true
}
It "Should contain a Container Application with an Ingress Port of 80 - Confirm-AzBPResource" {
$params = @{
ResourceType = "ContainerApp"
ResourceName = $conAppName
ResourceGroupName = $rgName
PropertyKey = "IngressTargetPort"
PropertyValue = 80
}
(Confirm-AzBPResource @params).Success | Should -Be $true
}
It "Should contain a Container Application named $conAppName" {
(Confirm-AzBPContainerApp -ResourceGroupName $rgName -Name $conAppName).Success | Should -Be $true
}
It "Should not contain a Container Application named $noContainerAppName" {
# The '-ErrorAction SilentlyContinue' command suppresses all errors.
# In this test, it will suppress the error message when a resource cannot be found.
# Remove this field to see all errors.
$params = @{
ResourceGroupName = $rgName
Name = $noContainerAppName
ErrorAction = 'SilentlyContinue'
}
(Confirm-AzBPContainerApp @params).Success | Should -Be $false
}
It "Should contain a Container Application named $conAppName" {
Confirm-AzBPContainerApp -ResourceGroupName $rgName -Name $conAppName | Should -BeDeployed
}
It "Should contain a Container Application named $conAppName in $location" {
Confirm-AzBPContainerApp -ResourceGroupName $rgName -Name $conAppName | Should -BeInLocation $location
}
It "Should contain a Container Application named $conAppName in $rgName" {
Confirm-AzBPContainerApp -ResourceGroupName $rgName -Name $conAppName | Should -BeInResourceGroup $rgName
}
}
AfterAll {
Get-Module Az-InfrastructureTesting | Remove-Module
Get-Module BenchPress.Azure | Remove-Module
}

Просмотреть файл

@ -0,0 +1,47 @@
# How To Run ContainerApp.Tests.ps1
`ContainerApp.Tests.ps1` contains examples of using the `Confirm-AzBPContainerApp` cmdlet.
## Pre-Requisites
- Follow the [setup instructions](../README.md)
## Steps
1. Navigate to ContainerApp directory:
```Powershell
cd examples\ContainerApp\
```
1. Deploy the Container Registry to your resource group:
```Powershell
New-AzResourceGroupDeployment -ResourceGroupName "<your-resource-group-name>"`
-TemplateFile ".\containerApp.bicep"
```
1. Update `ContainerApp.Tests.ps1` variables to point to your expected resources:
- `rg-test` -> `your-resource-group-name`
- `conAppBenchPressTest` -> `your-container-application-name`
- `westus3` -> `your-resource-group-location-name`
1. If using a local copy of `Az.InfrastructureTesting`, replace `Import-Module Az.InfrastructureTesting` with
`Import-Module "../../bin/BenchPress.Azure.psd1"`. Note that the final `AfterAll` step will properly remove the module
regardless of which method is chosen to load the module.
1. Run `ContainerApp.Tests.ps1`:
```Powershell
Invoke-Pester -Path .\ContainerApp.Tests.ps1
```
1. Success!
```Powershell
Tests completed in 5.02s
Tests Passed: 7, Failed: 0, Skipped: 0 NotRun: 0
```
1. Don't forget to delete any deployed resources that are no longer needed.

Просмотреть файл

@ -0,0 +1,69 @@
param containerAppName string = 'acr${take(uniqueString(resourceGroup().id), 5)}'
param location string = resourceGroup().location
param targetPort int = 80
param containerImage string = 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: 'loganalytics${containerAppName}'
location: location
properties: {
sku: {
name: 'PerGB2018'
}
}
}
resource containerAppEnv 'Microsoft.App/managedEnvironments@2022-10-01' = {
name: 'env${containerAppName}'
location: location
sku: {
name: 'Consumption'
}
properties: {
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalytics.properties.customerId
sharedKey: logAnalytics.listKeys().primarySharedKey
}
}
}
}
resource containerApp 'Microsoft.App/containerApps@2022-10-01' = {
name: containerAppName
location: location
properties: {
managedEnvironmentId: containerAppEnv.id
configuration: {
ingress: {
external: true
targetPort: targetPort
allowInsecure: false
traffic: [
{
latestRevision: true
weight: 100
}
]
}
}
template: {
revisionSuffix: 'firstrevision'
containers: [
{
name: containerAppName
image: containerImage
resources: {
cpu: json('0.5')
memory: '1Gi'
}
}
]
scale: {
minReplicas: 1
maxReplicas: 3
}
}
}
}