3 Commits
v0.1.2 ... main

Author SHA1 Message Date
52927bf64d .gitea/workflows/release.yaml aktualisiert
All checks were successful
Release Build and Release / build-and-test (push) Successful in 54s
Release Build and Release / docker-build-and-push (push) Successful in 5m59s
2025-10-01 21:25:27 +02:00
7373ea16e0 .gitea/workflows/release.yaml aktualisiert
All checks were successful
Release Build and Release / build-and-test (push) Successful in 59s
Release Build and Release / docker-build-and-push (push) Successful in 6m22s
2025-10-01 21:16:31 +02:00
9990b35787 Merge pull request 'v0.1.1 Release' (#15) from development into main
Some checks failed
Release Build and Release / build-and-test (push) Successful in 1m14s
Release Build and Release / docker-build-and-push (push) Failing after 11s
Reviewed-on: #15
2025-10-01 21:14:21 +02:00
13 changed files with 147 additions and 361 deletions

View File

@@ -1,132 +0,0 @@
name: Gitea CI/CD
on:
workflow_dispatch:
push:
branches: [ "development", "main", "feature/*", "bugfix/*", "enhancement/*" ]
tags: [ "v*.*.*" ]
pull_request:
branches: [ "development", "main" ]
env:
DOTNET_VERSION: '8.0.x'
DOCKER_IMAGE_NAME: watcher-server
REGISTRY_URL: git.triggermeelmo.com
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
TAG: ${{ github.ref == 'refs/heads/main' && 'latest' || github.ref == 'refs/heads/development' && 'development' || github.ref_type == 'tag' && github.ref_name || 'pr' }}
jobs:
build-and-test:
runs-on: ubuntu-latest
env:
RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
continue-on-error: true
- name: Publish
run: dotnet publish -c Release -o out
set-tag:
name: Set Tag Name
runs-on: ubuntu-latest
env:
RUNNER_TOOL_CACHE: /toolcache
outputs:
tag_name: ${{ steps.set_tag.outputs.tag_name }}
steps:
- uses: actions/checkout@v4
- name: Determine next semantic version tag
id: set_tag
run: |
git fetch --tags
# Find latest tag matching vX.Y.Z
latest_tag=$(git tag --list 'v*.*.*' --sort=-v:refname | head -n 1)
if [[ -z "$latest_tag" ]]; then
major=0
minor=0
patch=0
else
version="${latest_tag#v}"
IFS='.' read -r major minor patch <<< "$version"
fi
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
major=$((major + 1))
minor=0
patch=0
elif [[ "${GITHUB_REF}" == "refs/heads/development" ]]; then
minor=$((minor + 1))
patch=0
else
patch=$((patch + 1))
fi
new_tag="v${major}.${minor}.${patch}"
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
docker-build-and-push:
runs-on: ubuntu-latest
env:
RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache
needs: [build-and-test, set-tag]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_URL}}
username: ${{ secrets.AUTOMATION_USERNAME }}
password: ${{ secrets.AUTOMATION_PASSWORD }}
- name: Build and Push Multi-Arch Docker Image
run: |
docker buildx build \
--platform ${{ env.DOCKER_PLATFORMS }} \
-t ${{ env.REGISTRY_URL }}/watcher/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.set-tag.outputs.tag_name }} \
--push .
tag:
name: Create Tag
needs: [docker-build, build, set-tag]
runs-on: ubuntu-latest
env:
RUNNER_TOOL_CACHE: /toolcache
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Git user
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: Create and push tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag ${{ needs.set-tag.outputs.tag_name }}
git push origin ${{ needs.set-tag.outputs.tag_name }}

View File

@@ -0,0 +1,63 @@
name: Development Build
on:
push:
branches:
- development
env:
DOTNET_VERSION: '8.0.x'
DOCKER_IMAGE_NAME: 'watcher-server'
REGISTRY_URL: 'git.triggermeelmo.com/watcher'
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
continue-on-error: true
- name: Publish
run: dotnet publish -c Release -o out
docker-build-and-push:
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_URL}}
username: ${{ secrets.AUTOMATION_USERNAME }}
password: ${{ secrets.AUTOMATION_PASSWORD }}
- name: Build and Push Multi-Arch Docker Image
run: |
docker buildx build \
--platform ${{ env.DOCKER_PLATFORMS }} \
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:development \
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.sha }} \
--push .

View File

@@ -0,0 +1,62 @@
name: Release Build and Release
on:
push:
branches:
- main
env:
DOTNET_VERSION: '8.0.x'
DOCKER_IMAGE_NAME: 'watcher-server'
REGISTRY_URL: 'git.triggermeelmo.com/watcher'
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
continue-on-error: true
- name: Publish
run: dotnet publish -c Release -o out
docker-build-and-push:
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Gitea Container Registry
uses: docker/login-action@v2
with:
registry: git.triggermeelmo.com
username: ${{ secrets.AUTOMATION_USERNAME }}
password: ${{ secrets.AUTOMATION_PASSWORD }}
- name: Build and Push Multi-Arch Docker Image
run: |
docker buildx build \
--platform ${{ env.DOCKER_PLATFORMS }} \
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:v0.1.1 \
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.sha }} \
--push .

