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] eng/common templates #1909

Merged
19 commits merged into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 10 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ steps:
dotnet tool install
Azure.Sdk.Tools.PipelineGenerator
--version 1.0.2-dev.20210621.4
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk/nuget/v3/index.json
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json
scbedd marked this conversation as resolved.
Show resolved Hide resolved
--tool-path ${{parameters.ToolPath}}
workingDirectory: $(Pipeline.Workspace)/pipeline-generator
displayName: 'Install pipeline generator tool'
1 change: 1 addition & 0 deletions eng/common/scripts/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ $GetDocsMsMetadataForPackageFn = "Get-${Language}-DocsMsMetadataForPackage"
$GetDocsMsDevLanguageSpecificPackageInfoFn = "Get-${Language}-DocsMsDevLanguageSpecificPackageInfo"
$GetGithubIoDocIndexFn = "Get-${Language}-GithubIoDocIndex"
$FindArtifactForApiReviewFn = "Find-${Language}-Artifacts-For-Apireview"
$TestProxyTrustCertFn = "Import-Dev-Cert-${Language}"
83 changes: 83 additions & 0 deletions eng/common/testproxy/docker-start-proxy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env pwsh -c

<#
.DESCRIPTION
Start the docker proxy container. If it is already running, quietly exit. Any other error should fail.
.PARAMETER Mode
"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.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[ValidateSet("start", "stop")]
[String]
$Mode,
[String]
$TargetFolder = "."
)

try {
docker --version | Out-Null
}
catch {
Write-Error "A invocation of docker --version failed. This indicates that docker is not properly installed or running."
Write-Error "Please check your docker invocation and try running the script again."
}

$SELECTED_IMAGE_TAG = "1037115"
$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}"
$root = (Resolve-Path $TargetFolder).Path.Replace("`\", "/")

function Get-Proxy-Container(){
return (docker container ls -a --format "{{ json . }}" --filter "name=$CONTAINER_NAME" `
| ConvertFrom-Json `
| Select-Object -First 1)
}


$SelectedImage = $LINUX_IMAGE_SOURCE
$Initial = ""

# 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:"
}

