Skip to content

Add or update the Azure App Service build and deployment workflow config #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: starter-no-infra
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/starter-no-infra_msdocs-core-sql-555.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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-555

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'
include-prerelease: true

- 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_ACC2C22D7BF043FB87856F02B5214AA0 }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_3A6EAB9591494B9090A94F1B96DE78B4 }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_7813BF81C4234C13A9D2069A914E52C4 }}

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: 'msdocs-core-sql-555'
slot-name: 'Production'
package: .

20 changes: 10 additions & 10 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
options.UseSqlServer(builder.Configuration.GetConnectionString("MyDbConnection")));
builder.Services.AddDistributedMemoryCache();
}
// else
// {
// builder.Services.AddDbContext<MyDatabaseContext>(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<MyDatabaseContext>(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();
Expand Down
2 changes: 1 addition & 1 deletion Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<h1 class="display-4">Welcome Chema</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
2 changes: 1 addition & 1 deletion Views/Home/Privacy.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
<p>Chema, Use this page to detail your site's privacy policy.</p>
4 changes: 2 additions & 2 deletions Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
ViewData["Title"] = "Error - C";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
<h2 class="text-danger">Chema, An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
Expand Down
2 changes: 1 addition & 1 deletion Views/Todos/Create.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@model DotNetCoreSqlDb.Models.Todo

@{
ViewData["Title"] = "Create";
ViewData["Title"] = "Create - C";
}

<h1>Create</h1>
Expand Down
2 changes: 1 addition & 1 deletion Views/Todos/Delete.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@model DotNetCoreSqlDb.Models.Todo

@{
ViewData["Title"] = "Delete";
ViewData["Title"] = "Delete - C";
}

<h1>Delete</h1>
Expand Down
2 changes: 1 addition & 1 deletion Views/Todos/Details.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@model DotNetCoreSqlDb.Models.Todo

@{
ViewData["Title"] = "Details";
ViewData["Title"] = "Details - C";
}

<h1>Details</h1>
Expand Down
2 changes: 1 addition & 1 deletion Views/Todos/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@model DotNetCoreSqlDb.Models.Todo

@{
ViewData["Title"] = "Edit";
ViewData["Title"] = "Edit - C";
}

<h1>Edit</h1>
Expand Down