Skip to content

Commit e1b383f

Browse files
authored
Merge pull request #4 from NetCoreTemplates/feature/kamal-deployment
feat: add Kamal deployment configuration
2 parents 3518f56 + e456c5c commit e1b383f

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

.github/workflows/build-container.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
workflows: ["Build"]
88
types:
99
- completed
10+
branches:
11+
- main
12+
- master
1013
workflow_dispatch:
1114

1215
env:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ jobs:
101101
- name: Deploy with Kamal
102102
run: |
103103
kamal lock release -v
104-
kamal deploy -P --version latest
104+
kamal deploy -P --version latest

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+
}

config/deploy.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ service: my-app
44
# Name of the container image.
55
image: my-user/myapp
66

7+
# Required for use of ASP.NET Core with Kamal-Proxy.
78
env:
89
ASPNETCORE_FORWARDEDHEADERS_ENABLED: true
910

@@ -24,11 +25,6 @@ proxy:
2425
# kamal-proxy connects to your container over port 80, use `app_port` to specify a different port.
2526
app_port: 8080
2627

27-
healthcheck:
28-
interval: 3
29-
path: /metadata
30-
timeout: 3
31-
3228
# Credentials for your image host.
3329
registry:
3430
# Specify the registry server, if you're not using Docker Hub

0 commit comments

Comments
 (0)