From 07137f745fcb3429f1fb0b1df5b78e38c30fa35a Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Tue, 26 Mar 2024 17:33:17 -0500 Subject: [PATCH] added bash scripts for CQRS sample --- .../CqrsSqlServer.DataModel/populate-db.sh | 8 +++++ src/cqrs/cqrs-sqlserver/build.cmd | 24 --------------- src/cqrs/cqrs-sqlserver/build.sh | 25 ---------------- src/cqrs/cqrs-sqlserver/start-dependencies.sh | 30 ++++++++++++++++++- 4 files changed, 37 insertions(+), 50 deletions(-) create mode 100644 src/cqrs/cqrs-sqlserver/CqrsSqlServer.DataModel/populate-db.sh delete mode 100644 src/cqrs/cqrs-sqlserver/build.cmd delete mode 100644 src/cqrs/cqrs-sqlserver/build.sh diff --git a/src/cqrs/cqrs-sqlserver/CqrsSqlServer.DataModel/populate-db.sh b/src/cqrs/cqrs-sqlserver/CqrsSqlServer.DataModel/populate-db.sh new file mode 100644 index 0000000..20457ed --- /dev/null +++ b/src/cqrs/cqrs-sqlserver/CqrsSqlServer.DataModel/populate-db.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# Runs EF Core migrations + +parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) +cd "$parent_path" + +# Update the database without building the project +dotnet ef database update --no-build \ No newline at end of file diff --git a/src/cqrs/cqrs-sqlserver/build.cmd b/src/cqrs/cqrs-sqlserver/build.cmd deleted file mode 100644 index 9c92f71..0000000 --- a/src/cqrs/cqrs-sqlserver/build.cmd +++ /dev/null @@ -1,24 +0,0 @@ -@echo off -REM builds all docker images - -set version="0.1.0" -set hostImageName="sqlsharding.host" -set webImageName="sqlsharding.web" - -if "%~1"=="" ( - REM No version tag specified - echo No tag for [%hostImageName%] specified. Defaulting to [%version%] - echo No tag for [%webImageName%] specified. Defaulting to [%version%] -) else ( - set version="%~1" - echo Building [%hostImageName%] with tag [%version%] - echo Building [%webImageName%] with tag [%version%] -) - -dotnet publish %~dp0/SqlSharding.Host/SqlSharding.Host.csproj -c Release -p:Version=%version% - -docker build %~dp0/SqlSharding.Host/. -t "%hostImageName%:%version%" - -dotnet publish %~dp0/SqlSharding.WebApp/SqlSharding.WebApp.csproj -c Release -p:Version=%version% - -docker build %~dp0/SqlSharding.WebApp/. -t "%webImageName%:%version%" \ No newline at end of file diff --git a/src/cqrs/cqrs-sqlserver/build.sh b/src/cqrs/cqrs-sqlserver/build.sh deleted file mode 100644 index 29bab51..0000000 --- a/src/cqrs/cqrs-sqlserver/build.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -# Builds docker images -parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) -cd "$parent_path" - -version="0.1.0" -hostImageName="sqlsharding.host" -webImageName="sqlsharding.web" - -if [ -z $1 ]; then - echo "No tag for [${hostImageName}] specified. Defaulting to [${version}]" - echo "No tag for [${webImageName}] specified. Defaulting to [${version}]" -else - version="$1" - echo "Building [${hostImageName}] with tag [${version}]" - echo "Building [${webImageName}] with tag [${version}]" -fi - -dotnet publish ./SqlSharding.Host/SqlSharding.Host.csproj -c Release -p:Version=${version} - -docker build ./SqlSharding.Host/. -t "${imageName}:${version}" - -dotnet publish ./SqlSharding.WebApp/SqlSharding.WebApp.csproj -c Release -p:Version=${version} - -docker build ./SqlSharding.WebApp/. -t "${imageName}:${version}" \ No newline at end of file diff --git a/src/cqrs/cqrs-sqlserver/start-dependencies.sh b/src/cqrs/cqrs-sqlserver/start-dependencies.sh index 8bf0e97..b56aa8b 100644 --- a/src/cqrs/cqrs-sqlserver/start-dependencies.sh +++ b/src/cqrs/cqrs-sqlserver/start-dependencies.sh @@ -2,6 +2,10 @@ # launches local SQL Server dependency so we can run from Visual Studio parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) +# Step 0: Build the project +echo Building the project in release configuration... +dotnet build -c Release + version="0.1.0" imageName="akkadotnet.sqlserver" @@ -20,4 +24,28 @@ if docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=yourStrong(!)Password" -p 1533: return -1 docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=yourStrong(!)Password" -p 1533:1433 --name "sqlsharding-sql" -d "${imageName}:${version}" fi -fi \ No newline at end of file +fi + +# Step 1: Execute EF Database Update +attemptCount=0 +EFDatabaseUpdate() { + ((attemptCount++)) + echo "Attempting to update the database, attempt $attemptCount" + echo "Calling $(dirname "$0")/CqrsSqlServer.DataModel/populate-db.sh" + $(dirname "$0")/CqrsSqlServer.DataModel/populate-db.sh + if [ $? -ne 0 ]; then + echo "Attempt $attemptCount failed to update database." + if [ $attemptCount -lt 3 ]; then + echo "Waiting for 30 seconds before retry..." + sleep 30 + EFDatabaseUpdate + else + echo "Failed to update the database after 3 attempts - aborting" + exit 1 + fi + else + echo "Database updated successfully." + fi +} + +EFDatabaseUpdate \ No newline at end of file