mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 17:25:32 +00:00
+Docker
This commit is contained in:
@@ -32,7 +32,17 @@ npm run build # Build CSS/JS first (required!)
|
||||
dotnet build HaWeb.csproj # Build the web application
|
||||
```
|
||||
|
||||
### Production Deployment (Linux)
|
||||
### Production Deployment
|
||||
|
||||
**Docker (Recommended)**:
|
||||
```bash
|
||||
# From repository root
|
||||
docker volume create hamann_data
|
||||
docker-compose up -d --build
|
||||
```
|
||||
See `DOCKER.md` for detailed Docker deployment instructions.
|
||||
|
||||
**Manual (Linux)**:
|
||||
```bash
|
||||
npm run build
|
||||
dotnet publish --runtime linux-x64 -c Release
|
||||
|
||||
@@ -121,10 +121,35 @@ public class GitService : IGitService {
|
||||
|
||||
// Checkout the specified branch if it's not the default
|
||||
using var repo = new Repository(_repositoryPath);
|
||||
|
||||
// Log diagnostic information
|
||||
_logger?.LogInformation("HEAD: {Head}, IsDetached: {IsDetached}, Tip: {Tip}",
|
||||
repo.Head?.FriendlyName ?? "null",
|
||||
repo.Head?.IsRemote.ToString() ?? "null",
|
||||
repo.Head?.Tip?.Sha.Substring(0, 7) ?? "null");
|
||||
|
||||
_logger?.LogInformation("Available branches: {Branches}",
|
||||
string.Join(", ", repo.Branches.Select(b => $"{b.FriendlyName} (Remote: {b.IsRemote})")));
|
||||
|
||||
var branch = repo.Branches[_branch] ?? repo.Branches[$"origin/{_branch}"];
|
||||
|
||||
if (branch == null) {
|
||||
_logger?.LogWarning("Branch {Branch} not found. Attempting to create local tracking branch from origin/{Branch}", _branch, _branch);
|
||||
var remoteBranch = repo.Branches[$"origin/{_branch}"];
|
||||
if (remoteBranch != null) {
|
||||
branch = repo.CreateBranch(_branch, remoteBranch.Tip);
|
||||
repo.Branches.Update(branch, b => b.TrackedBranch = remoteBranch.CanonicalName);
|
||||
_logger?.LogInformation("Created local tracking branch {Branch}", _branch);
|
||||
}
|
||||
}
|
||||
|
||||
if (branch != null && branch.FriendlyName != repo.Head.FriendlyName) {
|
||||
Commands.Checkout(repo, branch);
|
||||
_logger?.LogInformation("Checked out branch {Branch}", _branch);
|
||||
} else if (branch != null) {
|
||||
_logger?.LogInformation("Already on branch {Branch}", _branch);
|
||||
} else {
|
||||
_logger?.LogError("Could not find or create branch {Branch}", _branch);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -52,8 +52,8 @@ public class XMLFileProvider : IXMLFileProvider {
|
||||
// Create File Lists; Here and in xmlservice, which does preliminary checking
|
||||
Scan();
|
||||
if (_WorkingTreeFiles != null && _WorkingTreeFiles.Any()) {
|
||||
var state = xmlservice.Collect(_WorkingTreeFiles, xmlservice.GetRootDefs());
|
||||
xmlservice.SetState(state);
|
||||
var initialState = xmlservice.Collect(_WorkingTreeFiles, xmlservice.GetRootDefs());
|
||||
xmlservice.SetState(initialState);
|
||||
}
|
||||
_HamannFiles = _ScanHamannFiles();
|
||||
|
||||
@@ -64,29 +64,27 @@ public class XMLFileProvider : IXMLFileProvider {
|
||||
if (_Lib.GetLibrary() != null) return;
|
||||
}
|
||||
|
||||
// -> NO: Try to create a new file
|
||||
var created = _XMLService.TryCreate(_XMLService.GetState());
|
||||
if (created != null) {
|
||||
var file = SaveHamannFile(created, _hamannFileProvider.GetFileInfo("./").PhysicalPath, null);
|
||||
if (file != null) {
|
||||
_Lib.SetLibrary(file, created.Document, null);
|
||||
if (_Lib.GetLibrary() != null) return;
|
||||
// -> NO: Try to create a new file (only if we have a valid git state and XML files)
|
||||
var currentState = _XMLService.GetState();
|
||||
if (currentState != null && _GitState != null) {
|
||||
var created = _XMLService.TryCreate(currentState);
|
||||
if (created != null) {
|
||||
var file = SaveHamannFile(created, _hamannFileProvider.GetFileInfo("./").PhysicalPath, null);
|
||||
if (file != null) {
|
||||
_Lib.SetLibrary(file, created.Document, null);
|
||||
if (_Lib.GetLibrary() != null) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// It failed, so use the last best File:
|
||||
else if (_HamannFiles != null && _HamannFiles.Any()) {
|
||||
if (_HamannFiles != null && _HamannFiles.Any()) {
|
||||
_Lib.SetLibrary(_HamannFiles.First(), null, null);
|
||||
if (_Lib.GetLibrary() != null) return;
|
||||
}
|
||||
|
||||
// -> There is none? Use Fallback:
|
||||
else {
|
||||
var options = new HaWeb.Settings.HaDocumentOptions();
|
||||
if (_Lib.SetLibrary(null, null, null) == null) {
|
||||
throw new Exception("Die Fallback Hamann.xml unter " + options.HamannXMLFilePath + " kann nicht geparst werden.");
|
||||
}
|
||||
}
|
||||
// No valid data available
|
||||
throw new Exception("Keine gültige Hamann.xml Datei gefunden. Repository konnte nicht geklont oder geparst werden.");
|
||||
}
|
||||
|
||||
public void ParseConfiguration(IConfiguration config) {
|
||||
@@ -111,29 +109,27 @@ public class XMLFileProvider : IXMLFileProvider {
|
||||
if (_Lib.GetLibrary() != null) return;
|
||||
}
|
||||
|
||||
// -> NO: Try to create a new file
|
||||
var created = _XMLService.TryCreate(_XMLService.GetState());
|
||||
if (created != null) {
|
||||
var file = SaveHamannFile(created, _hamannFileProvider.GetFileInfo("./").PhysicalPath, null);
|
||||
if (file != null) {
|
||||
_Lib.SetLibrary(file, created.Document, null);
|
||||
if (_Lib.GetLibrary() != null) return;
|
||||
// -> NO: Try to create a new file (only if we have a valid git state and XML files)
|
||||
var configState = _XMLService.GetState();
|
||||
if (configState != null && _GitState != null) {
|
||||
var created = _XMLService.TryCreate(configState);
|
||||
if (created != null) {
|
||||
var file = SaveHamannFile(created, _hamannFileProvider.GetFileInfo("./").PhysicalPath, null);
|
||||
if (file != null) {
|
||||
_Lib.SetLibrary(file, created.Document, null);
|
||||
if (_Lib.GetLibrary() != null) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// It failed, so use the last best File:
|
||||
else if (_HamannFiles != null && _HamannFiles.Any()) {
|
||||
if (_HamannFiles != null && _HamannFiles.Any()) {
|
||||
_Lib.SetLibrary(_HamannFiles.First(), null, null);
|
||||
if (_Lib.GetLibrary() != null) return;
|
||||
}
|
||||
|
||||
// -> There is none? Use Fallback:
|
||||
else {
|
||||
var options = new HaWeb.Settings.HaDocumentOptions();
|
||||
if (_Lib.SetLibrary(null, null, null) == null) {
|
||||
throw new Exception("Die Fallback Hamann.xml unter " + options.HamannXMLFilePath + " kann nicht geparst werden.");
|
||||
}
|
||||
}
|
||||
// No valid data available
|
||||
throw new Exception("Keine gültige Hamann.xml Datei gefunden. Repository konnte nicht geklont oder geparst werden.");
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
@@ -180,15 +176,18 @@ public class XMLFileProvider : IXMLFileProvider {
|
||||
}
|
||||
}
|
||||
|
||||
// Try to create a new file
|
||||
var created = _XMLService.TryCreate(_XMLService.GetState());
|
||||
if (created != null) {
|
||||
var file = SaveHamannFile(created, _hamannFileProvider.GetFileInfo("./").PhysicalPath, null);
|
||||
if (file != null) {
|
||||
_Lib.SetLibrary(file, created.Document, null);
|
||||
if (_Lib.GetLibrary() != null) {
|
||||
OnNewData();
|
||||
return;
|
||||
// Try to create a new file (only if we have a valid git state and XML files)
|
||||
var reloadState = _XMLService.GetState();
|
||||
if (reloadState != null && _GitState != null) {
|
||||
var created = _XMLService.TryCreate(reloadState);
|
||||
if (created != null) {
|
||||
var file = SaveHamannFile(created, _hamannFileProvider.GetFileInfo("./").PhysicalPath, null);
|
||||
if (file != null) {
|
||||
_Lib.SetLibrary(file, created.Document, null);
|
||||
if (_Lib.GetLibrary() != null) {
|
||||
OnNewData();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,12 +201,8 @@ public class XMLFileProvider : IXMLFileProvider {
|
||||
}
|
||||
}
|
||||
|
||||
// Use Fallback:
|
||||
var options = new HaWeb.Settings.HaDocumentOptions();
|
||||
if (_Lib.SetLibrary(null, null, null) == null) {
|
||||
throw new Exception("Die Fallback Hamann.xml unter " + options.HamannXMLFilePath + " kann nicht geparst werden.");
|
||||
}
|
||||
OnNewData();
|
||||
// No valid data available
|
||||
throw new Exception("Keine gültige Hamann.xml Datei gefunden. Repository konnte nicht geklont oder geparst werden.");
|
||||
}
|
||||
|
||||
public IFileInfo? SaveHamannFile(XElement element, string basefilepath, ModelStateDictionary? ModelState) {
|
||||
|
||||
@@ -56,9 +56,6 @@ app.UseMiddleware<WebSocketMiddleware>();
|
||||
// Production Options
|
||||
if (!app.Environment.IsDevelopment()) {
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto });
|
||||
}
|
||||
|
||||
@@ -66,11 +63,17 @@ app.UseAuthorization();
|
||||
|
||||
var cacheMaxAgeOneWeek = (60 * 60 * 24 * 7).ToString();
|
||||
app.UseStaticFiles(new StaticFileOptions {
|
||||
// Set ETag:
|
||||
OnPrepareResponse = ctx => {
|
||||
ctx.Context.Response.Headers.Add("Cache-Control", "public, max-age=" + cacheMaxAgeOneWeek);
|
||||
},
|
||||
ServeUnknownFileTypes = true,
|
||||
|
||||
// Ensure correct MIME types
|
||||
var path = ctx.File.PhysicalPath;
|
||||
if (path?.EndsWith(".css") == true) {
|
||||
ctx.Context.Response.ContentType = "text/css";
|
||||
} else if (path?.EndsWith(".js") == true) {
|
||||
ctx.Context.Response.ContentType = "application/javascript";
|
||||
}
|
||||
}
|
||||
});
|
||||
app.MapControllers();
|
||||
app.Run();
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
"AllowedHosts": "*",
|
||||
"FileStoragePath": "/home/simon/source/hamann-ausgabe-core/HaWeb/testdata/",
|
||||
"RepositoryBranch": "Main",
|
||||
"RepositoryURL": "https://github.com/Theodor-Springmann-Stiftung/hamann-xml",
|
||||
"RepositoryURL": "https://github.com/Theodor-Springmann-Stiftung/hamann-xml.git",
|
||||
"WebhookSecret": "secret",
|
||||
"FileSizeLimit": 52428800,
|
||||
"AvailableStartYear": 1700,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
},
|
||||
"AllowedWebSocketConnections": "*",
|
||||
"AllowedHosts": "*",
|
||||
"FileStoragePath": "/var/www/vhosts/development.hamann-ausgabe.de/httpdocs/Storage/",
|
||||
"FileStoragePath": "/app/data",
|
||||
"RepositoryBranch": "main",
|
||||
"RepositoryURL": "https://github.com/Theodor-Springmann-Stiftung/hamann-xml",
|
||||
"WebhookSecret": "",
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
},
|
||||
"AllowedWebSocketConnections": "*",
|
||||
"AllowedHosts": "*",
|
||||
"FileStoragePath": "/var/www/vhosts/hamann-ausgabe.de/httpdocs/Storage/",
|
||||
"RepositoryBranch": "main",
|
||||
"RepositoryURL": "",
|
||||
"FileStoragePath": "/app/data",
|
||||
"RepositoryBranch": "Release",
|
||||
"RepositoryURL": "https://github.com/Theodor-Springmann-Stiftung/hamann-xml.git",
|
||||
"WebhookSecret": ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user