if ($Mode -eq "start"){
$proxyContainer = Get-Proxy-Container

# if we already have one, we just need to check the state
if($proxyContainer){
if ($proxyContainer.State -eq "running")
{
Write-Host "Discovered an already running instance of the test-proxy!. Exiting"
exit(0)
}
}
# else we need to create it
else {
Write-Host "Attempting creation of Docker host $CONTAINER_NAME"
Write-Host "docker container create -v `"${root}:${Initial}/etc/testproxy`" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage"
docker container create -v "${root}:${Initial}/etc/testproxy" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage
}

Write-Host "Attempting start of Docker host $CONTAINER_NAME"
docker container start $CONTAINER_NAME
}

if ($Mode -eq "stop"){
$proxyContainer = Get-Proxy-Container

if($proxyContainer){
if($proxyContainer.State -eq "running"){
Write-Host "Found a running instance of $CONTAINER_NAME, shutting it down."
docker container stop $CONTAINER_NAME
}
}
}
20 changes: 20 additions & 0 deletions eng/common/testproxy/dotnet-devcert.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDSDCCAjCgAwIBAgIUPMKpJ/j10eQrcQBNnkImIaOYHakwDQYJKoZIhvcNAQEL
BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIxMDgwNTAwMzU1NloXDTIyMDgw
NTAwMzU1NlowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF
AAOCAQ8AMIIBCgKCAQEAxe/ZseXgOTVoF7uTjX5Leknk95jIoyGc+VlxA8BhzGOr
r4u6VNQZRCMq+svHY36tW4+u/xHNe2kvbwy2mnS8cFFLfst+94qBZVJDBxSGZ9I/
wekErNsjFsik4UrMvcC+ZlGPh7hb3f7tSx29tn1DIkAUXVnbZ6TT5s+mYRQpZ6fW
6kR3RNfc0A1IUM7Zs9yfNEr0O2H41P2HcLKoOPtvd7GvTQm9Ofh3srKvII+sZn/J
WH7r76oRQMX904mOMdryQwZLObsqX4dXIEbafKVSecB3PBVIhv8gVtJhcZbQP1pI
mMiWd6PHv46ZhGf7+cKnYUSa8Ia2t/wetK1wd00dFwIDAQABo4GRMIGOMA8GA1Ud
EwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGmMBYGA1UdJQEB/wQMMAoGCCsGAQUF
BwMBMBcGA1UdEQEB/wQNMAuCCWxvY2FsaG9zdDA6BgorBgEEAYI3VAEBBCwMKkFT
UC5ORVQgQ29yZSBIVFRQUyBkZXZlbG9wbWVudCBjZXJ0aWZpY2F0ZTANBgkqhkiG
9w0BAQsFAAOCAQEAIj2VlBVcXGSly6KCBg6lgwFi+henWfSox77iuGAaAxDjN3jd
9lZahW4MPNLHKSrPRb4YNSLZ2jh7zdcttQrqd4qH65o1q56q5JrCmli99iIzY9Y8
RdYyxK4Zzr31wjpsyFiWQfqJTuSFUUg9uDDj0negwEZLIGlt7nr12wflt2+QOJtD
byMeSZLbB5dPzn341DK0qfJEJMMgL0XsPEVZ3TQ6Alc9zq5wI608C/mXnz3xJE05
UTYD8pRJJ/DyG0empvOVE8Sg93msHPquAbgqO9aqCpykgg/a8CFvI4wRdfvGEFlv
8XJKL8Y/PFsmFeO3axq3zUYKFVdc9Un4dFIaag==
-----END CERTIFICATE-----
Binary file added eng/common/testproxy/dotnet-devcert.pfx
Binary file not shown.
20 changes: 20 additions & 0 deletions eng/common/testproxy/test-proxy-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
parameters:
rootFolder: '$(Build.SourcesDirectory)'

steps:
- pwsh: |
. $(Build.SourcesDirectory)/eng/common/scripts/common.ps1
scbedd marked this conversation as resolved.
Show resolved Hide resolved

if ($TestProxyTrustCertFn -and (Test-Path "Function:$TestProxyTrustCertFn"))
{
&$TestProxyTrustCertFn
}
displayName: 'Language Specific Certificate Trust'

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

- pwsh: |
docker container ls -a
displayName: Check running container
52 changes: 52 additions & 0 deletions eng/common/testproxy/test-proxy-tool.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
parameters:
rootFolder: '$(Build.SourcesDirectory)'

steps:
- pwsh: |
. $(Build.SourcesDirectory)/eng/common/scripts/common.ps1

if ($TestProxyTrustCertFn -and (Test-Path "Function:$TestProxyTrustCertFn"))
{
&$TestProxyTrustCertFn
}
displayName: 'Language Specific Certificate Trust'

- pwsh: |
Write-Host "##vso[task.setvariable variable=OriginalPath]$env:PATH"
displayName: 'Store Path Value'

- pwsh: |
Write-Host "##vso[task.setvariable variable=ASPNETCORE_Kestrel__Certificates__Default__Path]$(Build.SourcesDirectory)/eng/common/testproxy/dotnet-devcert.pfx"
Write-Host "##vso[task.setvariable variable=ASPNETCORE_Kestrel__Certificates__Default__Password]password"
displayName: 'Configure Kestrel Environment Variables'

- task: UseDotNet@2
displayName: "Use .NET Core SDK"
inputs:
packageType: sdk
version: 5.0.205

- pwsh: |
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.20210811.2
displayName: "Install test-proxy"

- pwsh: |
Start-Process $(Build.BinariesDirectory)/test-proxy/test-proxy.exe `
-ArgumentList "--storage-location '${{ parameters.rootFolder }}'" `
-NoNewWindow -PassThru
displayName: 'Run the testproxy - windows'
condition: and(succeeded(), eq(variables['Agent.OS'],'Windows_NT'))

# nohup does NOT continue beyond the current session if you use it within powershell
- bash: |
sudo nohup $(Build.BinariesDirectory)/test-proxy/test-proxy &
displayName: "Run the testproxy - linux/mac"
condition: and(succeeded(), ne(variables['Agent.OS'],'Windows_NT'))
workingDirectory: "${{ parameters.rootFolder }}"

- pwsh: |
Write-Host "##vso[task.setvariable variable=PATH]$(OriginalPath)"
displayName: 'Restore .NET version by resetting path'
4 changes: 2 additions & 2 deletions tools/http-fault-injector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

2. Install http-fault-injector
```
> dotnet tool install azure.sdk.tools.httpfaultinjector --global --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk/nuget/v3/index.json
> dotnet tool install azure.sdk.tools.httpfaultinjector --global --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json

You can invoke the tool using the following command: http-fault-injector
Tool 'azure.sdk.tools.httpfaultinjector' (version '0.1.0') was successfully installed.
```

## Updating
```
> dotnet tool update azure.sdk.tools.httpfaultinjector --global --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk/nuget/v3/index.json
> dotnet tool update azure.sdk.tools.httpfaultinjector --global --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json

Tool 'azure.sdk.tools.httpfaultinjector' was successfully updated from version '0.1.0' to version '0.1.1'.
```
Expand Down
2 changes: 1 addition & 1 deletion tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For a detailed explanation, check the README.md one level up from this one. This
2. Install test-proxy

```powershell
> dotnet tool install azure.sdk.tools.testproxy --global --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk/nuget/v3/index.json
> dotnet tool install azure.sdk.tools.testproxy --global --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json
```

This feed is available in [the public azure-sdk project.](https://dev.azure.com/azure-sdk/public/_packaging?_a=feed&feed=azure-sdk)
Expand Down
4 changes: 2 additions & 2 deletions tools/test-proxy/docker/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ RUN chmod +x $CERT_FOLDER/$CERT_IMPORT_SH \
# install the package
RUN dotnet tool install azure.sdk.tools.testproxy \
--global \
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk/nuget/v3/index.json \
--version 1.0.0-dev.20210729.1 \
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json \
--version 1.0.0-dev.20210811.2 \
&& mkdir /etc/testproxy

EXPOSE 5001
Expand Down
4 changes: 2 additions & 2 deletions tools/test-proxy/docker/dockerfile-win
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ RUN mkdir -p etc/testproxy
# install the package
RUN dotnet tool install azure.sdk.tools.testproxy \
--tool-path /proxyserver \
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk/nuget/v3/index.json \
--version 1.0.0-dev.20210729.1
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json \
--version 1.0.0-dev.20210811.2

EXPOSE 5001
EXPOSE 5000
Expand Down
2 changes: 1 addition & 1 deletion tools/test-proxy/documentation/using-in-devops.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Something along the lines of...
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/nuget/v3/index.json `
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json `
--version <version>
displayName: "Install TestProxy"

Expand Down