Merge pull request #107 from NicolasConstant/topic_admin-tooling
Topic admin tooling
This commit is contained in:
commit
b3bb57157f
3 changed files with 136 additions and 8 deletions
|
@ -1,11 +1,11 @@
|
||||||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
#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
|
WORKDIR /app
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
EXPOSE 443
|
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/
|
COPY ./src/ ./src/
|
||||||
RUN dotnet publish "/src/BirdsiteLive/BirdsiteLive.csproj" -c Release -o /app/publish
|
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
|
RUN dotnet publish "/src/BSLManager/BSLManager.csproj" -r linux-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -c Release -o /app/publish
|
||||||
|
|
|
@ -6,6 +6,7 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BirdsiteLive.Common.Settings;
|
using BirdsiteLive.Common.Settings;
|
||||||
using BirdsiteLive.DAL.Contracts;
|
using BirdsiteLive.DAL.Contracts;
|
||||||
|
using BSLManager.Tools;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using NStack;
|
using NStack;
|
||||||
using Terminal.Gui;
|
using Terminal.Gui;
|
||||||
|
@ -18,14 +19,17 @@ namespace BSLManager
|
||||||
{
|
{
|
||||||
Console.OutputEncoding = Encoding.Default;
|
Console.OutputEncoding = Encoding.Default;
|
||||||
|
|
||||||
var builder = new ConfigurationBuilder()
|
var settingsManager = new SettingsManager();
|
||||||
.AddEnvironmentVariables();
|
var settings = settingsManager.GetSettings();
|
||||||
var configuration = builder.Build();
|
|
||||||
|
|
||||||
var dbSettings = configuration.GetSection("Db").Get<DbSettings>();
|
//var builder = new ConfigurationBuilder()
|
||||||
var instanceSettings = configuration.GetSection("Instance").Get<InstanceSettings>();
|
// .AddEnvironmentVariables();
|
||||||
|
//var configuration = builder.Build();
|
||||||
|
|
||||||
var bootstrapper = new Bootstrapper(dbSettings, instanceSettings);
|
//var dbSettings = configuration.GetSection("Db").Get<DbSettings>();
|
||||||
|
//var instanceSettings = configuration.GetSection("Instance").Get<InstanceSettings>();
|
||||||
|
|
||||||
|
var bootstrapper = new Bootstrapper(settings.dbSettings, settings.instanceSettings);
|
||||||
var container = bootstrapper.Init();
|
var container = bootstrapper.Init();
|
||||||
|
|
||||||
var app = container.GetInstance<App>();
|
var app = container.GetInstance<App>();
|
||||||
|
|
124
src/BSLManager/Tools/SettingsManager.cs
Normal file
124
src/BSLManager/Tools/SettingsManager.cs
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!File.Exists(LocalFileName)) return null;
|
||||||
|
|
||||||
|
var jsonContent = File.ReadAllText(LocalFileName);
|
||||||
|
var content = JsonConvert.DeserializeObject<LocalSettingsData>(jsonContent);
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue