Skip to content

Commit 8b530b8

Browse files
Add project files.
1 parent fddba3a commit 8b530b8

File tree

15 files changed

+474
-0
lines changed

15 files changed

+474
-0
lines changed

.github/workflows/ci-cd.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: CI CD
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
release:
9+
types: [created]
10+
11+
env:
12+
CONFIGURATION: Release
13+
14+
jobs:
15+
16+
build:
17+
runs-on: ubuntu-latest
18+
name: Build and test
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Setup
22+
uses: actions/setup-dotnet@v1
23+
with:
24+
dotnet-version: 5.0.101
25+
- name: Build
26+
run: dotnet build --configuration ${{ env.CONFIGURATION }}
27+
28+
github-package-deploy:
29+
if: ${{ github.event_name == 'push' }}
30+
name: GitHub package deploy
31+
runs-on: ubuntu-latest
32+
needs: build
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v2
36+
- name: Setup .NET
37+
uses: actions/setup-dotnet@v1
38+
with:
39+
dotnet-version: 5.0.101
40+
- name: Publish
41+
run: dotnet publish --configuration ${{ env.CONFIGURATION }} -o '/publish'
42+
- name: Docker build
43+
run: docker build -f 'HttpHealthCheckDashboard/Dockerfile' -t docker.pkg.github.com/arnab-developer/httphealthcheckdashboard/httphealthcheckdashboard:1.0.0 .
44+
- name: Docker push
45+
run: |
46+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://docker.pkg.github.com -u Arnab-Developer --password-stdin
47+
docker push docker.pkg.github.com/arnab-developer/httphealthcheckdashboard/httphealthcheckdashboard:1.0.0
48+
49+
dockerhub-deploy:
50+
if: ${{ github.event_name == 'release' }}
51+
name: Dockerhub deploy
52+
runs-on: ubuntu-latest
53+
needs: build
54+
environment:
55+
name: Dockerhub
56+
url: https://hub.docker.com/r/45862391/httphealthcheckdashboard
57+
steps:
58+
- name: Checkout code
59+
uses: actions/checkout@v2
60+
- name: Setup .NET
61+
uses: actions/setup-dotnet@v1
62+
with:
63+
dotnet-version: 5.0.101
64+
- name: Publish
65+
run: dotnet publish --configuration ${{ env.CONFIGURATION }} -o '/publish'
66+
- name: Docker build
67+
run: docker build -f 'HttpHealthCheckDashboard/Dockerfile' -t 45862391/httphealthcheckdashboard:1.0.0 .
68+
- name: Docker push
69+
run: |
70+
echo "${{ secrets.DOCKERHUB_PWD }}" | docker login -u 45862391 --password-stdin
71+
docker push 45862391/httphealthcheckdashboard:1.0.0

HttpHealthCheckDashboard.sln

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31205.134
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpHealthCheckDashboard", "HttpHealthCheckDashboard\HttpHealthCheckDashboard.csproj", "{81264DB3-4F19-41C5-BF71-8D60E4C30C33}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BEA568BE-F115-4324-AF27-238C19C48EA8}"
9+
ProjectSection(SolutionItems) = preProject
10+
.github\workflows\ci-cd.yml = .github\workflows\ci-cd.yml
11+
LICENSE = LICENSE
12+
README.md = README.md
13+
EndProjectSection
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{81264DB3-4F19-41C5-BF71-8D60E4C30C33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{81264DB3-4F19-41C5-BF71-8D60E4C30C33}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{81264DB3-4F19-41C5-BF71-8D60E4C30C33}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{81264DB3-4F19-41C5-BF71-8D60E4C30C33}.Release|Any CPU.Build.0 = Release|Any CPU
25+
EndGlobalSection
26+
GlobalSection(SolutionProperties) = preSolution
27+
HideSolutionNode = FALSE
28+
EndGlobalSection
29+
GlobalSection(ExtensibilityGlobals) = postSolution
30+
SolutionGuid = {DAD9DD26-470C-4C43-9132-DA5CACB837DA}
31+
EndGlobalSection
32+
EndGlobal
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM mcr.microsoft.com/dotnet/runtime:5.0
2+
COPY publish/ ./app
3+
WORKDIR /app
4+
ENTRYPOINT ["dotnet", "HttpHealthCheckDashboard.dll"]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using ArnabDeveloper.HttpHealthCheck;
2+
3+
namespace HttpHealthCheckDashboard.HealthChecks
4+
{
5+
internal class CommonHealthCheck : ICommonHealthCheck
6+
{
7+
private readonly IHealthCheck _healthCheck;
8+
9+
public CommonHealthCheck(IHealthCheck healthCheck)
10+
{
11+
_healthCheck = healthCheck;
12+
}
13+
14+
bool ICommonHealthCheck.IsApiHealthy(ApiDetail? apiDetail)
15+
{
16+
if (apiDetail == null)
17+
{
18+
return false;
19+
}
20+
try
21+
{
22+
bool isApiHealthy = false;
23+
if (apiDetail.ApiCredential is null ||
24+
string.IsNullOrWhiteSpace(apiDetail.ApiCredential.UserName) ||
25+
string.IsNullOrWhiteSpace(apiDetail.ApiCredential.Password))
26+
{
27+
isApiHealthy = _healthCheck.IsHealthy(apiDetail.Url);
28+
}
29+
else
30+
{
31+
isApiHealthy = _healthCheck.IsHealthy(apiDetail.Url, apiDetail.ApiCredential);
32+
}
33+
return isApiHealthy;
34+
}
35+
catch
36+
{
37+
return false;
38+
}
39+
}
40+
}
41+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using ArnabDeveloper.HttpHealthCheck;
2+
using Microsoft.Extensions.Diagnostics.HealthChecks;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace HttpHealthCheckDashboard.HealthChecks
9+
{
10+
internal class GoogleHealthCheck
11+
: Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck
12+
{
13+
private readonly IEnumerable<ApiDetail> _urlDetails;
14+
private readonly ICommonHealthCheck _commonHealthCheck;
15+
16+
public GoogleHealthCheck(IEnumerable<ApiDetail> urlDetails,
17+
ICommonHealthCheck commonHealthCheck)
18+
{
19+
_urlDetails = urlDetails;
20+
_commonHealthCheck = commonHealthCheck;
21+
}
22+
23+
Task<HealthCheckResult> Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck.CheckHealthAsync(
24+
HealthCheckContext context, CancellationToken cancellationToken)
25+
{
26+
ApiDetail? apiDetail = _urlDetails.FirstOrDefault(u => u.Name == "Google");
27+
28+
return _commonHealthCheck.IsApiHealthy(apiDetail)
29+
? Task.FromResult(HealthCheckResult.Healthy())
30+
: Task.FromResult(HealthCheckResult.Unhealthy());
31+
}
32+
}
33+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using ArnabDeveloper.HttpHealthCheck;
2+
3+
namespace HttpHealthCheckDashboard.HealthChecks
4+
{
5+
public interface ICommonHealthCheck
6+
{
7+
bool IsApiHealthy(ApiDetail? apiDetail);
8+
}
9+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using ArnabDeveloper.HttpHealthCheck;
2+
using Microsoft.Extensions.Diagnostics.HealthChecks;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace HttpHealthCheckDashboard.HealthChecks
9+
{
10+
internal class MicrosoftHealthCheck
11+
: Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck
12+
{
13+
private readonly IEnumerable<ApiDetail> _urlDetails;
14+
private readonly ICommonHealthCheck _commonHealthCheck;
15+
16+
public MicrosoftHealthCheck(IEnumerable<ApiDetail> urlDetails,
17+
ICommonHealthCheck commonHealthCheck)
18+
{
19+
_urlDetails = urlDetails;
20+
_commonHealthCheck = commonHealthCheck;
21+
}
22+
23+
Task<HealthCheckResult> Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck.CheckHealthAsync(
24+
HealthCheckContext context, CancellationToken cancellationToken)
25+
{
26+
ApiDetail? apiDetail = _urlDetails.FirstOrDefault(u => u.Name == "Microsoft");
27+
28+
return _commonHealthCheck.IsApiHealthy(apiDetail)
29+
? Task.FromResult(HealthCheckResult.Healthy())
30+
: Task.FromResult(HealthCheckResult.Unhealthy());
31+
}
32+
}
33+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<LangVersion>9</LangVersion>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="ArnabDeveloper.HttpHealthCheck" Version="1.0.0" />
11+
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="5.0.1" />
12+
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="5.0.1" />
13+
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="5.0.1" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
4+
namespace HttpHealthCheckDashboard
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
CreateHostBuilder(args).Build().Run();
11+
}
12+
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
19+
}
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:30901",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"HttpHealthCheckDashboard": {
19+
"commandName": "Project",
20+
"dotnetRunMessages": "true",
21+
"launchBrowser": true,
22+
"applicationUrl": "http://localhost:5000",
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT": "Development"
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)