Skip to content
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
65 changes: 65 additions & 0 deletions .github/workflows/main_vhlr2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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 - VHLR2

on:
push:
branches:
- main
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
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_CD9400597E8D4878A2DB8746D8CBC3A0 }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_19BA0BCCDD0E4686961924AA90B3E565 }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_A443A7B2260D4B948EBD9885F96883FD }}

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

74 changes: 74 additions & 0 deletions .github/workflows/main_webappanddatabase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build and deploy ASP.Net Core app to Azure Web App - WebAppAndDataBase

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

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

# --- EF CORE MIGRATIONS (� �����������) ---
- name: Install EF Core Tool
run: dotnet tool install -g dotnet-ef --version 7.0.14

- name: Create migration bundle
run: |
PROJECT_PATH=$(find . -name "*.csproj" -print -quit)
echo "Found project at: $PROJECT_PATH"
dotnet ef migrations bundle --runtime linux-x64 -p "$PROJECT_PATH" -o ${{env.DOTNET_ROOT}}/myapp/migrate
# ------------------------------------------

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp

deploy:
runs-on: ubuntu-latest
needs: build
permissions:
id-token: write
contents: read

steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: .net-app

- name: Login to Azure
uses: azure/login@v2
with:
# ����� �����Ҳ� ���Ҳ � ������ ��в�����:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_CD9400597E8D4878A2DB8746D8CBC3A0 }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_19BA0BCCDD0E4686961924AA90B3E565 }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_A443A7B2260D4B948EBD9885F96883FD }}

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: 'VHLR2'
slot-name: 'Production'
package: .
startup-command: 'dotnet DotNetCoreSqlDb.dll'
30 changes: 13 additions & 17 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@
using DotNetCoreSqlDb.Data;
var builder = WebApplication.CreateBuilder(args);

// Add database context and cache
if(builder.Environment.IsDevelopment())
builder.Services.AddDbContext<MyDatabaseContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("AZURE_SQL_CONNECTIONSTRING")));
builder.Services.AddStackExchangeRedisCache(options =>
{
builder.Services.AddDbContext<MyDatabaseContext>(options =>
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.Configuration = Environment.GetEnvironmentVariable("AZURE_REDIS_REDISCONNECTOR_CONNECTIONSTRING")
?? builder.Configuration.GetConnectionString("AZURE_REDIS_REDISCONNECTOR_CONNECTIONSTRING");
options.InstanceName = "SampleInstance";
});
}

});

// Add services to the container.
builder.Services.AddControllersWithViews();
Expand All @@ -29,7 +19,13 @@

var app = builder.Build();

// Configure the HTTP request pipeline.
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = services.GetRequiredService<MyDatabaseContext>();
context.Database.Migrate();
}

if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
Expand Down
6 changes: 2 additions & 4 deletions appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
// The following connection string works for running the .NET application in the dev container.
// If running this project in Visual Studio in Windows, use the commented connection string instead.
"MyDbConnection": "Server=localhost;Database=ApplicationDB;User Id=sa;Password=P@ssw0rd;TrustServerCertificate=True;MultipleActiveResultSets=true"
//"MyDbConnection": "Server=(localdb)\\mssqllocaldb;Database=MyDatabaseContext-8e1630ac-d3ae-4719-955b-5d3235f3fadf;Trusted_Connection=True;MultipleActiveResultSets=true"
"AZURE_SQL_CONNECTIONSTRING": "Data Source=webappanddatabase-server.database.windows.net,1433;Initial Catalog=webappanddatabase-database;User ID=webappanddatabase-server-admin;Password=xLspxkWrNpiqp$kY",
"AZURE_REDIS_REDISCONNECTOR_CONNECTIONSTRING": "vhlr-cache.redis.cache.windows.net:6380,password=ByFyKv1DX1yMLHrOdLp0VOelwtEmvnidkAzCaBkpzkE=,ssl=True,abortConnect=False"
}
}