diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4fbc1e127ddd6e10f658d6bb801b6f6a2087c256..10f31c397cd124eb98789e38124e931817a38f7f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,8 +1,27 @@ # Development container for dotnet - FROM mcr.microsoft.com/devcontainers/dotnet:8.0 as develop -USER vscode +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Remove any existing user with the same UID (if it's not the specified user) +RUN if id -u $USER_UID >/dev/null 2>&1; then \ + existing_user=$(getent passwd $USER_UID | cut -d: -f1); \ + if [ "$existing_user" != "$USERNAME" ]; then \ + userdel -f $existing_user; \ + fi; \ + fi + +# Change the user's GID and UID +RUN groupmod -g $USER_GID $USERNAME \ + && usermod -u $USER_UID -g $USER_GID $USERNAME + +# Change user folder owner and group +RUN chown -R $USER_GID:$USER_GID /home/$USERNAME + +# [Optional] Set the default user. Omit if you want to keep the default as root. +USER $USERNAME # Add nuget sources for private packages (here: api-client) RUN dotnet nuget add source "https://git.rwth-aachen.de/api/v4/projects/88930/packages/nuget/index.json" -n "api-client" \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index bbcf65248fc2a559fa37c012acc667390c313808..910d5927826fd422c2486ad29f0311ae29aaa42a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -8,6 +8,7 @@ "updateRemoteUserUID": false, "remoteUser": "vscode", "containerUser": "vscode", + "postAttachCommand": "bash", "customizations": { "vscode": { "settings": { diff --git a/README.md b/README.md index fcea2a4b6f7fcba29e5045f234fb3055d87e5f06..80830d906a33136ab48e5ebd12b56a66d05d2573 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ## 📝 Overview -The Graph Deployer, intended to be used as a CRON job, is a .NET application designed to manage and deploy RDF graphs. It interacts with configured GitLab repositories to pull RDF graph definitions and updates a centralized repository if changes are detected or redeployment is triggered. The job uses a series of configurations to determine the operational parameters including the execution environment, repository access, and deployment specifications. +The Graph Deployer, intended to be used as a CRON job, is a .NET application designed to manage and deploy RDF graphs. It interacts with configured GitLab repositories to pull RDF graph definitions and updates a centralized repository if changes are detected or redeployment is triggered. The job uses a series of configurations to determine the operational parameters including the execution environment, repository access, and deployment specifications. ## Getting Started diff --git a/src/GraphDeployer/Deployer.cs b/src/GraphDeployer/Deployer.cs index 76d1611b46dbb4df14378c49d1ec08eeb440fa47..df916784921339b6476f8be928d3ce2851d15828 100644 --- a/src/GraphDeployer/Deployer.cs +++ b/src/GraphDeployer/Deployer.cs @@ -50,7 +50,7 @@ public class Deployer // Check if the graph deployer has to skip SSL checks when connecting to the API if (_graphDeployerConfiguration.SkipSslCheck) { - _logger.LogInformation("Skipping SSL certificate validation..."); + _logger.LogInformation("{y}Skipping SSL certificate validation...{res}", _y, _0); // Skip SSL certificate validation apiClientConfig.RemoteCertificateValidationCallback = (_, _, _, _) => true; } @@ -81,7 +81,11 @@ public class Deployer // Log the current application execution mode if (opts.DummyMode) { - _logger.LogInformation("Running in Dummy Mode. No changes will be made."); + _logger.LogInformation("{y}Running in Dummy Mode. No changes will be made.{r}", _y, _0); + } + if (opts.Redeploy) + { + _logger.LogInformation("{y}Redeploying all graphs.{r}", _y, _0); } // Override the working folder if specified in the configuration @@ -97,7 +101,7 @@ public class Deployer // Iterate over the repositories and deploy the graphs foreach (var graphRepo in _graphDeployerConfiguration.GitLab.Repositories) { - _logger.LogInformation("Working with {repoName}", graphRepo.Name); + _logger.LogInformation("Working with {bb}{repoName}{res}...", _bb, graphRepo.Name, _0); // Clone the repository inside the Working Folder var success = CloneRepo(graphRepo.Url, WorkingFolder, _graphDeployerConfiguration.GitLab.Token, graphRepo.Ref); @@ -129,10 +133,10 @@ public class Deployer } catch (Exception e) { - _logger.LogError("Failed to load and process Turtle file: \"{file}\". Error: {errorMessage}", file, e.Message); + _logger.LogError("Failed to load and process Turtle file: \"{r}{file}{res}\". Error: {errorMessage}", _r, file, _0, e.Message); } }); - _logger.LogDebug("Accumulated {count} graphs for possible deployment.", graphAccumulation.Count); + _logger.LogDebug("Accumulated {c}{count}{res} graphs for possible deployment.", _c, graphAccumulation.Count, _0); // Iterate over the accumulated graphs and deploy them foreach (var kv in graphAccumulation) @@ -142,11 +146,31 @@ public class Deployer var graphId = kv.Key.ToString(); var currentRun = new Dictionary<string, string>(); + _logger.LogDebug("Deploying graph: {c}{graphName}{res}", _c, graphId, _0); + // Get the hash of the currently deployed graph and compare it with the hash of the graph to be deployed files.ForEach((path) => currentRun.TryAdd(graphId, HashUtil.GetFileHash(path))); + var deployedGraph = deployedGraphsList.FirstOrDefault((g) => g.Uri == graphId); var hasChanged = deployedGraph is null || !deployedGraph.FileHashes.Contains(currentRun[graphId]) || opts.Redeploy; + if (hasChanged) + { + _logger.LogDebug("The graph has changed."); + } else + { + _logger.LogDebug("The graph has not changed."); + } + + if(deployedGraph is null) + { + _logger.LogDebug("Deployed graph is null"); + } else { + _logger.LogDebug("Deployed hash: {hash}", string.Join(',', deployedGraph.FileHashes)); + } + + _logger.LogDebug("Incoming hash: {hash}", currentRun[graphId]); + // Deploy the graph if it has changed or if the redeploy flag is set if (hasChanged) { @@ -175,12 +199,12 @@ public class Deployer }); } - _logger.LogInformation("Deployed {graphName} successfully.", graphId); + _logger.LogInformation("Deployed {c}{graphName}{res} {gb}successfully{res}.", _c, graphId, _0, _gb, _0); DeployedGraphs.Add(graphId); } else { - _logger.LogDebug("Skipped {graphName} as it has not changed.", graphId); + _logger.LogDebug("Skipped {c}{graphName}{res} as it has not changed.", _c, graphId, _0); SkippedGraphs.Add(graphId); continue; } @@ -249,7 +273,7 @@ public class Deployer // Retrieve the reference of the repository, either the branch name or the commit hash var repoRef = localRepo.Head.IsTracking ? localRepo.Head.FriendlyName : localRepo.Head.Tip.Sha; - _logger.LogInformation("Repository successfully cloned and switched on ref \"{ref}\".", repoRef); + _logger.LogInformation("Repository successfully cloned and switched on ref \"{c}{ref}{res}\".", _c, repoRef, _0); return true; } diff --git a/src/GraphDeployer/GraphDeployer.csproj b/src/GraphDeployer/GraphDeployer.csproj index cd34b5776740a9bfd46e3fe685c1941d034c3469..47504185f2e33d014d7f3e13ccc8d3947f019242 100644 --- a/src/GraphDeployer/GraphDeployer.csproj +++ b/src/GraphDeployer/GraphDeployer.csproj @@ -7,7 +7,7 @@ <AssemblyName>Coscine.GraphDeployer</AssemblyName> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> - <Version>2.1.0</Version> + <Version>2.1.6</Version> </PropertyGroup> <PropertyGroup> diff --git a/src/GraphDeployer/Output b/src/GraphDeployer/Output new file mode 160000 index 0000000000000000000000000000000000000000..a5abb9b05d3ed65cb1bc82e9fac08a9bf3392b11 --- /dev/null +++ b/src/GraphDeployer/Output @@ -0,0 +1 @@ +Subproject commit a5abb9b05d3ed65cb1bc82e9fac08a9bf3392b11 diff --git a/src/GraphDeployer/appsettings.json b/src/GraphDeployer/appsettings.json index 6fa53903c346bdc5e3ebef4439dba0c1f05054fc..4518ea29a43059b46c4484a21b67b650047cc140 100644 --- a/src/GraphDeployer/appsettings.json +++ b/src/GraphDeployer/appsettings.json @@ -13,7 +13,7 @@ "Token": null, "Repositories": [ { - "Name": "Application Profiles", + "Name": "Metadata Profiles", "Url": "https://git.rwth-aachen.de/coscine/graphs/applicationprofiles.git" }, { diff --git a/src/GraphDeployer/nlog.config b/src/GraphDeployer/nlog.config index e57a1713090266ca649ee185a60362ec07956514..f7f07d333702fc7677ba59da0f39dafd6275097a 100644 --- a/src/GraphDeployer/nlog.config +++ b/src/GraphDeployer/nlog.config @@ -7,9 +7,12 @@ <variable name="logHome" value="${basedir}/Logs" /> <variable name="logLevel" value="Warn" /> + + <!-- This variable is used to remove ANSI escape codes from the log message. --> + <variable name="message_raw" value="${replace:inner=${message}:searchFor=\x1B\[[0-9;]*[A-Za-z]:replaceWith=:regex=true}" /> <!--Possible aspnet- variables: https://nlog-project.org/config/?tab=layout-renderers&search=package:nlog.web--> - <variable name="layout" value="${longdate} | [${level:uppercase=true}] ${message} ${exception:format=tostring}" /> + <variable name="layout" value="${longdate} | [${level:uppercase=true}] ${message_raw} ${exception:format=tostring}" /> <targets> <!-- Write logs to File -->