From 4f7f103b469740d8b2cecec0e92ffa452786624d Mon Sep 17 00:00:00 2001 From: sbuckley3 <152215946+sbuckley3@users.noreply.github.com> Date: Fri, 7 Feb 2025 12:05:11 -0500 Subject: [PATCH 1/5] Add or update the Azure App Service build and deployment workflow config --- ...r-no-infra_msdocs-core-sql-tutorial-si.yml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml diff --git a/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml b/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml new file mode 100644 index 000000000..16c849edd --- /dev/null +++ b/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml @@ -0,0 +1,68 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy ASP.Net Core app to Azure Web App - msdocs-core-sql-tutorial-SI + +on: + push: + branches: + - starter-no-infra + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read #This is required for actions/checkout + + steps: + - uses: actions/checkout@v4 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + + - name: Build with dotnet + run: dotnet build --configuration Release + + - name: dotnet publish + run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v4 + with: + name: .net-app + path: ${{env.DOTNET_ROOT}}/myapp + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + permissions: + id-token: write #This is required for requesting the JWT + contents: read #This is required for actions/checkout + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v4 + with: + name: .net-app + + - name: Login to Azure + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_6932C55BCA514CF691DC4FDB2CF7B9FE }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_A7E492D6033B41089822B7C41F5E7227 }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_9F4AA6529BB54283B9F614D5A084717C }} + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v3 + with: + app-name: 'msdocs-core-sql-tutorial-SI' + slot-name: 'Production' + package: . + \ No newline at end of file From f5e8d9bbc0221a158e36d3cb21a7f7bb1ef4de2d Mon Sep 17 00:00:00 2001 From: sbuckley3 <152215946+sbuckley3@users.noreply.github.com> Date: Fri, 7 Feb 2025 17:22:10 +0000 Subject: [PATCH 2/5] Configure Azure database and cache connections --- ...r-no-infra_msdocs-core-sql-tutorial-si.yml | 30 +++++++++++-------- Program.cs | 20 ++++++------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml b/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml index 16c849edd..226a9da5b 100644 --- a/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml +++ b/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml @@ -29,6 +29,12 @@ jobs: - name: dotnet publish run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp + - name: Install dotnet ef + run: dotnet tool install --global dotnet-ef --versionj 8.* + + - name: Create migrations bundle + run: dotnet ef migrations bundle --runtime linux-x64 -o ${{env.DOTNET_ROOT}}/myapp/migrationsbundle + - name: Upload artifact for deployment job uses: actions/upload-artifact@v4 with: @@ -38,25 +44,25 @@ jobs: deploy: runs-on: ubuntu-latest needs: build - environment: - name: 'Production' + environment: + name: 'Production' url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - permissions: - id-token: write #This is required for requesting the JWT - contents: read #This is required for actions/checkout + permissions: + id-token: write #This is required for requesting the JWT + contents: read #This is required for actions/checkout steps: - name: Download artifact from build job uses: actions/download-artifact@v4 with: name: .net-app - - - name: Login to Azure - uses: azure/login@v2 - with: - client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_6932C55BCA514CF691DC4FDB2CF7B9FE }} - tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_A7E492D6033B41089822B7C41F5E7227 }} - subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_9F4AA6529BB54283B9F614D5A084717C }} + + - name: Login to Azure + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_6932C55BCA514CF691DC4FDB2CF7B9FE }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_A7E492D6033B41089822B7C41F5E7227 }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_9F4AA6529BB54283B9F614D5A084717C }} - name: Deploy to Azure Web App id: deploy-to-webapp diff --git a/Program.cs b/Program.cs index ffa365722..489436d7d 100644 --- a/Program.cs +++ b/Program.cs @@ -9,16 +9,16 @@ options.UseSqlServer(builder.Configuration.GetConnectionString("MyDbConnection"))); builder.Services.AddDistributedMemoryCache(); } -// else -// { -// builder.Services.AddDbContext(options => -// options.UseSqlServer(builder.Configuration.GetConnectionString("AZURE_SQL_CONNECTIONSTRING"))); -// builder.Services.AddStackExchangeRedisCache(options => -// { -// options.Configuration = builder.Configuration["AZURE_REDIS_CONNECTIONSTRING"]; -// options.InstanceName = "SampleInstance"; -// }); -// } + else + { + builder.Services.AddDbContext(options => + options.UseSqlServer(builder.Configuration.GetConnectionString("AZURE_SQL_CONNECTIONSTRING"))); + builder.Services.AddStackExchangeRedisCache(options => + { + options.Configuration = builder.Configuration["AZURE_REDIS_CONNECTIONSTRING"]; + options.InstanceName = "SampleInstance"; + }); + } // Add services to the container. builder.Services.AddControllersWithViews(); From 2b70eec951bf931482764c7e81e1b8bbccec6d0d Mon Sep 17 00:00:00 2001 From: sbuckley3 <152215946+sbuckley3@users.noreply.github.com> Date: Fri, 7 Feb 2025 17:25:56 +0000 Subject: [PATCH 3/5] New Commit --- .../workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml b/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml index 226a9da5b..de38ea6b6 100644 --- a/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml +++ b/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml @@ -30,7 +30,7 @@ jobs: run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp - name: Install dotnet ef - run: dotnet tool install --global dotnet-ef --versionj 8.* + run: dotnet tool install -g dotnet-ef --version 8.* - name: Create migrations bundle run: dotnet ef migrations bundle --runtime linux-x64 -o ${{env.DOTNET_ROOT}}/myapp/migrationsbundle From c14c6c78765d9929094c3835e5fbfc45830a8808 Mon Sep 17 00:00:00 2001 From: sbuckley3 <152215946+sbuckley3@users.noreply.github.com> Date: Fri, 7 Feb 2025 17:34:05 +0000 Subject: [PATCH 4/5] Fixing --- .../workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml b/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml index de38ea6b6..74c47dd55 100644 --- a/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml +++ b/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml @@ -30,7 +30,7 @@ jobs: run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp - name: Install dotnet ef - run: dotnet tool install -g dotnet-ef --version 8.* + run: dotnet tool install --global dotnet-ef --version 8.* - name: Create migrations bundle run: dotnet ef migrations bundle --runtime linux-x64 -o ${{env.DOTNET_ROOT}}/myapp/migrationsbundle From b1b38eb9e009b6b443040aacc12231b6eadbbd22 Mon Sep 17 00:00:00 2001 From: sbuckley3 <152215946+sbuckley3@users.noreply.github.com> Date: Fri, 7 Feb 2025 17:54:58 +0000 Subject: [PATCH 5/5] Update to program --- Program.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Program.cs b/Program.cs index 489436d7d..eb38ee159 100644 --- a/Program.cs +++ b/Program.cs @@ -9,16 +9,16 @@ options.UseSqlServer(builder.Configuration.GetConnectionString("MyDbConnection"))); builder.Services.AddDistributedMemoryCache(); } - else - { - builder.Services.AddDbContext(options => - options.UseSqlServer(builder.Configuration.GetConnectionString("AZURE_SQL_CONNECTIONSTRING"))); - builder.Services.AddStackExchangeRedisCache(options => - { - options.Configuration = builder.Configuration["AZURE_REDIS_CONNECTIONSTRING"]; - options.InstanceName = "SampleInstance"; - }); - } +else +{ + builder.Services.AddDbContext(options => + options.UseSqlServer(builder.Configuration.GetConnectionString("AZURE_SQL_CONNECTIONSTRING"))); + builder.Services.AddStackExchangeRedisCache(options => + { + options.Configuration = builder.Configuration["AZURE_REDIS_CONNECTIONSTRING"]; + options.InstanceName = "SampleInstance"; + }); +} // Add services to the container. builder.Services.AddControllersWithViews();