Skip to content

Commit

Permalink
Merge pull request #4 from NetCoreTemplates/feature/kamal-deployment
Browse files Browse the repository at this point in the history
feat: add Kamal deployment configuration
  • Loading branch information
Layoric authored Nov 26, 2024
2 parents ea2ee98 + 055c38a commit 12e103e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
workflows: ["Build"]
types:
- completed
branches:
- main
- master
workflow_dispatch:

env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
- master
types:
- completed
branches:
- main
- master
workflow_dispatch:

env:
Expand Down
37 changes: 37 additions & 0 deletions MyApp/Configure.HealthChecks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.Extensions.Diagnostics.HealthChecks;

[assembly: HostingStartup(typeof(MyApp.HealthChecks))]

namespace MyApp;

public class HealthChecks : IHostingStartup
{
public class HealthCheck : IHealthCheck
{
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken token = default)
{
// Perform health check logic here
return HealthCheckResult.Healthy();
}
}

public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddCheck<HealthCheck>("HealthCheck");

services.AddTransient<IStartupFilter, StartupFilter>();
});
}

public class StartupFilter : IStartupFilter
{
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
=> app => {
app.UseHealthChecks("/up");
next(app);
};
}
}
9 changes: 4 additions & 5 deletions config/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ service: my-app
# Name of the container image.
image: my-user/myapp

# Required for use of ASP.NET Core with Kamal-Proxy.
env:
ASPNETCORE_FORWARDEDHEADERS_ENABLED: true

# Deploy to these servers.
servers:
# IP address of server, optionally use env variable.
Expand All @@ -21,11 +25,6 @@ proxy:
# kamal-proxy connects to your container over port 80, use `app_port` to specify a different port.
app_port: 8080

healthcheck:
interval: 3
path: /metadata
timeout: 3

# Credentials for your image host.
registry:
# Specify the registry server, if you're not using Docker Hub
Expand Down

0 comments on commit 12e103e

Please sign in to comment.