-
Notifications
You must be signed in to change notification settings - Fork 524
[INTERNAL] CI: Fixes emulator set-up to leverage central SDK teams scripts #4813
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0f10cf4
Testing with JAVA emulaotr set-up instructions
kirankumarkolli 5179f88
Updating default arguments
kirankumarkolli 7d1e823
Removing lessmsi
kirankumarkolli e27244b
Changing partition count to 10
kirankumarkolli 0e26eeb
Adding defender exclusion
kirankumarkolli 3c68735
Merge branch 'master' into users/kirankk/emulator_new_logic
kirankumarkolli f02f079
changing compute port to default
kirankumarkolli e547a64
Merge branch 'master' into users/kirankk/emulator_new_logic
kirankumarkolli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Script for installing and launching cosmos emulator | ||
|
|
||
| .DESCRIPTION | ||
| This script downloads, installs and launches cosmosdb-emulator. | ||
|
|
||
| .PARAMETER EmulatorMsiUrl | ||
| Uri for downloading the cosmosdb-emulator | ||
|
|
||
| .PARAMETER StartParameters | ||
| Parameter with which to launch the cosmosdb-emulator\ | ||
|
|
||
| .PARAMETER Emulator | ||
| Exact path to Microsoft.Azure.Cosmos.Emulator.exe | ||
|
|
||
| .PARAMETER Stage | ||
| Determines what part of the script to run. Has to be either Install or Launch | ||
| #> | ||
| [CmdletBinding()] | ||
| Param ( | ||
| [string] $EmulatorMsiUrl = "https://aka.ms/cosmosdb-emulator", | ||
| [string] $StartParameters, | ||
| [string] $Emulator, | ||
| [Parameter(Mandatory=$True)] | ||
| [ValidateSet('Install', 'Launch')] | ||
| [string] $Stage | ||
| ) | ||
|
|
||
| $targetDir = Join-Path $Env:Temp AzureCosmosEmulator | ||
| $logFile = Join-Path $Env:Temp log.txt | ||
| $productName = "Azure Cosmos DB Emulator" | ||
|
|
||
| if ([string]::IsNullOrEmpty($Emulator)) | ||
| { | ||
| $Emulator = (Join-Path $targetDir (Join-Path $productName "Microsoft.Azure.Cosmos.Emulator.exe")) | ||
| } | ||
|
|
||
| if ($Stage -eq "Install") | ||
| { | ||
| $downloadTryCount = 0 | ||
| New-Item $targetDir -Type Directory | ||
| New-Item $logFile -Type File | ||
| do | ||
| { | ||
| # Download and Extract Public Cosmos DB Emulator | ||
| Write-Host "Downloading and extracting Cosmos DB Emulator - $EmulatorMsiUrl" | ||
| Write-Host "Target Directory $targetDir" | ||
| Write-Host "Log File $logFile" | ||
|
|
||
| $downloadTryCount++ | ||
| Write-Host "Download Try Count: $downloadTryCount" | ||
| Remove-Item -Path (Join-Path $targetDir '*') -Recurse | ||
| Clear-Content -Path $logFile | ||
|
|
||
| Add-MpPreference -ExclusionPath $targetDir | ||
|
|
||
| $installProcess = Start-Process msiexec -Wait -PassThru -ArgumentList "/a $EmulatorMsiUrl TARGETDIR=$targetDir /qn /liew $logFile" | ||
| Get-Content $logFile | ||
| Write-Host "Exit Code: $($installProcess.ExitCode)" | ||
| } | ||
| while(($installProcess.ExitCode -ne 0) -and ($downloadTryCount -lt 3)) | ||
|
|
||
| if(Test-Path (Join-Path $Env:LOCALAPPDATA CosmosDbEmulator)) | ||
| { | ||
| Write-Host "Deleting Cosmos DB Emulator data" | ||
| Remove-Item -Recurse -Force $Env:LOCALAPPDATA\CosmosDbEmulator | ||
| } | ||
|
|
||
| Write-Host "Getting Cosmos DB Emulator Version" | ||
| $fileVersion = Get-ChildItem $Emulator | ||
| Write-Host $Emulator $fileVersion.VersionInfo | ||
| } | ||
|
|
||
| if ($Stage -eq "Launch") | ||
| { | ||
| Write-Host "Launching Cosmos DB Emulator" | ||
| if (!(Test-Path $Emulator)) { | ||
| Write-Error "The emulator is not installed where expected at '$Emulator'" | ||
| return | ||
| } | ||
|
|
||
| $process = Start-Process $Emulator -ArgumentList "/getstatus" -PassThru -Wait | ||
| switch ($process.ExitCode) { | ||
| 1 { | ||
| Write-Host "The emulator is already starting" | ||
| return | ||
| } | ||
| 2 { | ||
| Write-Host "The emulator is already running" | ||
| return | ||
| } | ||
| 3 { | ||
| Write-Host "The emulator is stopped" | ||
| } | ||
| default { | ||
| Write-Host "Unrecognized exit code $($process.ExitCode)" | ||
| return | ||
| } | ||
| } | ||
|
|
||
| $argumentList = "" | ||
| if (-not [string]::IsNullOrEmpty($StartParameters)) { | ||
| $argumentList += , $StartParameters | ||
| } else { | ||
| # Use the default params if none provided | ||
| $argumentList = "/noexplorer /noui /enablepreview /EnableSqlComputeEndpoint /SqlComputePort=9999 /disableratelimiting /partitioncount=10 /consistency=Strong" | ||
| } | ||
|
|
||
| Write-Host "Starting emulator process: $Emulator $argumentList" | ||
| $process = Start-Process $Emulator -ArgumentList $argumentList -ErrorAction Stop -PassThru | ||
| Write-Host "Emulator process started: $($process.Name), $($process.FileVersion)" | ||
|
|
||
| $Timeout = 600 | ||
| $result="NotYetStarted" | ||
| $complete = if ($Timeout -gt 0) { | ||
| $start = [DateTimeOffset]::Now | ||
| $stop = $start.AddSeconds($Timeout) | ||
| { | ||
| $result -eq "Running" -or [DateTimeOffset]::Now -ge $stop | ||
| } | ||
| } | ||
| else { | ||
| { | ||
| $result -eq "Running" | ||
| } | ||
| } | ||
|
|
||
| do { | ||
| $process = Start-Process $Emulator -ArgumentList "/getstatus" -PassThru -Wait | ||
| switch ($process.ExitCode) { | ||
| 1 { | ||
| Write-Host "The emulator is starting" | ||
| } | ||
| 2 { | ||
| Write-Host "The emulator is running" | ||
| $result="Running" | ||
| return | ||
| } | ||
| 3 { | ||
| Write-Host "The emulator is stopped" | ||
| } | ||
| default { | ||
| Write-Host "Unrecognized exit code $($process.ExitCode)" | ||
| } | ||
| } | ||
| Start-Sleep -Seconds 5 | ||
| } | ||
| until ($complete.Invoke()) | ||
| Write-Error "The emulator failed to reach Running status within ${Timeout} seconds" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,69 +1,16 @@ | ||
| # File: templates/emulator-setup.yml | ||
| parameters: | ||
| EmulatorInstallPath: "$(Agent.HomeDirectory)/../../Program Files/Azure Cosmos DB Emulator/Microsoft.Azure.Cosmos.Emulator.exe" | ||
| EmulatorMsiUrl: "https://aka.ms/cosmosdb-emulator" | ||
| StartParameters: '' | ||
|
|
||
| steps: | ||
| - pwsh: | | ||
| Write-Host "Downloading Cosmos Emulator - $env:EMULATORMSIURL" -ForegroundColor green | ||
| Invoke-WebRequest "$env:EMULATORMSIURL" -OutFile "$env:temp\azure-cosmosdb-emulator.msi" | ||
| Write-Host "Finished Downloading Cosmos Emulator - $env:temp\azure-cosmosdb-emulator.msi" -ForegroundColor green | ||
| dir "$env:temp" | ||
|
|
||
| function Remove-DirectoryIfExists { | ||
| param ([string]$Path) | ||
|
|
||
| if (Test-Path -Path $Path -PathType Container) { | ||
| Remove-Item -Path $Path -Recurse -Force | ||
| Write-Output "Folder deleted: $Path" | ||
| } else { | ||
| Write-Output "Folder does not exist: $Path" | ||
| } | ||
| } | ||
|
|
||
| $lessMsiDir="$env:temp\lessmsi" | ||
| $emulatorDir="$env:temp\Azure Cosmos DB Emulator\" | ||
|
|
||
| Remove-DirectoryIfExists -Path $lessMsiDir | ||
| Remove-DirectoryIfExists -Path $emulatorDir | ||
|
|
||
| Expand-Archive -LiteralPath 'tools\lessmsi-v2.1.1.zip' -DestinationPath $lessMsiDir | ||
| &"$env:temp\lessmsi\lessmsi.exe" x "$env:temp\azure-cosmosdb-emulator.msi" "$emulatorDir" | ||
|
|
||
| Add-MpPreference -ExclusionPath "$emulatorDir\SourceDir\Azure Cosmos DB Emulator" | ||
| Add-MpPreference -ExclusionPath "$env:localappdata\CosmosDBEmulator" | ||
| displayName: Downloading and Installing Cosmos DB Emulator | ||
| failOnStderr: true | ||
| errorActionPreference: stop | ||
| - pwsh: | | ||
| Write-Host "Starting Cosmos DB Emulator" -ForegroundColor green | ||
| Import-Module "$env:temp\Azure Cosmos DB Emulator\SourceDir\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator" | ||
| Get-Item env:* | Sort-Object -Property Name | ||
|
|
||
| for ($j=0; $j -lt 3; $j++) { | ||
| Write-Host "Attempt $j" | ||
| Start-Process "$env:temp\Azure Cosmos DB Emulator\SourceDir\Azure Cosmos DB Emulator\CosmosDB.Emulator.exe" "/NoExplorer /NoUI /DisableRateLimiting /PartitionCount=10 /Consistency=Strong /EnablePreview /EnableSqlComputeEndpoint" -Verb RunAs | ||
| for ($i=0; $i -lt (3+2*$j); $i++) { | ||
| $status = Get-CosmosDbEmulatorStatus | ||
| Write-Host "Cosmos DB Emulator Status: $status" | ||
| if ($status -ne "Running") { | ||
| sleep 30; | ||
| } | ||
| else { | ||
| break; | ||
| } | ||
| } | ||
| if ($status -ne "Running") { | ||
| Write-Host "Shutting down and restarting" | ||
| Start-Process "$env:temp\Azure Cosmos DB Emulator\SourceDir\Azure Cosmos DB Emulator\CosmosDB.Emulator.exe" "/Shutdown" -Verb RunAs | ||
| sleep 30; | ||
| } | ||
| else { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if ($status -ne "Running") { | ||
| Write-Error "Emulator failed to start" | ||
| } | ||
|
|
||
| displayName: Waiting for Cosmos DB Emulator status | ||
| failOnStderr: true | ||
| errorActionPreference: stop | ||
| - task: Powershell@2 | ||
| inputs: | ||
| filePath: $(Build.SourcesDirectory)/templates/Cosmos-Emulator.ps1 | ||
| arguments: > | ||
| -EmulatorMsiUrl "${{ parameters.EmulatorMsiUrl }}" | ||
| -StartParameters "${{ parameters.StartParameters }}" | ||
| -Emulator "${{ parameters.EmulatorInstallPath }}" | ||
| -Stage "Launch" | ||
| pwsh: true | ||
| displayName: Launch Public Cosmos DB Emulator |
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.