1
- [CmdletBinding (DefaultParameterSetName = ' Default' )]
2
- param (
3
- [string ]$SearchDirectory ,
4
- [hashtable ]$Filters ,
5
- [string ]$Environment ,
6
- [string ]$Repository ,
7
- [switch ]$PushImages ,
8
- [string ]$ClusterGroup ,
9
- [string ]$DeployId ,
10
-
11
- [Parameter (ParameterSetName = ' DoLogin' , Mandatory = $true )]
12
- [switch ]$Login ,
13
-
14
- [Parameter (ParameterSetName = ' DoLogin' )]
15
- [string ]$Subscription ,
16
-
17
- # Default to true in Azure Pipelines environments
18
- [switch ] $CI = ($null -ne $env: SYSTEM_TEAMPROJECTID )
19
- )
20
-
21
1
$ErrorActionPreference = ' Stop'
22
2
23
3
. $PSScriptRoot / find-all - stress- packages.ps1
@@ -47,7 +27,7 @@ function RunOrExitOnFailure()
47
27
}
48
28
}
49
29
50
- function Login ([string ]$subscription , [string ]$clusterGroup , [boolean ]$pushImages )
30
+ function Login ([string ]$subscription , [string ]$clusterGroup , [switch ]$pushImages )
51
31
{
52
32
Write-Host " Logging in to subscription, cluster and container registry"
53
33
az account show * > $null
@@ -77,13 +57,38 @@ function DeployStressTests(
77
57
[string ]$searchDirectory = ' .' ,
78
58
[hashtable ]$filters = @ {},
79
59
[string ]$environment = ' test' ,
80
- [string ]$repository = ' images ' ,
81
- [boolean ]$pushImages = $false ,
82
- [string ]$clusterGroup = ' rg-stress-cluster-test ' ,
60
+ [string ]$repository = ' ' ,
61
+ [switch ]$pushImages ,
62
+ [string ]$clusterGroup = ' ' ,
83
63
[string ]$deployId = ' local' ,
84
- [string ]$subscription = ' Azure SDK Developer Playground'
64
+ [switch ]$login ,
65
+ [string ]$subscription = ' ' ,
66
+ [switch ]$ci
85
67
) {
86
- if ($PSCmdlet.ParameterSetName -eq ' DoLogin' ) {
68
+ if ($environment -eq ' test' ) {
69
+ if ($clusterGroup -or $subscription ) {
70
+ Write-Warning " Overriding cluster group and subscription with defaults for 'test' environment."
71
+ }
72
+ $clusterGroup = ' rg-stress-cluster-test'
73
+ $subscription = ' Azure SDK Developer Playground'
74
+ } elseif ($environment -eq ' prod' ) {
75
+ if ($clusterGroup -or $subscription ) {
76
+ Write-Warning " Overriding cluster group and subscription with defaults for 'prod' environment."
77
+ }
78
+ $clusterGroup = ' rg-stress-cluster-prod'
79
+ $subscription = ' Azure SDK Test Resources'
80
+ }
81
+
82
+ if (! $repository ) {
83
+ $repository = if ($env: USER ) { $env: USER } else { " ${env: USERNAME} " }
84
+ # Remove spaces, etc. that may be in $namespace
85
+ $repository -replace ' \W'
86
+ }
87
+
88
+ if ($login ) {
89
+ if (! $clusterGroup -or ! $subscription ) {
90
+ throw " clusterGroup and subscription parameters must be specified when logging into an environment that is not test or prod."
91
+ }
87
92
Login $subscription $clusterGroup $pushImages
88
93
}
89
94
@@ -96,7 +101,7 @@ function DeployStressTests(
96
101
Write-Host $pkgs.Directory " "
97
102
foreach ($pkg in $pkgs ) {
98
103
Write-Host " Deploying stress test at '$ ( $pkg.Directory ) '"
99
- DeployStressPackage $pkg $deployId $environment $repository $pushImages
104
+ DeployStressPackage $pkg $deployId $environment $repository $pushImages $login
100
105
}
101
106
102
107
Write-Host " Releases deployed by $deployId "
@@ -117,8 +122,9 @@ function DeployStressPackage(
117
122
[object ]$pkg ,
118
123
[string ]$deployId ,
119
124
[string ]$environment ,
120
- [string ]$repository ,
121
- [boolean ]$pushImages
125
+ [string ]$repositoryBase ,
126
+ [switch ]$pushImages ,
127
+ [switch ]$login
122
128
) {
123
129
$registry = RunOrExitOnFailure az acr list - g $clusterGroup -- subscription $subscription - o json
124
130
$registryName = ($registry | ConvertFrom-Json ).name
@@ -131,26 +137,23 @@ function DeployStressPackage(
131
137
if ($LASTEXITCODE ) { return }
132
138
}
133
139
140
+ $imageTag = " ${registryName} .azurecr.io"
141
+ if ($repositoryBase ) {
142
+ $imageTag += " /$repositoryBase "
143
+ }
144
+ $imageTag += " /$ ( $pkg.Namespace ) /$ ( $pkg.ReleaseName ) :${deployId} "
145
+
134
146
if ($pushImages ) {
135
- $dockerFiles = Get-ChildItem " $ ( $pkg.Directory ) /Dockerfile*"
136
- foreach ($dockerFile in $dockerFiles ) {
137
- # Infer docker image name from parent directory name, if file is named `Dockerfile`
138
- # or from suffix, is file is named like `Dockerfile.myimage` (for multiple dockerfiles).
139
- $prefix , $imageName = $dockerFile.Name.Split (" ." )
140
- if (! $imageName ) {
141
- $imageName = $dockerFile.Directory.Name
142
- }
143
- $imageTag = " ${registryName} .azurecr.io/$ ( $repository.ToLower ()) /$ ( $imageName ) :$deployId "
144
- Write-Host " Building and pushing stress test docker image '$imageTag '"
145
- Run docker build - t $imageTag -f $dockerFile.FullName $dockerFile.DirectoryName
146
- if ($LASTEXITCODE ) { return }
147
- Run docker push $imageTag
148
- if ($LASTEXITCODE ) {
149
- if ($PSCmdlet.ParameterSetName -ne ' DoLogin' ) {
150
- Write-Warning " If docker push is failing due to authentication issues, try calling this script with '-Login'"
151
- }
152
- return
147
+ Write-Host " Building and pushing stress test docker image '$imageTag '"
148
+ $dockerFile = Get-ChildItem " $ ( $pkg.Directory ) /Dockerfile"
149
+ Run docker build - t $imageTag -f $dockerFile.FullName $dockerFile.DirectoryName
150
+ if ($LASTEXITCODE ) { return }
151
+ Run docker push $imageTag
152
+ if ($LASTEXITCODE ) {
153
+ if ($login ) {
154
+ Write-Warning " If docker push is failing due to authentication issues, try calling this script with '-Login'"
153
155
}
156
+ return
154
157
}
155
158
}
156
159
@@ -162,8 +165,7 @@ function DeployStressPackage(
162
165
Run helm upgrade $pkg.ReleaseName $pkg.Directory `
163
166
- n $pkg.Namespace `
164
167
-- install `
165
- -- set repository= $registryName.azurecr.io / $repository `
166
- -- set tag= $deployId `
168
+ -- set image= $imageTag `
167
169
-- set stress- test-addons .env= $environment
168
170
if ($LASTEXITCODE ) {
169
171
# Issues like 'UPGRADE FAILED: another operation (install/upgrade/rollback) is in progress'
0 commit comments