Skip to content

Commit

Permalink
add manual Exit-OnError step
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmrdavid authored Mar 5, 2024
1 parent 980dc91 commit 250dfb0
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions test/SmokeTests/e2e-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,60 @@ param(
[string]$collation="Latin1_General_100_BIN2_UTF8"
)

function Exit-OnError() {
# There appears to be a known problem in GitHub Action's `pwsh`shell preventing it from failing fast on an error:
# https://github.com/actions/runner-images/issues/6668#issuecomment-1364540817
# Therefore, we manually check if there was an error an fail if so.
if (!$LASTEXITCODE.Equals(0)) {exit $LASTEXITCODE}
}

$ErrorActionPreference = "Stop"
$AzuriteVersion = "3.26.0"

if ($NoSetup -eq $false) {
# Build the docker image first, since that's the most critical step
Write-Host "Building sample app Docker container from '$DockerfilePath'..." -ForegroundColor Yellow
docker build -f $DockerfilePath -t $ImageName --progress plain $PSScriptRoot/../../
Exit-OnError

# Next, download and start the Azurite emulator Docker image
Write-Host "Pulling down the mcr.microsoft.com/azure-storage/azurite:$AzuriteVersion image..." -ForegroundColor Yellow
docker pull "mcr.microsoft.com/azure-storage/azurite:${AzuriteVersion}"
Exit-OnError

Write-Host "Starting Azurite storage emulator using default ports..." -ForegroundColor Yellow
docker run --name 'azurite' -p 10000:10000 -p 10001:10001 -p 10002:10002 -d "mcr.microsoft.com/azure-storage/azurite:${AzuriteVersion}"
Exit-OnError

if ($SetupSQLServer -eq $true) {
Write-Host "Pulling down the mcr.microsoft.com/mssql/server:$tag image..."
docker pull mcr.microsoft.com/mssql/server:$tag

Exit-OnError

# Start the SQL Server docker container with the specified edition
Write-Host "Starting SQL Server $tag $sqlpid docker container on port $port" -ForegroundColor DarkYellow
docker run $additinalRunFlags --name mssqlserver -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$pw" -e "MSSQL_PID=$sqlpid" -p ${port}:1433 -d mcr.microsoft.com/mssql/server:$tag

Exit-OnError

# Wait for SQL Server to be ready
Write-Host "Waiting for SQL Server to be ready..." -ForegroundColor Yellow
Start-Sleep -Seconds 30 # Adjust the sleep duration based on your SQL Server container startup time
Exit-OnError

# Get SQL Server IP Address - used to create SQLDB_Connection
Write-Host "Getting IP Address..." -ForegroundColor Yellow
$serverIpAddress = docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mssqlserver

Exit-OnError

# Create the database with strict binary collation
Write-Host "Creating '$dbname' database with '$collation' collation" -ForegroundColor DarkYellow
docker exec -d mssqlserver /opt/mssql-tools/bin/sqlcmd -S . -U sa -P "$pw" -Q "CREATE DATABASE [$dbname] COLLATE $collation"
Exit-OnError

# Wait for database to be ready
Write-Host "Waiting for database to be ready..." -ForegroundColor Yellow
Start-Sleep -Seconds 30 # Adjust the sleep duration based on your database container startup time
Exit-OnError

# Finally, start up the application container, connecting to the SQL Server container
Write-Host "Starting the $ContainerName application container" -ForegroundColor Yellow
Expand All @@ -65,6 +81,7 @@ if ($NoSetup -eq $false) {
--env 'AzureWebJobsStorage=UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://host.docker.internal' `
--env 'WEBSITE_HOSTNAME=localhost:8080' `
$ImageName
Exit-OnError
}
else {
Write-Host "Starting $ContainerName application container" -ForegroundColor Yellow
Expand All @@ -73,6 +90,7 @@ if ($NoSetup -eq $false) {
--env 'WEBSITE_HOSTNAME=localhost:8080' `
$ImageName
}
Exit-OnError
}

if ($sleep -gt 0) {
Expand All @@ -83,12 +101,14 @@ if ($sleep -gt 0) {

# Check to see what containers are running
docker ps
Exit-OnError

try {
# Make sure the Functions runtime is up and running
$pingUrl = "http://localhost:8080/admin/host/ping"
Write-Host "Pinging app at $pingUrl to ensure the host is healthy" -ForegroundColor Yellow
Invoke-RestMethod -Method Post -Uri "http://localhost:8080/admin/host/ping"
Exit-OnError

if ($NoValidation -eq $false) {
# Note that any HTTP protocol errors (e.g. HTTP 4xx or 5xx) will cause an immediate failure
Expand All @@ -98,7 +118,7 @@ try {
$result = Invoke-RestMethod -Method Post -Uri $startOrchestrationUri
Write-Host "Started orchestration with instance ID '$($result.id)'!" -ForegroundColor Yellow
Write-Host "Waiting for orchestration to complete..." -ForegroundColor Yellow

$retryCount = 0
$success = $false
$statusUrl = $result.statusQueryGetUri
Expand Down Expand Up @@ -133,4 +153,4 @@ try {
throw
}

Write-Host "Success!" -ForegroundColor Green
Write-Host "Success!" -ForegroundColor Green

0 comments on commit 250dfb0

Please sign in to comment.