Implemented update functionallity
All checks were successful
Updater CI/CD / publish (push) Successful in 2m18s

This commit is contained in:
2026-02-24 18:49:23 +01:00
commit a341b9cfda
16 changed files with 255 additions and 0 deletions

25
.dockerignore Normal file
View File

@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

26
.gitea/workflows/ci.yml Normal file
View File

@@ -0,0 +1,26 @@
name: Updater CI/CD
on:
push:
tags: [ "*" ]
jobs:
publish:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login git.leon-hoppe.de \
-u leon.hoppe --password-stdin
- name: Build Docker image
run: |
docker build -t git.leon-hoppe.de/leon.hoppe/updater:latest .
- name: Push Docker image
run: |
docker push git.leon-hoppe.de/leon.hoppe/updater:latest

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/

15
.idea/.idea.ServiceUpdater/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,15 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/.idea.ServiceUpdater.iml
/modules.xml
/contentModel.xml
/projectSettingsUpdater.xml
# Ignored default folder with query files
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

26
Dockerfile Normal file
View File

@@ -0,0 +1,26 @@
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
RUN apt-get update && apt-get install -y --no-install-recommends \
clang \
zlib1g-dev \
libc6-dev \
&& rm -rf /var/lib/apt/lists/*
COPY . .
RUN dotnet publish ServiceUpdater.csproj \
-c Release \
-o /app/publish \
-p:PublishAot=true \
-p:StripSymbols=true \
-p:InvariantGlobalization=true \
-r linux-x64 \
--self-contained true
FROM debian:bookworm-slim AS final
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
docker.io \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /app/publish/ServiceUpdater /app
COPY --from=build /app/publish/appsettings.json /app
RUN chmod +x /app/ServiceUpdater
ENTRYPOINT ["/app/ServiceUpdater"]

26
Program.cs Normal file
View File

@@ -0,0 +1,26 @@
using ServiceUpdater;
var builder = WebApplication.CreateSlimBuilder(args);
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.AddSingleton<UpdaterConfig>();
builder.Services.AddScoped<UpdateWorker>();
var app = builder.Build();
if (app.Environment.IsDevelopment()) {
app.MapOpenApi();
}
app.MapGet("update/{service}", async (UpdateWorker worker, string service, HttpContext context) => {
context.Response.Headers.Append("Content-Type", "text/event-stream");
await foreach (var line in worker.UpdateService(service)) {
await context.Response.WriteAsync(line + '\n');
await context.Response.Body.FlushAsync();
}
});
app.Run();

View File

@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "todos",
"applicationUrl": "http://localhost:5165",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

16
ServiceUpdater.csproj Normal file
View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>true</PublishAot>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0"/>
</ItemGroup>
</Project>

3
ServiceUpdater.slnx Normal file
View File

@@ -0,0 +1,3 @@
<Solution>
<Project Path="ServiceUpdater.csproj" />
</Solution>

58
UpdateWorker.cs Normal file
View File

@@ -0,0 +1,58 @@
using System.Diagnostics;
namespace ServiceUpdater;
public sealed class UpdateWorker(UpdaterConfig config) {
public async IAsyncEnumerable<string> UpdateService(string serviceName) {
yield return $"Starting update for {serviceName}";
await foreach (var line in RunProcess(serviceName, "compose pull")) {
yield return line;
}
yield return $"Downloaded changes for {serviceName}";
await foreach (var line in RunProcess(serviceName, "compose up -d --remove-orphans")) {
yield return line;
}
yield return $"Successfully updated {serviceName}";
}
private async IAsyncEnumerable<string> RunProcess(string folder, string arguments) {
var process = new Process {
StartInfo = new() {
FileName = "docker",
Arguments = arguments,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
WorkingDirectory = Path.Combine(config.ServicesRoot, folder)
}
};
process.Start();
var output = process.StandardOutput.ReadLineAsync();
var error = process.StandardError.ReadLineAsync();
while (true) {
var completed = await Task.WhenAny(output, error);
if (completed == output) {
var line = await output;
if (line == null) break;
yield return line;
output = process.StandardOutput.ReadLineAsync();
}
else {
var line = await error;
if (line == null) break;
yield return "[ERR] " + line;
error = process.StandardError.ReadLineAsync();
}
}
await process.WaitForExitAsync();
}
}

5
UpdaterConfig.cs Normal file
View File

@@ -0,0 +1,5 @@
namespace ServiceUpdater;
public sealed class UpdaterConfig(IConfiguration config) {
public string ServicesRoot => config["Root"] ?? "/";
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

9
appsettings.json Normal file
View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}