From 2b09bc37f8fdbc2dbeea1926b865aef844f2fae2 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 28 May 2021 19:34:41 -0400 Subject: [PATCH 1/3] fix docker images --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ae4a0ba..11a4422 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base +FROM mcr.microsoft.com/dotnet/aspnet:3.1-buster-slim AS base WORKDIR /app EXPOSE 80 EXPOSE 443 -FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS publish +FROM mcr.microsoft.com/dotnet/sdk:3.1-buster AS publish COPY ./src/ ./src/ RUN dotnet publish "/src/BirdsiteLive/BirdsiteLive.csproj" -c Release -o /app/publish RUN dotnet publish "/src/BSLManager/BSLManager.csproj" -r linux-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -c Release -o /app/publish From 7ed993e51ddcb32ea685ccbc873ed23a3be5b4e6 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 28 May 2021 21:07:47 -0400 Subject: [PATCH 2/3] getting settings manually --- src/BSLManager/Program.cs | 16 ++-- src/BSLManager/Tools/SettingsManager.cs | 117 ++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 src/BSLManager/Tools/SettingsManager.cs diff --git a/src/BSLManager/Program.cs b/src/BSLManager/Program.cs index ea2569c..629ff25 100644 --- a/src/BSLManager/Program.cs +++ b/src/BSLManager/Program.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using BirdsiteLive.Common.Settings; using BirdsiteLive.DAL.Contracts; +using BSLManager.Tools; using Microsoft.Extensions.Configuration; using NStack; using Terminal.Gui; @@ -18,14 +19,17 @@ namespace BSLManager { Console.OutputEncoding = Encoding.Default; - var builder = new ConfigurationBuilder() - .AddEnvironmentVariables(); - var configuration = builder.Build(); + var settingsManager = new SettingsManager(); + var settings = settingsManager.GetSettings(); - var dbSettings = configuration.GetSection("Db").Get(); - var instanceSettings = configuration.GetSection("Instance").Get(); + //var builder = new ConfigurationBuilder() + // .AddEnvironmentVariables(); + //var configuration = builder.Build(); - var bootstrapper = new Bootstrapper(dbSettings, instanceSettings); + //var dbSettings = configuration.GetSection("Db").Get(); + //var instanceSettings = configuration.GetSection("Instance").Get(); + + var bootstrapper = new Bootstrapper(settings.dbSettings, settings.instanceSettings); var container = bootstrapper.Init(); var app = container.GetInstance(); diff --git a/src/BSLManager/Tools/SettingsManager.cs b/src/BSLManager/Tools/SettingsManager.cs new file mode 100644 index 0000000..db98d71 --- /dev/null +++ b/src/BSLManager/Tools/SettingsManager.cs @@ -0,0 +1,117 @@ +using System; +using System.IO; +using System.Runtime.CompilerServices; +using BirdsiteLive.Common.Settings; +using Newtonsoft.Json; +using Org.BouncyCastle.Asn1.IsisMtt.X509; + +namespace BSLManager.Tools +{ + public class SettingsManager + { + private const string LocalFileName = "ManagerSettings.json"; + + public (DbSettings dbSettings, InstanceSettings instanceSettings) GetSettings() + { + var localSettingsData = GetLocalSettingsFile(); + if (localSettingsData != null) return Convert(localSettingsData); + + Console.WriteLine("We need to set up the manager"); + Console.WriteLine("Please provide the following information as provided in the docker-compose file"); + + LocalSettingsData data; + do + { + data = GetDataFromUser(); + Console.WriteLine(); + Console.WriteLine("Please check if all is ok:"); + Console.WriteLine(); + Console.WriteLine($"Db Host: {data.DbHost}"); + Console.WriteLine($"Db Name: {data.DbName}"); + Console.WriteLine($"Db User: {data.DbUser}"); + Console.WriteLine($"Db Password: {data.DbPassword}"); + Console.WriteLine($"Instance Domain: {data.InstanceDomain}"); + Console.WriteLine(); + + string resp; + do + { + Console.WriteLine("Is it valid? (yes, no)"); + resp = Console.ReadLine()?.Trim().ToLowerInvariant(); + + if (resp == "n" || resp == "no") data = null; + + } while (resp != "y" && resp != "yes" && resp != "n" && resp != "no"); + + } while (data == null); + + SaveLocalSettings(data); + return Convert(data); + } + + private LocalSettingsData GetDataFromUser() + { + var data = new LocalSettingsData(); + + Console.WriteLine("Db Host:"); + data.DbHost = Console.ReadLine(); + + Console.WriteLine("Db Name:"); + data.DbName = Console.ReadLine(); + + Console.WriteLine("Db User:"); + data.DbUser = Console.ReadLine(); + + Console.WriteLine("Db Password:"); + data.DbPassword = Console.ReadLine(); + + Console.WriteLine("Instance Domain:"); + data.InstanceDomain = Console.ReadLine(); + + return data; + } + + private (DbSettings dbSettings, InstanceSettings instanceSettings) Convert(LocalSettingsData data) + { + var dbSettings = new DbSettings + { + Type = data.DbType, + Host = data.DbHost, + Name = data.DbName, + User = data.DbUser, + Password = data.DbPassword + }; + var instancesSettings = new InstanceSettings + { + Domain = data.InstanceDomain + }; + return (dbSettings, instancesSettings); + } + + private LocalSettingsData GetLocalSettingsFile() + { + if (!File.Exists(LocalFileName)) return null; + + var jsonContent = File.ReadAllText(LocalFileName); + var content = JsonConvert.DeserializeObject(jsonContent); + return content; + } + + private void SaveLocalSettings(LocalSettingsData data) + { + var jsonContent = JsonConvert.SerializeObject(data); + File.WriteAllText(LocalFileName, jsonContent); + } + } + + internal class LocalSettingsData + { + public string DbType { get; set; } = "postgres"; + public string DbHost { get; set; } + public string DbName { get; set; } + public string DbUser { get; set; } + public string DbPassword { get; set; } + + public string InstanceDomain { get; set; } + } +} \ No newline at end of file From 0e787bbca8ef202523c5f531ae9dc56e75801325 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 28 May 2021 21:09:09 -0400 Subject: [PATCH 3/3] better deserialization --- src/BSLManager/Tools/SettingsManager.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/BSLManager/Tools/SettingsManager.cs b/src/BSLManager/Tools/SettingsManager.cs index db98d71..5ff6314 100644 --- a/src/BSLManager/Tools/SettingsManager.cs +++ b/src/BSLManager/Tools/SettingsManager.cs @@ -90,11 +90,18 @@ namespace BSLManager.Tools private LocalSettingsData GetLocalSettingsFile() { - if (!File.Exists(LocalFileName)) return null; + try + { + if (!File.Exists(LocalFileName)) return null; - var jsonContent = File.ReadAllText(LocalFileName); - var content = JsonConvert.DeserializeObject(jsonContent); - return content; + var jsonContent = File.ReadAllText(LocalFileName); + var content = JsonConvert.DeserializeObject(jsonContent); + return content; + } + catch (Exception) + { + return null; + } } private void SaveLocalSettings(LocalSettingsData data)