View File

@@ -4,8 +4,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
// Local Namespaces
using Watcher.Data;
using Watcher.Models;
using Watcher.ViewModels;
using Watcher.Services;
namespace Watcher.Controllers
{
@@ -18,16 +18,11 @@ namespace Watcher.Controllers
// Logging einbinden
private readonly ILogger<HomeController> _logger;
// Daten der Backgroundchecks abrufen
private IDashboardStore _DashboardStore;
// HomeController Constructor
public HomeController(AppDbContext context, ILogger<HomeController> logger, IDashboardStore dashboardStore)
public HomeController(AppDbContext context, ILogger<HomeController> logger)
{
_context = context;
_logger = logger;
_DashboardStore = dashboardStore;
}
// Dashboard unter /home/index
@@ -57,11 +52,9 @@ namespace Watcher.Controllers
.ToListAsync(),
Containers = await _context.Containers
.OrderBy(s => s.Name)
.ToListAsync(),
NetworkStatus = _DashboardStore.NetworkStatus,
DatabaseStatus = _DashboardStore.DatabaseStatus
.ToListAsync()
};
//ViewBag.NetworkConnection = _NetworkCheckStore.NetworkStatus;
return View(viewModel);
}
@@ -89,18 +82,11 @@ namespace Watcher.Controllers
.ToListAsync(),
Containers = await _context.Containers
.OrderBy(s => s.Name)
.ToListAsync(),
NetworkStatus = _DashboardStore.NetworkStatus,
DatabaseStatus = _DashboardStore.DatabaseStatus
.ToListAsync()
};
return PartialView("_DashboardStats", model);
}
public String ReturnNetworkStatus()
{
return "OK";
}
}
}

View File

