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

Revert "[INTERNAL] CI: Fixes emulator set-up to leverage central SDK teams scripts (#4813)" #4877

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
151 changes: 0 additions & 151 deletions templates/Cosmos-Emulator.ps1

This file was deleted.

81 changes: 67 additions & 14 deletions templates/emulator-setup.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,69 @@
parameters:
EmulatorInstallPath: "$(Agent.HomeDirectory)/../../Program Files/Azure Cosmos DB Emulator/Microsoft.Azure.Cosmos.Emulator.exe"
EmulatorMsiUrl: "https://aka.ms/cosmosdb-emulator"
StartParameters: ''
# File: templates/emulator-setup.yml

steps:
- 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
- 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
Binary file added tools/lessmsi-v2.1.1.zip
Binary file not shown.
Loading