Implemented update functionallity
All checks were successful
Updater CI/CD / publish (push) Successful in 2m18s
All checks were successful
Updater CI/CD / publish (push) Successful in 2m18s
This commit is contained in:
25
.dockerignore
Normal file
25
.dockerignore
Normal 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
26
.gitea/workflows/ci.yml
Normal 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
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/packages/
|
||||||
|
riderModule.iml
|
||||||
|
/_ReSharper.Caches/
|
||||||
15
.idea/.idea.ServiceUpdater/.idea/.gitignore
generated
vendored
Normal file
15
.idea/.idea.ServiceUpdater/.idea/.gitignore
generated
vendored
Normal 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/
|
||||||
4
.idea/.idea.ServiceUpdater/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.ServiceUpdater/.idea/encodings.xml
generated
Normal 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>
|
||||||
8
.idea/.idea.ServiceUpdater/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.ServiceUpdater/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/.idea.ServiceUpdater/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.ServiceUpdater/.idea/vcs.xml
generated
Normal 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
26
Dockerfile
Normal 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
26
Program.cs
Normal 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();
|
||||||
15
Properties/launchSettings.json
Normal file
15
Properties/launchSettings.json
Normal 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
16
ServiceUpdater.csproj
Normal 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
3
ServiceUpdater.slnx
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<Solution>
|
||||||
|
<Project Path="ServiceUpdater.csproj" />
|
||||||
|
</Solution>
|
||||||
58
UpdateWorker.cs
Normal file
58
UpdateWorker.cs
Normal 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
5
UpdaterConfig.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
namespace ServiceUpdater;
|
||||||
|
|
||||||
|
public sealed class UpdaterConfig(IConfiguration config) {
|
||||||
|
public string ServicesRoot => config["Root"] ?? "/";
|
||||||
|
}
|
||||||
8
appsettings.Development.json
Normal file
8
appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
appsettings.json
Normal file
9
appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user