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

[Test-Proxy] Allow debug logging with docker host from CI. Bump targeted test-proxy version. Update versioning methodology. #2823

Merged
9 commits merged into from
Mar 2, 2022
27 changes: 21 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,15 @@ catch {
Write-Error "Please check your docker invocation and try running the script again."
}

$SELECTED_IMAGE_TAG = "1369319"
$SELECTED_IMAGE_TAG = "1.0.0-dev20220224.1"
$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) {
$SELECTED_IMAGE_TAG = $VersionOverride
}

if (-not $TargetFolder){
$TargetFolder = Join-Path -Path $PSScriptRoot -ChildPath "../../../"
}
Expand All @@ -51,15 +60,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 +92,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
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
3 changes: 2 additions & 1 deletion eng/common/testproxy/test-proxy-tool.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
rootFolder: '$(Build.SourcesDirectory)'
runProxy: true
targetVersion: '1.0.0-dev20220224.1'

steps:
- pwsh: |
Expand All @@ -11,7 +12,7 @@ steps:
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 ${{ parameters.targetVersion }}
displayName: "Install test-proxy"

- pwsh: |
Expand Down