Skip to content

Commit

Permalink
Consume cosmos emulator from install path on agent (Azure#28568)
Browse files Browse the repository at this point in the history
Co-authored-by: Chidozie Ononiwu <[email protected]>
  • Loading branch information
azure-sdk and chidozieononiwu authored Feb 1, 2023
1 parent 214b513 commit 797f8dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
12 changes: 2 additions & 10 deletions eng/common/pipelines/templates/steps/cosmos-emulator.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
EmulatorInstallPath: "$(Agent.HomeDirectory)/../../Program Files/Azure Cosmos DB Emulator/Microsoft.Azure.Cosmos.Emulator.exe"
EmulatorMsiUrl: "https://aka.ms/cosmosdb-emulator"
StartParameters: ''

Expand All @@ -9,16 +10,7 @@ steps:
arguments: >
-EmulatorMsiUrl "${{ parameters.EmulatorMsiUrl }}"
-StartParameters "${{ parameters.StartParameters }}"
-Stage "Install"
pwsh: true
displayName: Install Public Cosmos DB Emulator

- task: Powershell@2
inputs:
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Cosmos-Emulator.ps1
arguments: >
-EmulatorMsiUrl "${{ parameters.EmulatorMsiUrl }}"
-StartParameters "${{ parameters.StartParameters }}"
-Emulator "${{ parameters.EmulatorInstallPath }}"
-Stage "Launch"
pwsh: true
displayName: Launch Public Cosmos DB Emulator
28 changes: 18 additions & 10 deletions eng/common/scripts/Cosmos-Emulator.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ This script downloads, installs and launches cosmosdb-emulator.
Uri for downloading the cosmosdb-emulator
.PARAMETER StartParameters
Parameter with which to launch the cosmosdb-emulator
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
Expand All @@ -18,6 +21,7 @@ Determines what part of the script to run. Has to be either Install or Launch
Param (
[string] $EmulatorMsiUrl = "https://aka.ms/cosmosdb-emulator",
[string] $StartParameters,
[string] $Emulator,
[Parameter(Mandatory=$True)]
[ValidateSet('Install', 'Launch')]
[string] $Stage
Expand All @@ -26,7 +30,11 @@ Param (
$targetDir = Join-Path $Env:Temp AzureCosmosEmulator
$logFile = Join-Path $Env:Temp log.txt
$productName = "Azure Cosmos DB Emulator"
$emulator = (Join-Path $targetDir (Join-Path $productName "Microsoft.Azure.Cosmos.Emulator.exe"))

if ([string]::IsNullOrEmpty($Emulator))
{
$Emulator = (Join-Path $targetDir (Join-Path $productName "Microsoft.Azure.Cosmos.Emulator.exe"))
}

if ($Stage -eq "Install")
{
Expand Down Expand Up @@ -58,19 +66,19 @@ if ($Stage -eq "Install")
}

Write-Host "Getting Cosmos DB Emulator Version"
$fileVersion = Get-ChildItem $emulator
Write-Host $emulator $fileVersion.VersionInfo
$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'"
if (!(Test-Path $Emulator)) {
Write-Error "The emulator is not installed where expected at '$Emulator'"
return
}

$process = Start-Process $emulator -ArgumentList "/getstatus" -PassThru -Wait
$process = Start-Process $Emulator -ArgumentList "/getstatus" -PassThru -Wait
switch ($process.ExitCode) {
1 {
Write-Host "The emulator is already starting"
Expand All @@ -97,8 +105,8 @@ if ($Stage -eq "Launch")
$argumentList = "/noexplorer /noui /enablepreview /disableratelimiting /enableaadauthentication"
}

Write-Host "Starting emulator process: $emulator $argumentList"
$process = Start-Process $emulator -ArgumentList $argumentList -ErrorAction Stop -PassThru
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
Expand All @@ -117,7 +125,7 @@ if ($Stage -eq "Launch")
}

do {
$process = Start-Process $emulator -ArgumentList "/getstatus" -PassThru -Wait
$process = Start-Process $Emulator -ArgumentList "/getstatus" -PassThru -Wait
switch ($process.ExitCode) {
1 {
Write-Host "The emulator is starting"
Expand Down

0 comments on commit 797f8dd

Please sign in to comment.