Skip to content

Commit 0189abf

Browse files
committed
Fix build container, and add Configure.HealthChecks.cs.
1 parent 37264c4 commit 0189abf

2 files changed

Lines changed: 41 additions & 9 deletions

File tree

.github/workflows/build-container.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,10 @@ jobs:
4242
echo "HAS_DEPLOY_ACTION=false" >> $GITHUB_ENV
4343
fi
4444
45-
# This step is for the deployment of the templates only, safe to delete
46-
- name: Modify csproj for template deploy
47-
if: env.HAS_DEPLOY_ACTION == 'true'
48-
run: |
49-
sed -i 's#<ContainerLabel Include="service" Value="blazor-gallery" />#<ContainerLabel Include="service" Value="${{ env.repository_name_lower }}" />#g' BlazorGallery/BlazorGallery.csproj
50-
5145
- name: Check for Client directory and package.json
5246
id: check_client
5347
run: |
54-
if [ -d "BlazorGallery.Client" ] && [ -f "BlazorGallery.Client/package.json" ]; then
48+
if [ -d "MyApp.Client" ] && [ -f "MyApp.Client/package.json" ]; then
5549
echo "client_exists=true" >> $GITHUB_OUTPUT
5650
else
5751
echo "client_exists=false" >> $GITHUB_OUTPUT
@@ -65,15 +59,15 @@ jobs:
6559

6660
- name: Install npm dependencies
6761
if: steps.check_client.outputs.client_exists == 'true'
68-
working-directory: ./BlazorGallery.Client
62+
working-directory: ./MyApp.Client
6963
run: npm install
7064

7165
- name: Install x tool
7266
run: dotnet tool install -g x
7367

7468
- name: Apply Production AppSettings
7569
if: env.HAS_APPSETTINGS_PATCH == 'true'
76-
working-directory: ./BlazorGallery
70+
working-directory: ./MyApp
7771
run: |
7872
cat <<EOF >> appsettings.json.patch
7973
${{ secrets.APPSETTINGS_PATCH }}
@@ -93,5 +87,6 @@ jobs:
9387
dotnet-version: '8.0'
9488

9589
- name: Build and push Docker image
90+
working-directory: ./MyApp
9691
run: |
9792
dotnet publish --os linux --arch x64 -c Release -p:ContainerRepository=${{ env.image_repository_name }} -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest -p:ContainerPort=80

MyApp/Configure.HealthChecks.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Microsoft.Extensions.Diagnostics.HealthChecks;
2+
3+
[assembly: HostingStartup(typeof(MyApp.HealthChecks))]
4+
5+
namespace MyApp;
6+
7+
public class HealthChecks : IHostingStartup
8+
{
9+
public class HealthCheck : IHealthCheck
10+
{
11+
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken token = default)
12+
{
13+
// Perform health check logic here
14+
return HealthCheckResult.Healthy();
15+
}
16+
}
17+
18+
public void Configure(IWebHostBuilder builder)
19+
{
20+
builder.ConfigureServices(services =>
21+
{
22+
services.AddHealthChecks()
23+
.AddCheck<HealthCheck>("HealthCheck");
24+
25+
services.AddTransient<IStartupFilter, StartupFilter>();
26+
});
27+
}
28+
29+
public class StartupFilter : IStartupFilter
30+
{
31+
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
32+
=> app => {
33+
app.UseHealthChecks("/up");
34+
next(app);
35+
};
36+
}
37+
}

0 commit comments

Comments
 (0)