@@ -5,7 +5,6 @@ using Serilog;
using Watcher.Data;
using Watcher.Models;
using Watcher.Services;
//using Watcher.Services;
//using Watcher.Workers;
@@ -16,7 +15,7 @@ var builder = WebApplication.CreateBuilder(args);
// Serilog konfigurieren nur Logs, die nicht von Microsoft stammen
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning) // <--
.Enrich.FromLogContext()
.WriteTo.File(
"logs/watcher-.log",
@@ -34,13 +33,6 @@ builder.Services.AddControllersWithViews();
// HttpContentAccessor
builder.Services.AddHttpContextAccessor();
// Storage Singleton
builder.Services.AddSingleton<IDashboardStore, DashboardStore>();
// Background Services
builder.Services.AddHostedService<NetworkCheck>();
builder.Services.AddHostedService<DatabaseCheck>();
// ---------- Konfiguration ----------
DotNetEnv.Env.Load();
@@ -222,4 +214,4 @@ app.MapControllerRoute(
pattern: "{controller=Home}/{action=Index}/{id?}"
);
app.Run();
app.Run();

View File

@@ -1,8 +0,0 @@
namespace Watcher.Services;
public class DashboardStore : IDashboardStore
{
public String? NetworkStatus { get; set; }
public String? DatabaseStatus { get; set; }
}

View File

@@ -1,67 +0,0 @@
using Microsoft.Data.Sqlite;
namespace Watcher.Services;
public class DatabaseCheck : BackgroundService
{
private readonly ILogger<DatabaseCheck> _logger;
private IDashboardStore _dashboardStore;
public DatabaseCheck(ILogger<DatabaseCheck> logger, IDashboardStore dashboardStore)
{
_logger = logger;
_dashboardStore = dashboardStore;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var timer = new PeriodicTimer(TimeSpan.FromSeconds(30));
while (await timer.WaitForNextTickAsync(stoppingToken))
{
// Hintergrundprozess abwarten
await checkDatabaseIntegrity();
// 5 Sekdunden Offset
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
}
// String sqliteConnectionString als Argument übergeben
public Task checkDatabaseIntegrity()
{
using var conn = new SqliteConnection("Data Source=./persistence/watcher.db");
_logger.LogInformation("Sqlite Integrity-Check started...");
try
{
conn.Open();
using var command = conn.CreateCommand();
command.CommandText = """
SELECT integrity_check FROM pragma_integrity_check;
""";
using var reader = command.ExecuteReader();
while (reader.Read())
{
string status = reader.GetString(0);
_dashboardStore.DatabaseStatus = status;
_logger.LogInformation("Sqlite DatabaseIntegrity: ${status}", status);
}
conn.Close();
}
catch (SqliteException e)
{
conn.Close();
_logger.LogError(e.Message);
// TODO: LogEvent erstellen
}
_logger.LogInformation("Database Integrity-Check finished.");
return Task.CompletedTask;
}
}

View File

@@ -1,7 +0,0 @@
namespace Watcher.Services;
public interface IDashboardStore
{
String? NetworkStatus { get; set; }
String? DatabaseStatus { get; set; }
}

View File

@@ -1,59 +0,0 @@
using System.Net.NetworkInformation;
namespace Watcher.Services;
public class NetworkCheck : BackgroundService
{
private readonly ILogger<NetworkCheck> _logger;
private IDashboardStore _DashboardStore;
public NetworkCheck(ILogger<NetworkCheck> logger, IDashboardStore DashboardStore)
{
_logger = logger;
_DashboardStore = DashboardStore;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var timer = new PeriodicTimer(TimeSpan.FromSeconds(30));
while (await timer.WaitForNextTickAsync(stoppingToken))
{
// Hintergrundprozess abwarten
await checkConnectionAsync();
// 5 Sekdunden Offset
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
}
public Task checkConnectionAsync()
{
_logger.LogInformation("Networkcheck started.");
string host = "8.8.8.8";
Ping p = new Ping();
try
{
PingReply reply = p.Send(host, 3000);
if (reply.Status == IPStatus.Success)
{
_DashboardStore.NetworkStatus = "online";
_logger.LogInformation("Ping successfull. Watcher is online.");
}
}
catch
{
_DashboardStore.NetworkStatus = "offline";
_logger.LogError("Ping failed. Watcher appears to have no network connection.");
// LogEvent erstellen
}
_logger.LogInformation("Networkcheck finished.");
return Task.CompletedTask;
}
}

View File

@@ -14,8 +14,5 @@ namespace Watcher.ViewModels
public List<LogEvent> RecentEvents { get; set; } = new();
public List<Container> Containers { get; set; } = new();
public String? NetworkStatus { get; set; } = "?";
public String? DatabaseStatus { get; set; } = "?";
}
}

View File

@@ -1,4 +1,3 @@
@using Microsoft.IdentityModel.Tokens
@model Watcher.ViewModels.DashboardViewModel
@{
@@ -58,54 +57,18 @@
<div class="card-body">
<h5 class="fw-bold mb-3"><i class="bi bi-heart-pulse me-2 text-danger"></i>Systemstatus</h5>
@if (!Model.NetworkStatus.IsNullOrEmpty())
{
@if (Model.NetworkStatus == "online")
{
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Netzwerk</span>
<span class="badge bg-success">@Model.NetworkStatus</span>
</div>
<div class="progress mb-3" style="height: 6px;">
<div class="progress-bar bg-success w-100"></div>
</div>
} else if (Model.NetworkStatus == "offline")
{
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Netzwerk</span>
<span class="badge bg-danger">@Model.NetworkStatus</span>
</div>
<div class="progress mb-3" style="height: 6px;">
<div class="progress-bar bg-danger w-100"></div>
</div>
}
}
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Netzwerk</span>
<span class="badge bg-success">OK</span>
</div>
<div class="progress mb-3" style="height: 6px;">
<div class="progress-bar bg-success w-100"></div>
</div>
@if (!Model.DatabaseStatus.IsNullOrEmpty())
{
@if (Model.DatabaseStatus == "ok")
{
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Datenbank</span>
<span class="badge bg-success">healthy</span>
</div>
} else
{
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Datenbank</span>
<span class="badge bg-danger">unhealthy</span>
</div>
}
} else
{
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Datenbank</span>
<span class="badge bg-primary">Missing Data</span>
</div>
}
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Datenbank</span>
<span class="badge bg-success">OK</span>
</div>
<div class="progress mb-3" style="height: 6px;">
<div class="progress-bar bg-success w-100"></div>
</div>
@@ -134,7 +97,6 @@
</div>
<!-- Services -->
<!-- TODO
<div class="col-12 col-lg-6">
<div class="card shadow rounded-3 p-4 h-100">
<h2 class="h5 fw-semibold mb-3">Services</h2>
@@ -151,22 +113,20 @@
</ul>
</div>
</div>
-->
<!-- Server Liste -->
<!-- TODO
<div class="col-12 col-lg-6">
<div class="card shadow rounded-3 p-4 h-100">
<h2 class="h5 fw-semibold mb-3">Server</h2>
<ul class="list-group list-group-flush">
@foreach (Server server in Model.Servers)
@foreach (var server in Model.Servers)
{
<li class="list-group-item d-flex justify-content-between align-items-center serverlist">
<span>@server.Name</span>
<span class="badge bg-info" )">
CPU:
<span class="badge bg-info")">
CPU: 30.45%
</span>
<span class="badge bg-info" )">
<span class="badge bg-info")">
RAM: 65.09%
</span>
<span class="badge @(server.IsOnline ? "bg-success" : "bg-danger")">
@@ -176,7 +136,6 @@
}
</ul>
</div>
-->
</div>

Binary file not shown.

View File