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

Sync eng/common directory with azure-sdk-tools for PR 2823 #27287

Merged
merged 8 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 22 additions & 6 deletions eng/common/testproxy/docker-start-proxy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ Pass value "start" or "stop" to start up or stop the test-proxy instance.
.PARAMETER TargetFolder
The folder in which context the test proxy will be started. Defaults to current working directory.

.PARAMETER VersionOverride
This script defaults the proxy version to the "common" version synced across all sdk repositories. If provided,
this parameter's value will be used as the target tag when downloading the image from azsdk docker hosting.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[ValidateSet("start", "stop")]
[String]
$Mode,
[String]
$TargetFolder = ""
$TargetFolder = "",
[String]
$VersionOverride = ""
)

try {
Expand All @@ -31,11 +36,16 @@ catch {
Write-Error "Please check your docker invocation and try running the script again."
}

$SELECTED_IMAGE_TAG = "1369319"
$SELECTED_IMAGE_TAG = $(Get-Content "$PSScriptRoot/target_version.txt" -Raw).Trim()
$CONTAINER_NAME = "ambitious_azsdk_test_proxy"
$LINUX_IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-lin:${SELECTED_IMAGE_TAG}"
$WINDOWS_IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-win:${SELECTED_IMAGE_TAG}"

if($VersionOverride) {
Write-Host "Overriding default target proxy version of '$SELECTED_IMAGE_TAG' with override $VersionOverride."
$SELECTED_IMAGE_TAG = $VersionOverride
}

if (-not $TargetFolder){
$TargetFolder = Join-Path -Path $PSScriptRoot -ChildPath "../../../"
}
Expand All @@ -51,15 +61,21 @@ function Get-Proxy-Container(){

$SelectedImage = $LINUX_IMAGE_SOURCE
$Initial = ""
$LinuxContainerArgs = "--add-host=host.docker.internal:host-gateway"
$AdditionalContainerArgs = "--add-host=host.docker.internal:host-gateway"

# most of the time, running this script on a windows machine will work just fine, as docker defaults to linux containers
# however, in CI, windows images default to _windows_ containers. We cannot swap them. We can tell if we're in a CI build by
# checking for the environment variable TF_BUILD.
if ($IsWindows -and $env:TF_BUILD){
$SelectedImage = $WINDOWS_IMAGE_SOURCE
$Initial = "C:"
$LinuxContainerArgs = ""
$AdditionalContainerArgs = ""
}

# there isn't really a great way to get environment variables automagically from the CI environment to the docker image
# handle loglevel here so that setting such a setting in CI will also bump the docker logging
if ($env:Logging__LogLevel__Default) {
$AdditionalContainerArgs += "-e Logging__LogLevel__Default=$($env:Logging__LogLevel__Default)"
}

if ($Mode -eq "start"){
Expand All @@ -77,9 +93,9 @@ if ($Mode -eq "start"){
else {
$attempts = 0
Write-Host "Attempting creation of Docker host $CONTAINER_NAME"
Write-Host "docker container create -v `"${root}:${Initial}/srv/testproxy`" $LinuxContainerArgs -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage"
Write-Host "docker container create -v `"${root}:${Initial}/srv/testproxy`" $AdditionalContainerArgs -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage"
while($attempts -lt 3){
docker container create -v "${root}:${Initial}/srv/testproxy" $LinuxContainerArgs -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage
docker container create -v "${root}:${Initial}/srv/testproxy" $AdditionalContainerArgs -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage

if($LASTEXITCODE -ne 0){
$attempts += 1
Expand Down
1 change: 1 addition & 0 deletions eng/common/testproxy/target_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0-dev.20220224.2
5 changes: 3 additions & 2 deletions eng/common/testproxy/test-proxy-docker.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
parameters:
rootFolder: '$(Build.SourcesDirectory)'
rootFolder: '$(Build.SourcesDirectory)'
targetVersion: ''

steps:
- pwsh: |
Expand All @@ -11,7 +12,7 @@ steps:
displayName: 'Dump active docker information'

- pwsh: |
$(Build.SourcesDirectory)/eng/common/testproxy/docker-start-proxy.ps1 -Mode start -TargetFolder "${{ parameters.rootFolder }}"
$(Build.SourcesDirectory)/eng/common/testproxy/docker-start-proxy.ps1 -Mode start -TargetFolder "${{ parameters.rootFolder }}" -VersionOverride="${{ parameters.targetVersion }}"
displayName: 'Run the docker container'

- pwsh: |
Expand Down
11 changes: 10 additions & 1 deletion eng/common/testproxy/test-proxy-tool.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
parameters:
rootFolder: '$(Build.SourcesDirectory)'
runProxy: true
targetVersion: ''

steps:
- pwsh: |
$(Build.SourcesDirectory)/eng/common/scripts/trust-proxy-certificate.ps1
displayName: 'Language Specific Certificate Trust'

- pwsh: |
$version = $(Get-Content "$(Build.SourcesDirectory)/eng/common/testproxy/target_version.txt" -Raw).Trim()
$overrideVersion = "${{ parameters.targetVersion }}"

if($overrideVersion) {
Write-Host "Overriding default target proxy version of '$version' with override $overrideVersion."
$version = $overrideVersion
}

dotnet tool install azure.sdk.tools.testproxy `
--tool-path $(Build.BinariesDirectory)/test-proxy `
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json `
--version 1.0.0-dev.20220210.1
--version $version
displayName: "Install test-proxy"

- pwsh: |
Expand Down