Skip to content

Commit 3a9bf7d

Browse files
committed
test azure deployment frontend
1 parent 951c3fc commit 3a9bf7d

File tree

7 files changed

+218
-65
lines changed

7 files changed

+218
-65
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build and deploy .NET Core application to Web App ShowcaseFrontend20250815143102
2+
on:
3+
push:
4+
branches:
5+
- dockerfile-testing
6+
env:
7+
AZURE_WEBAPP_NAME: ShowcaseFrontend20250815143102
8+
AZURE_WEBAPP_PACKAGE_PATH: ShowcaseFrontend/published
9+
CONFIGURATION: Release
10+
DOTNET_CORE_VERSION: 8.0.x
11+
WORKING_DIRECTORY: ShowcaseFrontend
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Setup .NET SDK
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
21+
- name: Restore
22+
run: dotnet restore "${{ env.WORKING_DIRECTORY }}"
23+
- name: Build
24+
run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore
25+
- name: Test
26+
run: dotnet test "${{ env.WORKING_DIRECTORY }}" --no-build
27+
- name: Publish
28+
run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}"
29+
- name: Publish Artifacts
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: webapp
33+
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
34+
deploy:
35+
runs-on: ubuntu-latest
36+
needs: build
37+
steps:
38+
- name: Download artifact from build job
39+
uses: actions/download-artifact@v4
40+
with:
41+
name: webapp
42+
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
43+
- name: Azure Login
44+
uses: azure/login@v2
45+
with:
46+
creds: ${{ secrets.ShowcaseFrontend20250815143102_SPN }}
47+
- name: Deploy to Azure WebApp
48+
uses: azure/webapps-deploy@v2
49+
with:
50+
app-name: ${{ env.AZURE_WEBAPP_NAME }}
51+
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

.github/workflows/docker-image.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
11
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
22
WORKDIR /app
3-
EXPOSE 8080
4-
EXPOSE 8081
5-
6-
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS dev
7-
WORKDIR /app
8-
COPY ./ShowcaseAPI ./ShowcaseAPI
9-
WORKDIR /app/ShowcaseAPI
10-
CMD ["dotnet", "watch", "run", "--no-launch-profile", "--urls", "http://+:80"]
3+
EXPOSE 80
4+
ENV ASPNETCORE_URLS=http://+:80
115

126
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
137
WORKDIR /src
14-
COPY ["ShowcaseAPI/ShowcaseAPI.csproj", "ShowcaseAPI/"]
15-
RUN dotnet restore "ShowcaseAPI/ShowcaseAPI.csproj"
16-
8+
COPY ["ShowcaseAPI.csproj", "."]
9+
RUN dotnet restore "ShowcaseAPI.csproj"
1710
COPY . .
18-
WORKDIR "/src/ShowcaseAPI"
1911
RUN dotnet build "ShowcaseAPI.csproj" -c Release -o /app/build
2012

2113
FROM build AS publish
2214
RUN dotnet publish "ShowcaseAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false
2315

24-
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
16+
FROM base AS final
2517
WORKDIR /app
26-
27-
# https://github.com/palfrey/wait-for-db
28-
COPY ShowcaseAPI/wait-for-sql.sh .
29-
RUN chmod +x wait-for-sql.sh
30-
3118
COPY --from=publish /app/publish .
32-
33-
ENTRYPOINT ["./wait-for-sql.sh"]
19+
ENTRYPOINT ["dotnet", "ShowcaseAPI.dll"]

ShowcaseProject/ShowcaseAPI/Program.cs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
builder.Services.AddSwaggerGen();
3838

3939
builder.Services.AddDbContext<DataContext>(options =>
40-
options.UseSqlServer(Environment.GetEnvironmentVariable("DATABASE_URL")));
40+
options.UseSqlServer(Environment.GetEnvironmentVariable("DATABASE_URL")?? "Server=localhost;Database=TestDb;User Id=sa;Password=Your_password123;TrustServerCertificate=True;"));
4141

4242
builder.Services.AddAuthorization();
4343

@@ -47,11 +47,11 @@
4747

4848
var app = builder.Build();
4949
// Configure the HTTP request pipeline.
50-
if (app.Environment.IsDevelopment())
51-
{
50+
//if (app.Environment.IsDevelopment())
51+
//{
5252
app.UseSwagger();
5353
app.UseSwaggerUI();
54-
}
54+
//}
5555

5656
app.MapIdentityApi<IdentityUser>();
5757

@@ -71,31 +71,31 @@
7171

7272
app.MapControllers();
7373

