Compare commits
18 Commits
fe45d901e4
...
enhancemen
Author | SHA1 | Date | |
---|---|---|---|
f207440ae6 | |||
ef187f8750 | |||
570b5abfa0 | |||
8f938f999e | |||
2249d1a776 | |||
37de21f06b | |||
b9d5ade0f1 | |||
921b4a9664 | |||
0e9555e3f7 | |||
19c7aaaca1 | |||
068c67d0d9 | |||
4c6635f989 | |||
98080df509 | |||
286f72eac7 | |||
d49977815d | |||
b012693c21 | |||
e385eb94f4 | |||
285ff89cb0 |
@@ -2,25 +2,22 @@ name: Gitea CI/CD
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
#push:
|
push:
|
||||||
#branches: [ "development", "main", "staging"]
|
branches: [ "development", "main", "staging" ]
|
||||||
#tags: [ "v*.*.*" ]
|
|
||||||
pull_request:
|
|
||||||
#branches: [ "development", "main", "staging" ]
|
|
||||||
tags: [ "v*.*.*" ]
|
tags: [ "v*.*.*" ]
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
packages: write
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DOTNET_VERSION: '8.0.x'
|
DOTNET_VERSION: '8.0.x'
|
||||||
DOCKER_IMAGE_NAME: watcher-server
|
DOCKER_IMAGE_NAME: watcher-server
|
||||||
REGISTRY_URL: git.triggermeelmo.com
|
REGISTRY_URL: git.triggermeelmo.com
|
||||||
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
|
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-test:
|
dotnet-build-and-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
@@ -46,13 +43,14 @@ jobs:
|
|||||||
|
|
||||||
set-tag:
|
set-tag:
|
||||||
name: Set Tag Name
|
name: Set Tag Name
|
||||||
|
needs: [dotnet-build-and-test]
|
||||||
|
#if: ${{ !failure() && !cancelled() && github.event_name != 'pull_request' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
tag_name: ${{ steps.set_tag.outputs.tag_name }}
|
tag_name: ${{ steps.set_tag.outputs.tag_name }}
|
||||||
|
should_tag: ${{ steps.set_tag.outputs.should_tag }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Determine next semantic version tag
|
- name: Determine next semantic version tag
|
||||||
id: set_tag
|
id: set_tag
|
||||||
@@ -74,20 +72,33 @@ jobs:
|
|||||||
major=$((major + 1))
|
major=$((major + 1))
|
||||||
minor=0
|
minor=0
|
||||||
patch=0
|
patch=0
|
||||||
|
new_tag="v${major}.${minor}.${patch}"
|
||||||
|
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
||||||
|
echo "should_tag=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "Creating new major version tag: ${new_tag}"
|
||||||
|
|
||||||
elif [[ "${GITHUB_REF}" == "refs/heads/development" ]]; then
|
elif [[ "${GITHUB_REF}" == "refs/heads/development" ]]; then
|
||||||
minor=$((minor + 1))
|
minor=$((minor + 1))
|
||||||
patch=0
|
patch=0
|
||||||
|
new_tag="v${major}.${minor}.${patch}"
|
||||||
|
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
||||||
|
echo "should_tag=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "Creating new minor version tag: ${new_tag}"
|
||||||
|
|
||||||
elif [[ "${GITHUB_REF}" == "refs/heads/staging" ]]; then
|
elif [[ "${GITHUB_REF}" == "refs/heads/staging" ]]; then
|
||||||
patch=$((patch + 1))
|
patch=$((patch + 1))
|
||||||
fi
|
|
||||||
|
|
||||||
new_tag="v${major}.${minor}.${patch}"
|
new_tag="v${major}.${minor}.${patch}"
|
||||||
echo "Creating new version tag: ${new_tag}"
|
|
||||||
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
||||||
|
echo "should_tag=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "Creating new patch version tag: ${new_tag}"
|
||||||
|
fi
|
||||||
|
|
||||||
docker-build-and-push:
|
docker-build-and-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [build-and-test, set-tag]
|
needs: [dotnet-build-and-test, set-tag]
|
||||||
|
if: |
|
||||||
|
needs.set-tag.outputs.should_tag == 'true' &&
|
||||||
|
github.event_name != 'pull_request'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -111,37 +122,25 @@ jobs:
|
|||||||
|
|
||||||
tag:
|
tag:
|
||||||
name: Create Tag
|
name: Create Tag
|
||||||
needs: [docker-build-and-push]
|
needs: [docker-build-and-push, set-tag]
|
||||||
|
if: |
|
||||||
|
needs.set-tag.outputs.should_tag == 'true' &&
|
||||||
|
github.event_name != 'pull_request'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Check if tag already exists
|
- name: Set up Git user
|
||||||
id: check_tag
|
|
||||||
run: |
|
run: |
|
||||||
git fetch --tags
|
|
||||||
if git rev-parse "${{ needs.set-tag.outputs.tag_name }}" >/dev/null 2>&1; then
|
|
||||||
echo "Tag ${{ needs.set-tag.outputs.tag_name }} already exists!"
|
|
||||||
echo "exists=true" >> $GITHUB_OUTPUT
|
|
||||||
else
|
|
||||||
echo "Tag ${{ needs.set-tag.outputs.tag_name }} does not exist"
|
|
||||||
echo "exists=false" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Create and push tag
|
|
||||||
if: steps.check_tag.outputs.exists == 'false'
|
|
||||||
run: |
|
|
||||||
echo "Creating new tag: ${{ needs.set-tag.outputs.tag_name }}"
|
|
||||||
git config user.name "GitHub Actions"
|
git config user.name "GitHub Actions"
|
||||||
git config user.email "actions@github.com"
|
git config user.email "actions@github.com"
|
||||||
git tag ${{ needs.set-tag.outputs.tag_name }}
|
|
||||||
git push -u origin ${{ needs.set-tag.outputs.tag_name }}
|
|
||||||
echo "Tag created and pushed successfully"
|
|
||||||
|
|
||||||
- name: Skip tag creation
|
- name: Create and push tag
|
||||||
if: steps.check_tag.outputs.exists == 'true'
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
echo "Skipping tag creation - ${{ needs.set-tag.outputs.tag_name }} already exists"
|
echo "Creating new tag: ${{ needs.set-tag.outputs.tag_name }}"
|
||||||
|
git tag ${{ needs.set-tag.outputs.tag_name }}
|
||||||
|
git push origin ${{ needs.set-tag.outputs.tag_name }}
|
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
@@ -36,11 +37,17 @@ builder.Services.AddHttpContextAccessor();
|
|||||||
|
|
||||||
// Storage Singleton
|
// Storage Singleton
|
||||||
builder.Services.AddSingleton<IDashboardStore, DashboardStore>();
|
builder.Services.AddSingleton<IDashboardStore, DashboardStore>();
|
||||||
|
builder.Services.AddSingleton<ISystemStore, SystemStore>();
|
||||||
|
|
||||||
// Background Services
|
// Background Services
|
||||||
builder.Services.AddHostedService<NetworkCheck>();
|
builder.Services.AddHostedService<NetworkCheck>();
|
||||||
builder.Services.AddHostedService<DatabaseCheck>();
|
builder.Services.AddHostedService<DatabaseCheck>();
|
||||||
|
|
||||||
|
// Swagger API-Dokumentation
|
||||||
|
builder.Services.AddSwaggerGen(options =>
|
||||||
|
{
|
||||||
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Watcher-Server API", Version = "v1" });
|
||||||
|
});
|
||||||
|
|
||||||
// ---------- Konfiguration ----------
|
// ---------- Konfiguration ----------
|
||||||
DotNetEnv.Env.Load();
|
DotNetEnv.Env.Load();
|
||||||
@@ -212,6 +219,8 @@ if (!app.Environment.IsDevelopment())
|
|||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
app.UseSwagger();
|
||||||
|
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
@@ -222,4 +231,11 @@ app.MapControllerRoute(
|
|||||||
pattern: "{controller=Home}/{action=Index}/{id?}"
|
pattern: "{controller=Home}/{action=Index}/{id?}"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app.MapSwagger();
|
||||||
|
|
||||||
|
app.UseSwaggerUI(options =>
|
||||||
|
{
|
||||||
|
options.SwaggerEndpoint("v1/swagger.json", "Watcher-Server API v1");
|
||||||
|
});
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
9
Watcher/Services/ISystemStore.cs
Normal file
9
Watcher/Services/ISystemStore.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Watcher.Services;
|
||||||
|
|
||||||
|
public interface ISystemStore
|
||||||
|
{
|
||||||
|
Boolean NewVersionAvailable { get; set; }
|
||||||
|
|
||||||
|
Double DatabaseSize { get; set; }
|
||||||
|
|
||||||
|
}
|
42
Watcher/Services/SystemMangement.cs
Normal file
42
Watcher/Services/SystemMangement.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Net.Http;
|
||||||
|
|
||||||
|
namespace Watcher.Services;
|
||||||
|
|
||||||
|
public class SystemManagement : BackgroundService
|
||||||
|
{
|
||||||
|
private readonly ILogger<NetworkCheck> _logger;
|
||||||
|
|
||||||
|
private ISystemStore _SystemStore;
|
||||||
|
|
||||||
|
public SystemManagement(ILogger<NetworkCheck> logger, ISystemStore SystemStore)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_SystemStore = SystemStore;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
// Todo: Umstellen auf einmal alle 24h
|
||||||
|
var timer = new PeriodicTimer(TimeSpan.FromSeconds(30));
|
||||||
|
|
||||||
|
while (await timer.WaitForNextTickAsync(stoppingToken))
|
||||||
|
{
|
||||||
|
// Hintergrundprozess abwarten
|
||||||
|
await checkForNewDockerImageVersion();
|
||||||
|
|
||||||
|
// 5 Sekdunden Offset
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task checkForNewDockerImageVersion()
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task createDailySqliteBackup()
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
9
Watcher/Services/SystemStore.cs
Normal file
9
Watcher/Services/SystemStore.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Watcher.Services;
|
||||||
|
|
||||||
|
public class SystemStore: ISystemStore
|
||||||
|
{
|
||||||
|
public Boolean NewVersionAvailable { get; set; }
|
||||||
|
|
||||||
|
public Double DatabaseSize { get; set; }
|
||||||
|
|
||||||
|
}
|
@@ -23,6 +23,7 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.6" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.6" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Reference in New Issue
Block a user