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..74c47dd55 --- /dev/null +++ b/.github/workflows/starter-no-infra_msdocs-core-sql-tutorial-si.yml @@ -0,0 +1,74 @@ +# 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: Install dotnet ef + 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 + + - 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 diff --git a/Program.cs b/Program.cs index ffa365722..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();