74-
using (var scope = app.Services.CreateScope())
75-
{
76-
var services = scope.ServiceProvider;
77-
try
78-
{
79-
var context = services.GetRequiredService<DataContext>();
80-
context.Database.Migrate();
81-
}
82-
catch (Exception ex)
83-
{
84-
Console.WriteLine($"Database migratie mislukt: {ex.Message}");
85-
}
86-
}
87-
88-
using (var scope = app.Services.CreateScope())
89-
{
90-
var roleManager = scope.ServiceProvider.GetRequiredService<RoleManager<IdentityRole>>();
91-
var roles = new[] { "Admin", "User" };
92-
93-
foreach (var role in roles)
94-
{
95-
if (!await roleManager.RoleExistsAsync(role))
96-
{
97-
await roleManager.CreateAsync(new IdentityRole(role));
98-
}
99-
}
100-
}
74+
//using (var scope = app.Services.CreateScope())
75+
//{
76+
// var services = scope.ServiceProvider;
77+
// try
78+
// {
79+
// var context = services.GetRequiredService<DataContext>();
80+
// context.Database.Migrate();
81+
// }
82+
// catch (Exception ex)
83+
// {
84+
// Console.WriteLine($"Database migratie mislukt: {ex.Message}");
85+
// }
86+
//}
87+
88+
//using (var scope = app.Services.CreateScope())
89+
//{
90+
// var roleManager = scope.ServiceProvider.GetRequiredService<RoleManager<IdentityRole>>();
91+
// var roles = new[] { "Admin", "User" };
92+
93+
// foreach (var role in roles)
94+
// {
95+
// if (!await roleManager.RoleExistsAsync(role))
96+
// {
97+
// await roleManager.CreateAsync(new IdentityRole(role));
98+
// }
99+
// }
100+
//}
101101
app.Run();
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"metadata": {
5+
"_dependencyType": "compute.appService.windows"
6+
},
7+
"parameters": {
8+
"resourceGroupName": {
9+
"type": "string",
10+
"defaultValue": "myResourceGroup",
11+
"metadata": {
12+
"description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking."
13+
}
14+
},
15+
"resourceGroupLocation": {
16+
"type": "string",
17+
"defaultValue": "eastus",
18+
"metadata": {
19+
"description": "Location of the resource group. Resource groups could have different location than resources, however by default we use API versions from latest hybrid profile which support all locations for resource types we support."
20+
}
21+
},
22+
"resourceName": {
23+
"type": "string",
24+
"defaultValue": "showcaseerik",
25+
"metadata": {
26+
"description": "Name of the main resource to be created by this template."
27+
}
28+
},
29+
"resourceLocation": {
30+
"type": "string",
31+
"defaultValue": "[parameters('resourceGroupLocation')]",
32+
"metadata": {
33+
"description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there."
34+
}
35+
}
36+
},
37+
"variables": {
38+
"appServicePlan_name": "[concat('Plan', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
39+
"appServicePlan_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/serverFarms/', variables('appServicePlan_name'))]"
40+
},
41+
"resources": [
42+
{
43+
"type": "Microsoft.Resources/resourceGroups",
44+
"name": "[parameters('resourceGroupName')]",
45+
"location": "[parameters('resourceGroupLocation')]",
46+
"apiVersion": "2019-10-01"
47+
},
48+
{
49+
"type": "Microsoft.Resources/deployments",
50+
"name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
51+
"resourceGroup": "[parameters('resourceGroupName')]",
52+
"apiVersion": "2019-10-01",
53+
"dependsOn": [
54+
"[parameters('resourceGroupName')]"
55+
],
56+
"properties": {
57+
"mode": "Incremental",
58+
"template": {
59+
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
60+
"contentVersion": "1.0.0.0",
61+
"resources": [
62+
{
63+
"location": "[parameters('resourceLocation')]",
64+
"name": "[parameters('resourceName')]",
65+
"type": "Microsoft.Web/sites",
66+
"apiVersion": "2015-08-01",
67+
"tags": {
68+
"[concat('hidden-related:', variables('appServicePlan_ResourceId'))]": "empty"
69+
},
70+
"dependsOn": [
71+
"[variables('appServicePlan_ResourceId')]"
72+
],
73+
"kind": "app",
74+
"properties": {
75+
"name": "[parameters('resourceName')]",
76+
"kind": "app",
77+
"httpsOnly": true,
78+
"reserved": false,
79+
"serverFarmId": "[variables('appServicePlan_ResourceId')]",
80+
"siteConfig": {
81+
"metadata": [
82+
{
83+
"name": "CURRENT_STACK",
84+
"value": "dotnetcore"
85+
}
86+
]
87+
}
88+
},
89+
"identity": {
90+
"type": "SystemAssigned"
91+
}
92+
},
93+
{
94+
"location": "[parameters('resourceLocation')]",
95+
"name": "[variables('appServicePlan_name')]",
96+
"type": "Microsoft.Web/serverFarms",
97+
"apiVersion": "2015-08-01",
98+
"sku": {
99+
"name": "S1",
100+
"tier": "Standard",
101+
"family": "S",
102+
"size": "S1"
103+
},
104+
"properties": {
105+
"name": "[variables('appServicePlan_name')]"
106+
}
107+
}
108+
]
109+
}
110+
}
111+
}
112+
]
113+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"dependencies": {
3+
"compute.appService1": {
4+
"group": "connections",
5+
"type": "compute.appService"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"dependencies": {
3+
"compute.appService1": {
4+
"group": "connections",
5+
"resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/Microsoft.Web/sites/showcaseerik",
6+
"type": "compute.appService.windows"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)