Skip to content

Commit

Permalink
Initial add of recording (#180)
Browse files Browse the repository at this point in the history
* Initial add

* README.md and cleanup

* README update

* PR Feedback
  • Loading branch information
rhurey authored Feb 13, 2024
1 parent 577360a commit f1fc5c8
Show file tree
Hide file tree
Showing 33 changed files with 90,085 additions and 136 deletions.
152 changes: 21 additions & 131 deletions .azure/pipelines/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,144 +262,34 @@ stages:
TestFilter: 'cli=ai&tag!=skip'
TestResultsPath: '$(Build.SourcesDirectory)/testresults'
TestRunTitle: 'Azure AI CLI $(AICLIVersion) ($(BuildConfiguration)-$(Build.BuildNumber))'
TestRunTrxFileName: '$(TestResultsPath)/ai-cli-test-results-$(BuildConfiguration)-$(Build.BuildNumber).trx'
TestRunTrxFileName: '$(TestResultsPath)/ai-cli-test-results-$(BuildConfiguration)-$(Build.BuildNumber)'
TestBackupArtifactFile: '$(Build.ArtifactStagingDirectory)/ai-cli-test-run-backup-artifact-$(BuildConfiguration)-$(Build.BuildNumber).zip'
jobs:
- job: TestJob
steps:
- template: test_setup.yaml
- template: docker_proxy_setup.yaml

# -----------------------------------------------------------------------------
# Download the ai CLI artifacts
# -----------------------------------------------------------------------------
- task: DownloadPipelineArtifact@2
displayName: Download ai-cli-artifacts
inputs:
artifact: 'ai-cli-artifacts'
targetPath: '$(Build.ArtifactStagingDirectory)/ai-cli-artifacts'
- task: CopyFiles@2
displayName: Copy downloaded ai-cli-artifacts
inputs:
Contents: '**/*'
SourceFolder: $(Build.ArtifactStagingDirectory)/ai-cli-artifacts
TargetFolder: $(TargetFolder)
FlattenFolders: true
- task: Bash@3
displayName: List files...
inputs:
targetType: 'inline'
script: |
echo listing for $(System.DefaultWorkingDirectory)
ls -la $(System.DefaultWorkingDirectory)
echo listing for $(Build.ArtifactStagingDirectory)
ls -la $(Build.ArtifactStagingDirectory)
# -----------------------------------------------------------------------------
# Install the ai CLI
# -----------------------------------------------------------------------------
- task: DotNetCoreCLI@2
displayName: INSTALL AI - Installing ai CLI via `dotnet tool install`
inputs:
includeNuGetOrg: false
command: custom
custom: tool
version: '8.0.x'
arguments: install
--ignore-failed-sources
--add-source "$(System.DefaultWorkingDirectory)"
--global Azure.AI.CLI
--version "$(AICLIVersion)"

# -----------------------------------------------------------------------------
# Finish job prep (mkdir, config cli)
# -----------------------------------------------------------------------------
- bash: |
env | sort
which dotnet
dotnet --version
echo "TestResultsPath: $(TestResultsPath)"
mkdir $(TestResultsPath)
echo "LocalInputPath: $(LocalInputPath)"
ls -la $(LocalInputPath)
ai config system --set input.path $(LocalInputPath)
ai config --find
echo "DefaultWorkingDirectory: $(System.DefaultWorkingDirectory)"
ls -la $(System.DefaultWorkingDirectory)
displayName: Finish job prep (mkdir, config cli)
workingDirectory: '$(System.DefaultWorkingDirectory)'
# -----------------------------------------------------------------------------
# Build the YamlTestAdapter
# -----------------------------------------------------------------------------
- task: DotNetCoreCLI@2
displayName: Build YamlTestAdapter
inputs:
includeNuGetOrg: false
command: build
version: '8.0.x'
projects: '**/testadapter/YamlTestAdapter.csproj'
arguments:
-c $(BuildConfiguration)
/p:Platform=x64
/p:LocalBinOutputPath="$(LocalBinOutputPath)"

# -----------------------------------------------------------------------------
# Run the tests
# -----------------------------------------------------------------------------
- task: AzureCLI@2
displayName: Run ai-cli tests
continueOnError: true
inputs:
azureSubscription: 'AI_CLI_TestAdapter'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az --version
az account show
cd $(TestResultsPath)
echo dotnet test --logger trx --results-directory "$(Agent.TempDirectory)" --logger:"trx;LogFileName=$(TestRunTrxFileName)" --logger:"console;verbosity=normal" --filter "$(TestFilter)" "$(LocalBinOutputPath)/$(BuildConfiguration)/net8.0/Azure.AI.CLI.TestAdapter.dll"
dotnet test --logger trx --results-directory "$(Agent.TempDirectory)" --logger:"trx;LogFileName=$(TestRunTrxFileName)" --logger:"console;verbosity=normal" --filter "$(TestFilter)" "$(LocalBinOutputPath)/$(BuildConfiguration)/net8.0/Azure.AI.CLI.TestAdapter.dll"
# -----------------------------------------------------------------------------
# Archive and publish the test run backup artifact
# -----------------------------------------------------------------------------
- task: ArchiveFiles@2
displayName: Archive ai-cli-test run backup artifact (build/bin)
continueOnError: true
inputs:
rootFolderOrFile: '$(LocalBinOutputPath)'
includeRootFolder: false
archiveFile: '$(TestBackupArtifactFile)'
replaceExistingArchive: false
- template: test_execute_and_report.yaml
parameters:
test_adapter_name: Azure.AI.CLI.RecordedTestAdapter
TestFilter: $(TestFilter)
envToSet: 'TEST_MODE=Playback;REQUESTS_CA_BUNDLE=/ca/ca.crt'

- task: ArchiveFiles@2
displayName: Archive ai-cli-test run backup artifact (testresults)
continueOnError: true
inputs:
rootFolderOrFile: '$(TestResultsPath)'
includeRootFolder: false
archiveFile: '$(TestBackupArtifactFile)'
replaceExistingArchive: false

- task: PublishBuildArtifacts@1
displayName: Publish ai-cli-test run backup artifact
continueOnError: true
retryCountOnTaskFailure: 5
inputs:
parallel: true
pathToPublish: '$(TestBackupArtifactFile)'
artifactName: TestRunBackup

# -----------------------------------------------------------------------------
# Publish the test results
# -----------------------------------------------------------------------------
- task: PublishTestResults@2
displayName: Publish ai-cli test results
inputs:
testRunner: VSTest
testResultsFiles: '$(TestRunTrxFileName)'
testRunTitle: '$(TestRunTitle)'
failTaskOnFailedTests: true
- script: |
docker logs nginx
docker stop nginx
docker rm nginx
docker logs test-proxy
docker stop test-proxy
docker rm test-proxy
displayName: Stop nginx-recording-test-proxy locally
- template: test_execute_and_report.yaml
parameters:
test_adapter_name: Azure.AI.CLI.TestAdapter
TestFilter: $(TestFilter)&tag!=recordable

- stage: ManualApproval
dependsOn: [SetupStage, BuildStage, TestStage]
condition: and(succeeded(), or(eq(stageDependencies.SetupStage.outputs['SetupJob.Variables.IsRelease'], 'true'), eq(variables['PublishDevBuild'], 'true')))
Expand Down
36 changes: 36 additions & 0 deletions .azure/pipelines/docker_proxy_setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
steps:
- task: docker@2
displayName: Login to acrbn acr
inputs:
command: login
containerRegistry: 'acrbn-acr'
- task: docker@2
displayName: Build nginx-recording-test-proxy locally
inputs:
command: build
repository: nginx-recording-test-proxy-dev
dockerfile: 'tests/recordproxy/Dockerfile'
containerRegistry: 'acrbn-acr'
- bash: |
docker images
host_ip=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
echo "Host IP: $host_ip"
HOST_URL="http://$host_ip:5000"
echo "Host URL: $HOST_URL"
mkdir /logs
docker create -p 5004:5004 --name nginx -v ./logs:/logs -e TEST_PROXY_URL="$HOST_URL" acrbn.azurecr.io/nginx-recording-test-proxy-dev:$(Build.BuildId)
docker start nginx
docker create -p 5001:5001 -p 5000:5000 -v ./tests/recordings:/srv/testproxy --name test-proxy azsdkengsys.azurecr.io/engsys/test-proxy:latest
docker start test-proxy
docker ps
displayName: Run nginx-recording-test-proxy locally
- bash: |
sudo mkdir /ca
sudo chmod 777 /ca
sudo curl -v http://localhost:5004/ca.crt > /ca/ca.crt
sudo mkdir /usr/local/share/ca-certificates/extra
sudo cp /ca/ca.crt /usr/local/share/ca-certificates/extra/ca.crt
sudo dpkg-reconfigure ca-certificates
sudo update-ca-certificates
displayName: Install nginx-recording-test-proxy certificate
115 changes: 115 additions & 0 deletions .azure/pipelines/nginx-docker-build-and-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# This template common steps for building and pushing of dev-carbon images
# Note that this also makes sure we comply with the SBOM requirements even
# though we likely will never use these images beyond the dev/build environment

variables:
# The base name of the image
# This also matches the suffix of the Dockerfile - ex Dockerfile.ubuntu
baseName: 'ubuntu'
# The version of the the base-named image
baseVer: '20.04'
# The path of the image (should normally not change)
repositorydocker: nginx-recording-test-proxy
dockerfile: 'tests/recordproxy/Dockerfile.base'
version: $(Build.BuildId)

trigger:
branches:
include:
- main
- refs/tags/*
pr:
- main

pool:
name: $(UbuntuPipelineName)

stages:
- stage: SetupStage
jobs:
- job: SetupJob
steps:
- task: Bash@3
name: Variables
inputs:
filePath: ./.azure/pipelines/scripts/set-variables.sh
arguments: '0.0.0-dev2024.$(Build.BuildId)'
displayName: 'Set up environment variables'

- stage: DockerStage
dependsOn: SetupStage
jobs:
- job: DockerJob

steps:
- task: Docker@2
displayName: Login to ACR
inputs:
containerRegistry: 'acrbn-acr'
command: 'login'
- task: Docker@2
displayName: Build ($(dockerfile) - $(version))
inputs:
command: 'build'
containerRegistry: 'acrbn-acr'
repository: $[variables.repositorydocker]
Dockerfile: $(dockerfile)
buildContext: '.'

################################################################################
## SBOM

# So, I have come up with a way to build the SBOM and add it to the image that
# we just built above. It assumes a single tag, but that is just fine as
# we want just a single tag here.
# For the SBOM tool, we need to have a directory to which it writes to
- task: Bash@3
displayName: 'Make directory for SBOM'
condition: succeeded()
inputs:
targetType: 'inline'
script: |
mkdir -p "$(System.ArtifactsDirectory)/_SBOM"
# See https://aka.ms/sbom and https://aka.ms/CyberEoM2SBOM
# and specifically https://eng.ms/docs/cloud-ai-platform/devdiv/one-engineering-system-1es/1es-docs/secure-supply-chain/ado-sbom-generator
- task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0
displayName: 'SBOM Generation Task'
condition: succeeded()
# What do we do for this? There is no output directory - it is a container build
inputs:
BuildDropPath: '$(System.ArtifactsDirectory)/_SBOM'

# Show the contents of the SBOM in the build output logs
- task: Bash@3
displayName: 'View SBOM'
condition: succeeded()
inputs:
targetType: 'inline'
script: |
echo "Showing the SBOM contents, just because"
for f in $(find "$(System.ArtifactsDirectory)/_SBOM/_manifest" -type f); do
echo
ls -l $f
[[ $f == *.json ]] && sha256sum $f
echo "==== START: $f"
[[ $f == *.json ]] && jq . $f || cat $f
echo
echo "==== END: $f"
echo
done
true
## SBOM
################################################################################

- task: Docker@2
displayName: 'Push ${{ variables.repositorydocker }}'
condition: and(succeeded(), in(variables['Build.Reason'], 'Manual', 'Schedule', 'IndividualCI', 'BatchedCI'))
inputs:
command: 'push'
containerRegistry: 'acrbn-acr'
repository: '$(repositorydocker)'
tags: |
${{ variables.repositorydocker }}
${{ variables.repositorydocker }}-$(Build.BuildId)
78 changes: 78 additions & 0 deletions .azure/pipelines/test_execute_and_report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
parameters:
test_adapter_name: Azure.AI.CLI.TestAdapter
TestFilter: 'TestCategory!=SkipOnVSTS'
envToSet: ''
steps:
# -----------------------------------------------------------------------------
# Run the tests
# -----------------------------------------------------------------------------
- task: AzureCLI@2
displayName: Run ai-cli tests
continueOnError: true
inputs:
azureSubscription: 'AI_CLI_TestAdapter'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az --version
az account show
cd $(TestResultsPath)
IFS=';' read -ra ENV_VARS <<< "${{ parameters.envToSet }}"
for env_var in "${ENV_VARS[@]}"; do
echo "Setting $env_var"
export "$env_var"
done
echo
echo "Running Docker containers"
docker ps
echo
echo "Current Environment Variables"
env
echo
echo dotnet test --logger trx --results-directory "$(Agent.TempDirectory)" --logger:"trx;LogFileName=$(TestRunTrxFileName)-${{ parameters.test_adapter_name }}.trx" --logger:"console;verbosity=normal" --filter "${{ parameters.TestFilter }}" "$(LocalBinOutputPath)/$(BuildConfiguration)/net8.0/${{ parameters.test_adapter_name }}.dll"
dotnet test --logger trx --results-directory "$(Agent.TempDirectory)" --logger:"trx;LogFileName=$(TestRunTrxFileName)-${{ parameters.test_adapter_name }}.trx" --logger:"console;verbosity=normal" --filter "${{ parameters.TestFilter }}" "$(LocalBinOutputPath)/$(BuildConfiguration)/net8.0/${{ parameters.test_adapter_name }}.dll"
# -----------------------------------------------------------------------------
# Archive and publish the test run backup artifact
# -----------------------------------------------------------------------------
- task: ArchiveFiles@2
displayName: Archive ai-cli-test run backup artifact (build/bin)
continueOnError: true
inputs:
rootFolderOrFile: '$(LocalBinOutputPath)'
includeRootFolder: false
archiveFile: '$(TestBackupArtifactFile)'
replaceExistingArchive: false

- task: ArchiveFiles@2
displayName: Archive ai-cli-test run backup artifact (testresults)
continueOnError: true
inputs:
rootFolderOrFile: '$(TestResultsPath)'
includeRootFolder: false
archiveFile: '$(TestBackupArtifactFile)'
replaceExistingArchive: false

- task: PublishBuildArtifacts@1
displayName: Publish ai-cli-test run backup artifact
continueOnError: true
retryCountOnTaskFailure: 5
inputs:
parallel: true
pathToPublish: '$(TestBackupArtifactFile)'
artifactName: TestRunBackup

# -----------------------------------------------------------------------------
# Publish the test results
# -----------------------------------------------------------------------------
- task: PublishTestResults@2
displayName: Publish ai-cli test results
condition: succeededOrFailed()
inputs:
testRunner: VSTest
testResultsFiles: '$(TestRunTrxFileName)-${{ parameters.test_adapter_name }}.trx'
testRunTitle: '$(TestRunTitle)'
failTaskOnFailedTests: true
Loading

0 comments on commit f1fc5c8

Please sign in to comment.