Skip to content

Commit

Permalink
Merge pull request #775 from pieterh/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pieterh authored Apr 10, 2023
2 parents 249e4b4 + de4769c commit 97487f7
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 40 deletions.
37 changes: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ The recommended method is to use Docker compose (See below). For instructions ho

### Docker compose
```
mkdir /hems
cd /hems
mkdir hems
cd hems
mkdir config
```

create config.json and a NLog.config in the 'config' subfolder. You can find examples of these in this repository folder docker/tests/config/

*docker-compose.yml*

```
Expand All @@ -64,11 +67,13 @@ services:
container_name: hems
restart: unless-stopped
ports:
- "8080:8080"
- "8080:5000"
volumes:
- ./config:/app/ems/userdata
environment:
- TZ=Europe/Amsterdam
- EMS_PATHS_CONFIG=/app/ems/userdata/config.json
- EMS_PATHS_NLOG=/app/ems/userdata/NLog.config
```

You can use the following two options to start the container:
Expand All @@ -90,21 +95,29 @@ docker image prune

### Docker

Get the image from the repository:
Get the latest image from the repository:
```
docker pull pieterhil/energy-management-system:latest
```

Remove any old containers from the system that where left over from a prvious run.
```
docker container rm hems
```
docker run -d \
-p 8080:8080 \
-p 8443:443 \
-v <path for config files>:/app/ems/userdata \
-e TZ=Europe/Amsterdam
--device=<device_id> \
--name=hems \
pieterhil/energy-management-system:latest

```
docker run \
-p 8080:5000 \
--mount type=bind,source="$(pwd)"/config,destination=/app/ems/userdata \
-e TZ=Europe/Amsterdam \
-e EMS_PATHS_CONFIG=/app/ems/userdata/config.json \
-e EMS_PATHS_NLOG=/app/ems/userdata/NLog.config \
--name=hems \
pieterhil/energy-management-system:feature-blazorwasm
```

### Frontend
The frontend is accessible using the browser http://127.0.0.1:8080 if you are running the docker on you own local system.

## Developing and Contributing
We'd love to get contributions from you! Take a look at the
Expand Down
3 changes: 2 additions & 1 deletion backend/EMS.Library/EMS.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="NLog" Version="5.1.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="JsonSchema.Net" Version="4.0.2" />
<PackageReference Include="JsonSchema.Net" Version="4.0.3" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.55.0.65544">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand All @@ -26,6 +26,7 @@
<Folder Include="Assembly\" />
<Folder Include="Exceptions\" />
<Folder Include="dotNET\" />
<Folder Include="Files\" />
</ItemGroup>
<ItemGroup>
<None Remove="Adapter\PriceProvider\" />
Expand Down
20 changes: 20 additions & 0 deletions backend/EMS.Library/Files/FileTools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
namespace EMS.Library.Files
{
public static class FileTools
{
public static bool FileExistsAndReadable(string? path)
{
try
{
if (string.IsNullOrWhiteSpace(path)) return false;
using var f = File.OpenRead(path);
return true;
}
catch (FileNotFoundException) { /* the file was not found */ }
catch (FieldAccessException) { /* no access to the file */ }
return false;
}
}
}

2 changes: 1 addition & 1 deletion backend/EMS/EMS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.2.3" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="JsonSchema.Net" Version="4.0.2" />
<PackageReference Include="JsonSchema.Net" Version="4.0.3" />
<PackageReference Include="Microsoft.Json.Schema.Validation" Version="2.3.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.55.0.65544">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
39 changes: 25 additions & 14 deletions backend/EMS/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using System.Runtime.InteropServices;
using EMS.Library.dotNET;
using Microsoft.AspNetCore.Http;
using EMS.Library.Files;

namespace EMS
{
Expand Down Expand Up @@ -134,7 +135,7 @@ private static void ConfigureLogging(Options options)
}
catch (FileNotFoundException)
{
Logger.Error($"Ther logger configuration file '{options.NLogConfig}' could not be found. Using default logging to console.");
Logger.Error($"The logger configuration file '{options.NLogConfig}' could not be found. Using default logging to console.");
EnforceLogging(true);
}
}
Expand All @@ -148,20 +149,30 @@ static IHost CreateHost(Options options)
})
.UseNLog()
.ConfigureAppConfiguration((builderContext, configuration) =>
{
IHostEnvironment env = builderContext.HostingEnvironment;
Logger.Info($"Hosting environment: {env.EnvironmentName}");
if (ConfigurationManager.ValidateConfig(options.ConfigFile) && !string.IsNullOrWhiteSpace(options?.ConfigFile))
{
configuration.Sources.Clear();
configuration
.AddJsonFile(options.ConfigFile, optional: false, reloadOnChange: false)
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true, reloadOnChange: false);
}
else
Logger.Error("There was an error with the configuration file");

{

IHostEnvironment env = builderContext.HostingEnvironment;
Logger.Info($"Hosting environment: {env.EnvironmentName}");
var configFile = options.ConfigFile;
var configFileEnvironmentSpecific = $"config.{env.EnvironmentName}.json";
if (FileTools.FileExistsAndReadable(configFile))
{
if (ConfigurationManager.ValidateConfig(configFile) && !string.IsNullOrWhiteSpace(configFile))
{
configuration.Sources.Clear();
configuration.AddJsonFile(configFile, optional: false, reloadOnChange: false);

if (FileTools.FileExistsAndReadable(configFileEnvironmentSpecific))
{
configuration.AddJsonFile(configFileEnvironmentSpecific, optional: true, reloadOnChange: false);
}
}
else

throw new ArgumentException($"There was an error with the configuration file {configFile}");
}
else
throw new ArgumentException($"The configuration file {configFile} was not found or not readable.");
})
.ConfigureServices((builderContext, services) =>
{
Expand Down
2 changes: 1 addition & 1 deletion backend/EPEXSPOT/EPEXSPOT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="JsonSchema.Net" Version="4.0.2" />
<PackageReference Include="JsonSchema.Net" Version="4.0.3" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.55.0.65544">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion docker/build/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ RUN ls -la /app/ems/dist/_framework
RUN ls -la /app/ems/dist/_content
RUN ls -la /app/ems/dist/_content/MudBlazor

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
ENTRYPOINT /usr/local/bin/entrypoint.sh --config ${EMS_PATHS_CONFIG} --nlogcfg ${EMS_PATHS_NLOG}
17 changes: 7 additions & 10 deletions docker/build/entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/usr/bin/env bash

set -e

printf "\n\033[0;44m---> Starting HEMS \033[0m\n"
id
ls -la /app/ems
ls -la /app/ems/userdata
#params=$(echo "$@" "--nlogdebug true")
params=$(echo "$@" )
paramsStr=$( IFS=$'\n'; echo "${params}" )

printf "\n\033[0;44m---> Starting HEMS \033[0m\n"
cd /app/ems
printf "\n\033[0;44m---> dotnet EMS.dll -- --config $EMS_PATHS_CONFIG --nlogcfg $EMS_PATHS_NLOG \033[0m\n"
dotnet EMS.dll -- --config $EMS_PATHS_CONFIG --nlogcfg $EMS_PATHS_NLOG
printf "\n\033[0;44m---> dotnet EMS.dll -- %s \033[0m\n" "$paramsStr"
dotnet EMS.dll -- $params

printf "\n\033[0;44m---> Are we done?\033[0m\n"
tail -f /dev/null
printf "\n\033[0;44m---> Done\033[0m\n"
1 change: 1 addition & 0 deletions docker/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config/logging.log

0 comments on commit 97487f7

Please sign in to comment.