From 91261667198dd93a60a42b3c4bf577b01d37bf79 Mon Sep 17 00:00:00 2001 From: Darren Reid Date: Tue, 26 Nov 2024 16:41:25 +1100 Subject: [PATCH 1/3] feat: add Kamal deployment configuration --- MyApp/Configure.HealthChecks.cs | 37 +++++++++++++++++++++++++++++++++ config/deploy.yml | 9 ++++---- 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 MyApp/Configure.HealthChecks.cs diff --git a/MyApp/Configure.HealthChecks.cs b/MyApp/Configure.HealthChecks.cs new file mode 100644 index 0000000..dbbb700 --- /dev/null +++ b/MyApp/Configure.HealthChecks.cs @@ -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 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"); + + services.AddTransient(); + }); + } + + public class StartupFilter : IStartupFilter + { + public Action Configure(Action next) + => app => { + app.UseHealthChecks("/up"); + next(app); + }; + } +} \ No newline at end of file diff --git a/config/deploy.yml b/config/deploy.yml index 56e655c..2bab8a4 100644 --- a/config/deploy.yml +++ b/config/deploy.yml @@ -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. @@ -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 From 07db27e017724db2521eeb33af00081f0883a643 Mon Sep 17 00:00:00 2001 From: Darren Reid Date: Tue, 26 Nov 2024 17:06:53 +1100 Subject: [PATCH 2/3] Update workflows --- .github/workflows/build-container.yml | 3 +++ .github/workflows/release.yml | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml index 82925e1..66130ac 100644 --- a/.github/workflows/build-container.yml +++ b/.github/workflows/build-container.yml @@ -7,6 +7,9 @@ on: workflows: ["Build"] types: - completed + branches: + - main + - master workflow_dispatch: env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6a41086..0bd5ad4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,6 +7,9 @@ on: workflows: ["Build Container"] types: - completed + branches: + - main + - master workflow_dispatch: env: @@ -98,4 +101,4 @@ jobs: - name: Deploy with Kamal run: | kamal lock release -v - kamal deploy -P --version latest \ No newline at end of file + kamal deploy -P --version latest From 055c38a1ed49791f937f901c677841d679c042cd Mon Sep 17 00:00:00 2001 From: Darren Reid Date: Tue, 26 Nov 2024 17:10:46 +1100 Subject: [PATCH 3/3] Update workflows --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0bd5ad4..a2dd9ca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -71,7 +71,7 @@ jobs: bundler-cache: true - name: Install Kamal - run: gem install kamal -v 2.2.2 + run: gem install kamal -v 2.3.0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3