From 86deafdafb24c011d85bbbab2ab4e98c90e194df Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 14:20:07 -0500 Subject: [PATCH 01/23] Removed automated deployments on startup, added section to readme Readme should now say how to do deployments locally --- api/ExpressedRealms.DB/readme.md | 11 +++++++++++ api/ExpressedRealms.Server/Program.cs | 18 ------------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/api/ExpressedRealms.DB/readme.md b/api/ExpressedRealms.DB/readme.md index b5006ed3..d8ecb40f 100644 --- a/api/ExpressedRealms.DB/readme.md +++ b/api/ExpressedRealms.DB/readme.md @@ -58,3 +58,14 @@ the application has. See the CharacterConfiguration class for an example. * [Seeding](https://code-maze.com/migrations-and-seed-data-efcore/) * [Type Configuration](https://stackoverflow.com/questions/46978332/use-ientitytypeconfiguration-with-a-base-entity) + +## Applying Migrations Locally +Create the efbundle.exe: +```shell +dotnet ef migrations bundle --self-contained --project ExpressedRealms.DB --startup-project ExpressedRealms.Server +``` + +Run the bundle +```shell +./efbundle --connection="Host=localhost:5432;Port=5432;Database=expressedRealms;Username=user;Password=password" +``` diff --git a/api/ExpressedRealms.Server/Program.cs b/api/ExpressedRealms.Server/Program.cs index 6cc20ef6..1fa6a1f9 100644 --- a/api/ExpressedRealms.Server/Program.cs +++ b/api/ExpressedRealms.Server/Program.cs @@ -122,24 +122,6 @@ Log.Information("Building the App"); var app = builder.Build(); - // Migrate latest database changes during startup - Log.Information("Checking if Migrations Need to Be Run"); - using (var scope = app.Services.CreateScope()) - { - var dbContext = scope.ServiceProvider.GetRequiredService(); - - if (dbContext.Database.GetPendingMigrations().Any()) - { - Log.Information("DB is missing migrations, running them now"); - dbContext.Database.Migrate(); - Log.Information("Successfully ran all migrations!"); - } - else - { - Log.Information("No Migrations are needed"); - } - } - app.UseDefaultFiles(); app.UseStaticFiles(); From 0f911f5b31347421c2b83b42b6fa6ac5c5e2b550 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 15:06:09 -0500 Subject: [PATCH 02/23] Created Github Action to Deploy DB Changes --- .github/workflows/DeployDatabaseChanges.yml | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/DeployDatabaseChanges.yml diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml new file mode 100644 index 00000000..f4709329 --- /dev/null +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -0,0 +1,72 @@ +name: .NET + +on: + push: + branches: [ "main" ] + paths: + - 'api/ExpressedRealms.DB/Migrations/**' + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + id-token: write + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build --no-restore + + - name: Restore Tools + run: dotnet tool restore + + - name: Build Bundle + run: dotnet ef migrations bundle --self-contained --project ExpressedRealms.DB --startup-project ExpressedRealms.Server + working-directory: ./api + + - name: Get Public IP + id: ip + uses: haythem/public-ip@v1.3 + + - name: Print Public IP + run: | + echo ${{ steps.ip.outputs.ipv4 }} + echo ${{ steps.ip.outputs.ipv6 }} + + - name: Azure Login + uses: azure/login@v1 + with: + client-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_TENANT_ID }} + subscription-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_SUBSCRIPTION_ID }} + + - name: Add IP to Firewall + run: az postgres server firewall-rule create --resource-group ${RESOURCE_GROUP} --server ${SQL_SERVER} --name GitHubIP --start-ip-address ${IP_ADDRESS} --end-ip-address ${IP_ADDRESS} + env: + SQL_SERVER: ${{ secrets.Postgres_Server_Name }} + IP_ADDRESS: ${{ steps.ip.outputs.ipv4 }} + RESOURCE_GROUP: ${{ secrets.Posgres_Resource_Group }} + + - name: Run Migrations + run: ./efbundle --connection "${{ secrets.CONNECTION_STRING }}" + working-directory: ./api + + - name: Remove IP from Firewall + if: always() + run: az sql postgres firewall-rule delete --resource-group ${RESOURCE_GROUP} --server ${SQL_SERVER} --name GitHubIP + env: + SQL_SERVER: ${{ secrets.Postgres_Server_Name }} + RESOURCE_GROUP: ${{ secrets.Posgres_Resource_Group }} \ No newline at end of file From ad6b8a2606a0b8d0f9edc1396601f4f183485495 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 15:19:24 -0500 Subject: [PATCH 03/23] Addressed Linter Errors, Tweaked Workflow itself --- .github/workflows/DeployDatabaseChanges.yml | 32 ++++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index f4709329..ee38396b 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -1,16 +1,21 @@ -name: .NET +--- + +name: Deploy Database Changes on: push: - branches: [ "main" ] + branches: ["main"] paths: - 'api/ExpressedRealms.DB/Migrations/**' pull_request: - branches: [ "main" ] + branches: ["main"] jobs: build: runs-on: ubuntu-latest + defaults: + run: + working-directory: ./api permissions: packages: write contents: read @@ -18,7 +23,7 @@ jobs: id-token: write steps: - uses: actions/checkout@v4 - + - name: Setup .NET uses: actions/setup-dotnet@v3 with: @@ -29,44 +34,43 @@ jobs: - name: Build run: dotnet build --no-restore - + - name: Restore Tools run: dotnet tool restore - + - name: Build Bundle run: dotnet ef migrations bundle --self-contained --project ExpressedRealms.DB --startup-project ExpressedRealms.Server - working-directory: ./api - + - name: Get Public IP id: ip uses: haythem/public-ip@v1.3 - + - name: Print Public IP run: | echo ${{ steps.ip.outputs.ipv4 }} echo ${{ steps.ip.outputs.ipv6 }} - + - name: Azure Login uses: azure/login@v1 with: client-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_CLIENT_ID }} tenant-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_TENANT_ID }} subscription-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_SUBSCRIPTION_ID }} - + - name: Add IP to Firewall run: az postgres server firewall-rule create --resource-group ${RESOURCE_GROUP} --server ${SQL_SERVER} --name GitHubIP --start-ip-address ${IP_ADDRESS} --end-ip-address ${IP_ADDRESS} env: SQL_SERVER: ${{ secrets.Postgres_Server_Name }} IP_ADDRESS: ${{ steps.ip.outputs.ipv4 }} RESOURCE_GROUP: ${{ secrets.Posgres_Resource_Group }} - + - name: Run Migrations run: ./efbundle --connection "${{ secrets.CONNECTION_STRING }}" working-directory: ./api - + - name: Remove IP from Firewall if: always() run: az sql postgres firewall-rule delete --resource-group ${RESOURCE_GROUP} --server ${SQL_SERVER} --name GitHubIP env: SQL_SERVER: ${{ secrets.Postgres_Server_Name }} - RESOURCE_GROUP: ${{ secrets.Posgres_Resource_Group }} \ No newline at end of file + RESOURCE_GROUP: ${{ secrets.Posgres_Resource_Group }} From 5924a77a8948bc902110c8613cd05d56b4fb768f Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 15:26:14 -0500 Subject: [PATCH 04/23] Another shot at getting the ef tools working --- .github/workflows/DeployDatabaseChanges.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index ee38396b..628e0b04 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -35,6 +35,12 @@ jobs: - name: Build run: dotnet build --no-restore + - name: Install dotnet-ef tool + run: dotnet tool install --global dotnet-ef + + - name: Add dotnet tools to PATH + run: echo "$HOME/.dotnet/tools" >> $GITHUB_PATH + - name: Restore Tools run: dotnet tool restore From 7bbda3926435779ab548dd26adb9b6a22de35e27 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 15:47:16 -0500 Subject: [PATCH 05/23] Fixed remove command, Fixed Casing on Secrets --- .github/workflows/DeployDatabaseChanges.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 628e0b04..9373bf14 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -66,9 +66,9 @@ jobs: - name: Add IP to Firewall run: az postgres server firewall-rule create --resource-group ${RESOURCE_GROUP} --server ${SQL_SERVER} --name GitHubIP --start-ip-address ${IP_ADDRESS} --end-ip-address ${IP_ADDRESS} env: - SQL_SERVER: ${{ secrets.Postgres_Server_Name }} + SQL_SERVER: ${{ secrets.POSTGRESS_SERVER_NAME }} IP_ADDRESS: ${{ steps.ip.outputs.ipv4 }} - RESOURCE_GROUP: ${{ secrets.Posgres_Resource_Group }} + RESOURCE_GROUP: ${{ secrets.POSTGRESS_RESOURCE_GROUP }} - name: Run Migrations run: ./efbundle --connection "${{ secrets.CONNECTION_STRING }}" @@ -76,7 +76,7 @@ jobs: - name: Remove IP from Firewall if: always() - run: az sql postgres firewall-rule delete --resource-group ${RESOURCE_GROUP} --server ${SQL_SERVER} --name GitHubIP + run: az postgres firewall-rule delete --resource-group ${RESOURCE_GROUP} --server ${SQL_SERVER} --name GitHubIP env: SQL_SERVER: ${{ secrets.Postgres_Server_Name }} RESOURCE_GROUP: ${{ secrets.Posgres_Resource_Group }} From 0ad5a11a4bebe4614f29c5dfff010e5ce98c43d7 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 15:51:29 -0500 Subject: [PATCH 06/23] Fixed typo --- .github/workflows/DeployDatabaseChanges.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 9373bf14..86408838 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -66,9 +66,9 @@ jobs: - name: Add IP to Firewall run: az postgres server firewall-rule create --resource-group ${RESOURCE_GROUP} --server ${SQL_SERVER} --name GitHubIP --start-ip-address ${IP_ADDRESS} --end-ip-address ${IP_ADDRESS} env: - SQL_SERVER: ${{ secrets.POSTGRESS_SERVER_NAME }} + SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} IP_ADDRESS: ${{ steps.ip.outputs.ipv4 }} - RESOURCE_GROUP: ${{ secrets.POSTGRESS_RESOURCE_GROUP }} + RESOURCE_GROUP: ${{ secrets.POSTGRES_RESOURCE_GROUP }} - name: Run Migrations run: ./efbundle --connection "${{ secrets.CONNECTION_STRING }}" From b55f4f0dd5cd258a5f681c9d2eba5d6863b783f3 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 16:13:03 -0500 Subject: [PATCH 07/23] Fixed Action Lint findings Hoping this fixes the resource issue as well --- .github/workflows/DeployDatabaseChanges.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 86408838..daf0d8a7 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -39,7 +39,7 @@ jobs: run: dotnet tool install --global dotnet-ef - name: Add dotnet tools to PATH - run: echo "$HOME/.dotnet/tools" >> $GITHUB_PATH + run: echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH" - name: Restore Tools run: dotnet tool restore @@ -64,7 +64,7 @@ jobs: subscription-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_SUBSCRIPTION_ID }} - name: Add IP to Firewall - run: az postgres server firewall-rule create --resource-group ${RESOURCE_GROUP} --server ${SQL_SERVER} --name GitHubIP --start-ip-address ${IP_ADDRESS} --end-ip-address ${IP_ADDRESS} + run: az postgres server firewall-rule create --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP --start-ip-address "${IP_ADDRESS}" --end-ip-address "${IP_ADDRESS}" env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} IP_ADDRESS: ${{ steps.ip.outputs.ipv4 }} @@ -76,7 +76,7 @@ jobs: - name: Remove IP from Firewall if: always() - run: az postgres firewall-rule delete --resource-group ${RESOURCE_GROUP} --server ${SQL_SERVER} --name GitHubIP + run: az postgres firewall-rule delete --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP env: - SQL_SERVER: ${{ secrets.Postgres_Server_Name }} - RESOURCE_GROUP: ${{ secrets.Posgres_Resource_Group }} + SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} + RESOURCE_GROUP: ${{ secrets.POSTGRES_RESOURCE_GROUP }} From e8c0793f50b9f2349994d6133042c470ad01cba0 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 16:52:21 -0500 Subject: [PATCH 08/23] Fixed Remove IP from Firewall run --- .github/workflows/DeployDatabaseChanges.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index daf0d8a7..c0079b2b 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -76,7 +76,7 @@ jobs: - name: Remove IP from Firewall if: always() - run: az postgres firewall-rule delete --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP + run: az postgres server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} RESOURCE_GROUP: ${{ secrets.POSTGRES_RESOURCE_GROUP }} From 9b5a874c972706a03cd0b34fe2e71e3ae5e7ad4c Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 16:54:30 -0500 Subject: [PATCH 09/23] Pipeline says I should use --yes --- .github/workflows/DeployDatabaseChanges.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index c0079b2b..4a740b73 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -76,7 +76,7 @@ jobs: - name: Remove IP from Firewall if: always() - run: az postgres server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP + run: az postgres server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP --yes env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} RESOURCE_GROUP: ${{ secrets.POSTGRES_RESOURCE_GROUP }} From c8b103ed11a1fbcdf27de512a17f9e42c36fdbef Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 17:00:21 -0500 Subject: [PATCH 10/23] Realized I needed flexible-server, not server in commands AHHHHHH --- .github/workflows/DeployDatabaseChanges.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 4a740b73..cb3b5c42 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -64,7 +64,7 @@ jobs: subscription-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_SUBSCRIPTION_ID }} - name: Add IP to Firewall - run: az postgres server firewall-rule create --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP --start-ip-address "${IP_ADDRESS}" --end-ip-address "${IP_ADDRESS}" + run: az postgres flexible-server firewall-rule create --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP --start-ip-address "${IP_ADDRESS}" --end-ip-address "${IP_ADDRESS}" env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} IP_ADDRESS: ${{ steps.ip.outputs.ipv4 }} @@ -76,7 +76,7 @@ jobs: - name: Remove IP from Firewall if: always() - run: az postgres server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP --yes + run: az postgres flexible-server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP --yes env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} RESOURCE_GROUP: ${{ secrets.POSTGRES_RESOURCE_GROUP }} From f68ee2416a43b49d329c5f3ba9b868edabcf22f2 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 17:04:36 -0500 Subject: [PATCH 11/23] Fixed server parameter --- .github/workflows/DeployDatabaseChanges.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index cb3b5c42..86c56067 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -64,7 +64,7 @@ jobs: subscription-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_SUBSCRIPTION_ID }} - name: Add IP to Firewall - run: az postgres flexible-server firewall-rule create --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP --start-ip-address "${IP_ADDRESS}" --end-ip-address "${IP_ADDRESS}" + run: az postgres flexible-server firewall-rule create --resource-group "${RESOURCE_GROUP}" --server-name "${SQL_SERVER}" --name GitHubIP --start-ip-address "${IP_ADDRESS}" --end-ip-address "${IP_ADDRESS}" env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} IP_ADDRESS: ${{ steps.ip.outputs.ipv4 }} @@ -76,7 +76,7 @@ jobs: - name: Remove IP from Firewall if: always() - run: az postgres flexible-server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --server "${SQL_SERVER}" --name GitHubIP --yes + run: az postgres flexible-server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --server-name "${SQL_SERVER}" --name GitHubIP --yes env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} RESOURCE_GROUP: ${{ secrets.POSTGRES_RESOURCE_GROUP }} From 9e8b633f07cb32b849994d4404aff87ffd5a4cbc Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 17:07:52 -0500 Subject: [PATCH 12/23] After consulting docs, got correct parameter for db name --- .github/workflows/DeployDatabaseChanges.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 86c56067..1f906d83 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -64,7 +64,7 @@ jobs: subscription-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_SUBSCRIPTION_ID }} - name: Add IP to Firewall - run: az postgres flexible-server firewall-rule create --resource-group "${RESOURCE_GROUP}" --server-name "${SQL_SERVER}" --name GitHubIP --start-ip-address "${IP_ADDRESS}" --end-ip-address "${IP_ADDRESS}" + run: az postgres flexible-server firewall-rule create --resource-group "${RESOURCE_GROUP}" --name "${SQL_SERVER}" --name GitHubIP --start-ip-address "${IP_ADDRESS}" --end-ip-address "${IP_ADDRESS}" env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} IP_ADDRESS: ${{ steps.ip.outputs.ipv4 }} @@ -76,7 +76,7 @@ jobs: - name: Remove IP from Firewall if: always() - run: az postgres flexible-server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --server-name "${SQL_SERVER}" --name GitHubIP --yes + run: az postgres flexible-server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --name "${SQL_SERVER}" --name GitHubIP --yes env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} RESOURCE_GROUP: ${{ secrets.POSTGRES_RESOURCE_GROUP }} From d3b00da553fac7e9639493fa7959afdd198a9d84 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 17:10:21 -0500 Subject: [PATCH 13/23] Fixed rulename parameter --- .github/workflows/DeployDatabaseChanges.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 1f906d83..1f6f4e5a 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -64,7 +64,7 @@ jobs: subscription-id: ${{ secrets.EXPRESSEDREALMS_DATABASE_AZURE_SUBSCRIPTION_ID }} - name: Add IP to Firewall - run: az postgres flexible-server firewall-rule create --resource-group "${RESOURCE_GROUP}" --name "${SQL_SERVER}" --name GitHubIP --start-ip-address "${IP_ADDRESS}" --end-ip-address "${IP_ADDRESS}" + run: az postgres flexible-server firewall-rule create --resource-group "${RESOURCE_GROUP}" --name "${SQL_SERVER}" --rule-name GitHubIP --start-ip-address "${IP_ADDRESS}" --end-ip-address "${IP_ADDRESS}" env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} IP_ADDRESS: ${{ steps.ip.outputs.ipv4 }} @@ -76,7 +76,7 @@ jobs: - name: Remove IP from Firewall if: always() - run: az postgres flexible-server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --name "${SQL_SERVER}" --name GitHubIP --yes + run: az postgres flexible-server firewall-rule delete --resource-group "${RESOURCE_GROUP}" --name "${SQL_SERVER}" --rule-name GitHubIP --yes env: SQL_SERVER: ${{ secrets.POSTGRES_SERVER_NAME }} RESOURCE_GROUP: ${{ secrets.POSTGRES_RESOURCE_GROUP }} From abd615f39c22e368eb5ed667f004b469f7a20847 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Sat, 17 Aug 2024 22:17:12 -0500 Subject: [PATCH 14/23] Switching to the Access Token method for password --- .github/workflows/DeployDatabaseChanges.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 1f6f4e5a..ef370941 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -70,9 +70,17 @@ jobs: IP_ADDRESS: ${{ steps.ip.outputs.ipv4 }} RESOURCE_GROUP: ${{ secrets.POSTGRES_RESOURCE_GROUP }} + - name: Get Access Token + id: get_token + run: | + token=$(az account get-access-token --resource https://ossrdbms-aad.database.windows.net/ --query accessToken -o tsv) + echo "##[set-output name=token;]$token" + - name: Run Migrations run: ./efbundle --connection "${{ secrets.CONNECTION_STRING }}" working-directory: ./api + env: + CONNECTION_STRING: "Server=${{secrets.CONNECTION_STRING_SERVER_NAME}};Database=${{secrets.CONNECTION_STRING_DATABASE}};Port=5432;User Id=${{secrets.CONNECTION_STRING_USER_ID}};Password=${{ steps.get_token.outputs.token }};Ssl Mode=Require;" - name: Remove IP from Firewall if: always() From 56132351df25d229d6165229db1d15873bfc8c0d Mon Sep 17 00:00:00 2001 From: noremacskich Date: Wed, 4 Sep 2024 00:17:38 -0500 Subject: [PATCH 15/23] Trying the connection string from in app --- .github/workflows/DeployDatabaseChanges.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index ef370941..930569b9 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -80,7 +80,7 @@ jobs: run: ./efbundle --connection "${{ secrets.CONNECTION_STRING }}" working-directory: ./api env: - CONNECTION_STRING: "Server=${{secrets.CONNECTION_STRING_SERVER_NAME}};Database=${{secrets.CONNECTION_STRING_DATABASE}};Port=5432;User Id=${{secrets.CONNECTION_STRING_USER_ID}};Password=${{ steps.get_token.outputs.token }};Ssl Mode=Require;" + CONNECTION_STRING: "${{secrets.AZURE_POSTGRESSQL_CONNECTIONSTRING}};Password=${{ steps.get_token.outputs.token }};" - name: Remove IP from Firewall if: always() From 61fbe60ca01a423e9b89aee05ca0a27a527a73f1 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Wed, 4 Sep 2024 00:35:27 -0500 Subject: [PATCH 16/23] Set dummy connection string for efcore bundle --- .github/workflows/DeployDatabaseChanges.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 930569b9..fa70a941 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -46,7 +46,9 @@ jobs: - name: Build Bundle run: dotnet ef migrations bundle --self-contained --project ExpressedRealms.DB --startup-project ExpressedRealms.Server - + env: + CONNECTION_STRING=Foo + - name: Get Public IP id: ip uses: haythem/public-ip@v1.3 From b059dfae1a7c35d564663c32988587714b4f894b Mon Sep 17 00:00:00 2001 From: noremacskich Date: Wed, 4 Sep 2024 00:37:00 -0500 Subject: [PATCH 17/23] Fixed config issue --- .github/workflows/DeployDatabaseChanges.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index fa70a941..6b4c3fa5 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -47,7 +47,7 @@ jobs: - name: Build Bundle run: dotnet ef migrations bundle --self-contained --project ExpressedRealms.DB --startup-project ExpressedRealms.Server env: - CONNECTION_STRING=Foo + CONNECTION_STRING: "Foo" - name: Get Public IP id: ip From 77cebb311ad7862e7092fc9f0152f07369f5531c Mon Sep 17 00:00:00 2001 From: noremacskich Date: Wed, 4 Sep 2024 00:40:01 -0500 Subject: [PATCH 18/23] Got a proper name on the environment variable --- .github/workflows/DeployDatabaseChanges.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 6b4c3fa5..92a08b3e 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -47,7 +47,7 @@ jobs: - name: Build Bundle run: dotnet ef migrations bundle --self-contained --project ExpressedRealms.DB --startup-project ExpressedRealms.Server env: - CONNECTION_STRING: "Foo" + ConnectionStrings__DefaultConnection: "Foo" - name: Get Public IP id: ip From 0d0a743c3146b262d3255457bf7142c0eeb35614 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Wed, 4 Sep 2024 00:47:08 -0500 Subject: [PATCH 19/23] Should now be getting the token correctly --- .github/workflows/DeployDatabaseChanges.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 92a08b3e..70a33e09 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -75,7 +75,7 @@ jobs: - name: Get Access Token id: get_token run: | - token=$(az account get-access-token --resource https://ossrdbms-aad.database.windows.net/ --query accessToken -o tsv) + token=$(az account get-access-token --query accessToken -o tsv) echo "##[set-output name=token;]$token" - name: Run Migrations From 176ab21da4a7f4d47052b68c0a937e46e6b4708b Mon Sep 17 00:00:00 2001 From: noremacskich Date: Wed, 4 Sep 2024 00:57:24 -0500 Subject: [PATCH 20/23] Trying new connection string Based off of what I have in my local pgadmin instance --- .github/workflows/DeployDatabaseChanges.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 70a33e09..5f81605f 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -75,14 +75,14 @@ jobs: - name: Get Access Token id: get_token run: | - token=$(az account get-access-token --query accessToken -o tsv) + token=$(az account get-access-token --resource https://ossrdbms-aad.database.windows.net/ --query accessToken -o tsv) echo "##[set-output name=token;]$token" - name: Run Migrations run: ./efbundle --connection "${{ secrets.CONNECTION_STRING }}" working-directory: ./api env: - CONNECTION_STRING: "${{secrets.AZURE_POSTGRESSQL_CONNECTIONSTRING}};Password=${{ steps.get_token.outputs.token }};" + CONNECTION_STRING: "${{secrets.DB_DEPLOYMENT_CONNECTION_STRING}};Password=${{ steps.get_token.outputs.token }};" - name: Remove IP from Firewall if: always() From bc389f7fc1f73fc3f3c5faac090000a1f0beb7ce Mon Sep 17 00:00:00 2001 From: noremacskich Date: Wed, 4 Sep 2024 01:00:42 -0500 Subject: [PATCH 21/23] Forgot to add in SSL mode --- .github/workflows/DeployDatabaseChanges.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 5f81605f..865ed63d 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -82,7 +82,7 @@ jobs: run: ./efbundle --connection "${{ secrets.CONNECTION_STRING }}" working-directory: ./api env: - CONNECTION_STRING: "${{secrets.DB_DEPLOYMENT_CONNECTION_STRING}};Password=${{ steps.get_token.outputs.token }};" + CONNECTION_STRING: "${{secrets.DB_DEPLOYMENT_CONNECTION_STRING}};Password=${{ steps.get_token.outputs.token }};Ssl Mode=Require;" - name: Remove IP from Firewall if: always() From 677843eecca1a3903c6e08c492390e028a873c21 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Wed, 4 Sep 2024 01:18:19 -0500 Subject: [PATCH 22/23] Trying different token strategy --- .github/workflows/DeployDatabaseChanges.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 865ed63d..2fda1af1 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -76,13 +76,13 @@ jobs: id: get_token run: | token=$(az account get-access-token --resource https://ossrdbms-aad.database.windows.net/ --query accessToken -o tsv) - echo "##[set-output name=token;]$token" + echo "TOKEN=$token" >> $GITHUB_ENV - name: Run Migrations run: ./efbundle --connection "${{ secrets.CONNECTION_STRING }}" working-directory: ./api env: - CONNECTION_STRING: "${{secrets.DB_DEPLOYMENT_CONNECTION_STRING}};Password=${{ steps.get_token.outputs.token }};Ssl Mode=Require;" + CONNECTION_STRING: "${{secrets.DB_DEPLOYMENT_CONNECTION_STRING}};Password=${{ env.TOKEN}};Ssl Mode=Require;" - name: Remove IP from Firewall if: always() From 8d18ab292c8338c1e430692feb93be6ddfd1d7e7 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Wed, 4 Sep 2024 01:32:47 -0500 Subject: [PATCH 23/23] Trying direct call on connection --- .github/workflows/DeployDatabaseChanges.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/DeployDatabaseChanges.yml b/.github/workflows/DeployDatabaseChanges.yml index 2fda1af1..d5cbbd84 100644 --- a/.github/workflows/DeployDatabaseChanges.yml +++ b/.github/workflows/DeployDatabaseChanges.yml @@ -79,10 +79,8 @@ jobs: echo "TOKEN=$token" >> $GITHUB_ENV - name: Run Migrations - run: ./efbundle --connection "${{ secrets.CONNECTION_STRING }}" + run: ./efbundle --connection "${{secrets.DB_DEPLOYMENT_CONNECTION_STRING}};Password=${{ env.TOKEN}};Ssl Mode=Require;" working-directory: ./api - env: - CONNECTION_STRING: "${{secrets.DB_DEPLOYMENT_CONNECTION_STRING}};Password=${{ env.TOKEN}};Ssl Mode=Require;" - name: Remove IP from Firewall if: always()