Multiple configuration modifications

Added Enviroment variable support
Addes baseUrl variable for live services
Included default env variables in docker-compose.yml
Updated sql and nodejs versions
This commit is contained in:
kunkliricsi 2020-11-23 10:50:10 +01:00
parent 85320d3cf3
commit 5b42ce9f43
12 changed files with 62 additions and 100 deletions

View File

@ -1,14 +1,13 @@
#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/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash -
RUN apt-get update
RUN apt-get install -y nodejs
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash -
RUN apt-get update
RUN apt-get install -y nodejs
WORKDIR /src

View File

@ -1,28 +0,0 @@
#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/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
WORKDIR /src
COPY ["Birdmap.API/Birdmap.API.csproj", "Birdmap.API/"]
COPY ["Birdmap.BLL/Birdmap.BLL.csproj", "Birdmap.BLL/"]
COPY ["Birdmap.Common/Birdmap.Common.csproj", "Birdmap.Common/"]
COPY ["Birdmap.DAL/Birdmap.DAL.csproj", "Birdmap.DAL/"]
RUN dotnet restore "Birdmap.API/Birdmap.API.csproj"
COPY . .
WORKDIR "/src/Birdmap.API"
RUN dotnet build "Birdmap.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Birdmap.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Birdmap.API.dll"]

View File

@ -1,30 +0,0 @@
#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/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get update
RUN apt-get install -y nodejs
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get update
RUN apt-get install -y nodejs
WORKDIR /src
COPY ["Birdmap.API/Birdmap.API.csproj", "Birdmap.API/"]
COPY ["Birdmap.BLL/Birdmap.BLL.csproj", "Birdmap.BLL/"]
COPY ["Birdmap.Common/Birdmap.Common.csproj", "Birdmap.Common/"]
COPY ["Birdmap.DAL/Birdmap.DAL.csproj", "Birdmap.DAL/"]
RUN dotnet restore "Birdmap.API/Birdmap.API.csproj"
COPY . .
WORKDIR "/src/Birdmap.API"
RUN dotnet build "Birdmap.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Birdmap.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Birdmap.API.dll"]

View File

@ -1,5 +1,6 @@
using Birdmap.DAL;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
@ -20,12 +21,6 @@ namespace Birdmap.API
logger.Debug("Building host...");
var host = CreateHostBuilder(args).Build();
using (var scope = host.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<BirdmapContext>();
db.Database.EnsureCreated();
}
logger.Debug("Seeding database...");
SeedDatabase(host);
@ -45,6 +40,10 @@ namespace Birdmap.API
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddEnvironmentVariables(prefix: "Birdmap_");
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
@ -59,8 +58,8 @@ namespace Birdmap.API
private static void SeedDatabase(IHost host)
{
using var scope = host.Services.CreateScope();
var dbInitializer = scope.ServiceProvider.GetRequiredService<DbInitializer>();
var dbInitializer = scope.ServiceProvider.GetRequiredService<DbInitializer>();
dbInitializer.Initialize();
}
}

View File

@ -2,6 +2,10 @@
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "http://localhost/Birdmap.API",
"sslPort": 0
},
"iisExpress": {
"applicationUrl": "http://localhost:63288",
"sslPort": 44331
@ -12,6 +16,7 @@
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"Birdmap_LocalDbConnectionString": "Data Source=DESKTOP-3600;Initial Catalog=birdmap2;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"ASPNETCORE_ENVIRONMENT": "Development"
}
},

View File

