Skip to content

Commit

Permalink
Merge pull request #5 from NetCoreTemplates/feature/kamal-deployment
Browse files Browse the repository at this point in the history
Feature/kamal deployment
  • Loading branch information
Layoric authored Nov 26, 2024
2 parents 8a30c3f + 3e3a17f commit fa80652
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
7 changes: 5 additions & 2 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 Expand Up @@ -45,10 +48,10 @@ jobs:
run: |
sed -i 's#<ContainerLabel Include="service" Value="my-app" />#<ContainerLabel Include="service" Value="${{ env.repository_name_lower }}" />#g' MyApp/MyApp.csproj
- name: Check for Client directory
- name: Check for Client directory and package.json
id: check_client
run: |
if [ -d "MyApp.Client" ]; then
if [ -d "MyApp.Client" ] && [ -f "MyApp.Client/package.json" ]; then
echo "client_exists=true" >> $GITHUB_OUTPUT
else
echo "client_exists=false" >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ jobs:
- name: Deploy with Kamal
run: |
kamal lock release -v
kamal deploy -P --version latest
kamal deploy -P --version latest
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)

Check warning on line 11 in MyApp/Configure.HealthChecks.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
// 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);
};
}
}
1 change: 1 addition & 0 deletions MyApp/MyApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ItemGroup>
<ContainerLabel Include="service" Value="my-app" />
</ItemGroup>

<ItemGroup>
<Using Include="MyApp" />
<Using Include="MyApp.Data" />
Expand Down
6 changes: 1 addition & 5 deletions config/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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

Expand All @@ -24,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 fa80652

Please sign in to comment.