@ -10,7 +10,7 @@
"Secret": "7vj.3KW.hYE!}4u6",
// "LocalDbConnectionString": "Data Source=DESKTOP-3600\\SQLEXPRESS;Initial Catalog=birdmap;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
//"LocalDbConnectionString": "Data Source=DESKTOP-3600;Initial Catalog=birdmap;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"LocalDbConnectionString": "Data Source=db;Initial Catalog=master;User=sa;Password=asdfjkl-123",
"LocalDbConnectionString": "Data Source=db;Initial Catalog=birdmap;User=sa;Password=RPSsql12345",
"Defaults": {
"Services": {
"Local Database": "https://localhost:44331/health",
@ -30,6 +30,7 @@
]
},
"UseDummyServices": true,
"ServicesBaseUrl": "https://birb.k8s.kmlabz.com/",
"Mqtt": {
"BrokerHostSettings": {
"Host": "localhost",

View File

@ -23,8 +23,9 @@ namespace Birdmap.BLL.Services
private System.Net.Http.HttpClient _httpClient;
private System.Lazy<Newtonsoft.Json.JsonSerializerSettings> _settings;
public LiveDummyService(System.Net.Http.HttpClient httpClient)
public LiveDummyService(string baseUrl, System.Net.Http.HttpClient httpClient)
{
_baseUrl = baseUrl;
_httpClient = httpClient;
_settings = new System.Lazy<Newtonsoft.Json.JsonSerializerSettings>(CreateSerializerSettings);
}

View File

@ -23,8 +23,9 @@ namespace Birdmap.BLL.Services
private System.Net.Http.HttpClient _httpClient;
private System.Lazy<Newtonsoft.Json.JsonSerializerSettings> _settings;
public LiveInputService(System.Net.Http.HttpClient httpClient)
public LiveInputService(string baseUrl, System.Net.Http.HttpClient httpClient)
{
_baseUrl = baseUrl;
_httpClient = httpClient;
_settings = new System.Lazy<Newtonsoft.Json.JsonSerializerSettings>(CreateSerializerSettings);
}

View File

@ -2,6 +2,7 @@
using Birdmap.BLL.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Http;
namespace Birdmap.BLL
{
@ -20,8 +21,20 @@ namespace Birdmap.BLL
}
else
{
services.AddTransient<IInputService, LiveInputService>();
services.AddTransient<IDeviceService, LiveDummyService>();
var baseUrl = configuration.GetValue<string>("ServicesBaseUrl");
services.AddTransient<IInputService, LiveInputService>(serviceProvider =>
{
var httpClient = serviceProvider.GetService<HttpClient>();
var service = new LiveInputService(baseUrl, httpClient);
return service;
});
services.AddTransient<IDeviceService, LiveDummyService>(serviceProvider =>
{
var httpClient = serviceProvider.GetService<HttpClient>();
var service = new LiveDummyService(baseUrl, httpClient);
return service;
});
}
return services;

View File

@ -22,10 +22,17 @@ namespace Birdmap.DAL
public void Initialize()
{
EnsureCreated();
AddDefaultUsers();
AddDefaultServices();
}
private void EnsureCreated()
{
_logger.LogInformation("Ensuring database is created...");
_context.Database.EnsureCreated();
}
private void AddDefaultServices()
{
_logger.LogInformation("Removing previously added default services...");

View File

@ -1,22 +0,0 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app
EXPOSE 80
RUN curl --silent --location https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install --yes nodejs
# copy csproj and restore as distinct layers
WORKDIR /src
COPY . .
RUN dotnet restore "Birdmap.API/Birdmap.API.csproj"
# copy everything else and build app
RUN dotnet publish "Birdmap.API/Birdmap.API.csproj" -c Release -o /app
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "Birdmap.API.dll"]

View File

@ -2,20 +2,36 @@ version: '3.4'
services:
db:
image: "mcr.microsoft.com/mssql/server:2017-latest"
image: "mcr.microsoft.com/mssql/server:2019-latest"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=asdfjkl-123
- SA_PASSWORD=RPSsql12345
birdmap.api:
image: ${DOCKER_REGISTRY-}birdmapapi
ports:
- "8000:80"
- "5001:443"
- "5000:5000"
- "5001:5001"
build:
context: .
dockerfile: Birdmap.API/Dockerfile
depends_on:
- db
environment:
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_URLS=https://localhost:5001;http://localhost:5000
- Birdmap_LocalDbConnectionString=Data Source=db;Initial Catalog=birdmap;User=sa;Password=RPSsql12345
- Birdmap_Defaults__Users__0__Name=admin
- Birdmap_Defaults__Users__0__Password=pass
- Birdmap_Defaults__Users__0__Role=Admin
- Birdmap_Defaults__Users__1__Name=user
- Birdmap_Defaults__Users__1__Password=pass
- Birdmap_Defaults__Users__1__Role=User
- Birdmap_Defaults__Services__Local-Database=https://localhost/health
- Birdmap_UseDummyServices=true
- Birdmap_ServicesBaseUrl=https://birb.k8s.kmlabz.com/
- Birdmap_Mqtt__BrokerHostSettings__Host=localhost
- Birdmap_Mqtt__BrokerHostSettings__Port=1883
- Birdmap_Mqtt__ClientSettings__Id=ASP.NET Core client
- Birdmap_Mqtt__ClientSettings__Username=username
- Birdmap_Mqtt__ClientSettings__Password=password
- Birdmap_Mqtt__ClientSettings__Topic=devices/output