diff --git a/Chatbot.Api.Application/Chatbot.Api.Application.csproj b/Chatbot.Api.Application/Chatbot.Api.Application.csproj index 95f47b3..bccfd32 100644 --- a/Chatbot.Api.Application/Chatbot.Api.Application.csproj +++ b/Chatbot.Api.Application/Chatbot.Api.Application.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net5.0 diff --git a/Chatbot.Api.Domain.Data/Chatbot.Api.Domain.Data.csproj b/Chatbot.Api.Domain.Data/Chatbot.Api.Domain.Data.csproj index ec6e150..53b8b74 100644 --- a/Chatbot.Api.Domain.Data/Chatbot.Api.Domain.Data.csproj +++ b/Chatbot.Api.Domain.Data/Chatbot.Api.Domain.Data.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net5.0 diff --git a/Chatbot.Api.Domain/Chatbot.Api.Domain.csproj b/Chatbot.Api.Domain/Chatbot.Api.Domain.csproj index 9f5c4f4..4a8b90f 100644 --- a/Chatbot.Api.Domain/Chatbot.Api.Domain.csproj +++ b/Chatbot.Api.Domain/Chatbot.Api.Domain.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net5.0 diff --git a/Chatbot.Api/Chatbot.Api.csproj b/Chatbot.Api/Chatbot.Api.csproj index df1745d..905b0c6 100644 --- a/Chatbot.Api/Chatbot.Api.csproj +++ b/Chatbot.Api/Chatbot.Api.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 Linux @@ -19,7 +19,6 @@ - diff --git a/Chatbot.Api/Dockerfile b/Chatbot.Api/Dockerfile index 3aef4e2..0207ff6 100644 --- a/Chatbot.Api/Dockerfile +++ b/Chatbot.Api/Dockerfile @@ -1,10 +1,12 @@ #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 +#ARG BASE_IMAGE="buster-slim" + +FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build +FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build WORKDIR /src COPY dependencies.props . COPY Directory.Build.props . @@ -30,6 +32,9 @@ ENV ConnectionStrings__DatabaseConnection="***REMOVED***" ENV TZ=Europe/Bucharest RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +ARG APP_VERSION=0.0.0.0 +ENV APP_VERSION=${APP_VERSION} + #Workaround to lower the TLS level in container for old sql server version RUN sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf diff --git a/Chatbot.Api/Program.cs b/Chatbot.Api/Program.cs index da3fd45..817e13a 100644 --- a/Chatbot.Api/Program.cs +++ b/Chatbot.Api/Program.cs @@ -32,19 +32,25 @@ namespace Chatbot.Api var connectionString = configuration.GetConnectionString("DatabaseConnection"); var loggingLevelParam = configuration.GetValue("Logging:LogLevel:Default"); - Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel); + var loggingLevelOk = Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel); + if (!loggingLevelOk) + throw new Exception($"Logging level '{loggingLevelParam}' is not valid."); + var loggingLevelSwitch = new LoggingLevelSwitch(loggingLevel); var columnOptions = new ColumnOptions(); columnOptions.Store.Remove(StandardColumn.Properties); columnOptions.Store.Remove(StandardColumn.MessageTemplate); columnOptions.Store.Add(StandardColumn.LogEvent); + + var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs" }; + Log.Logger = new LoggerConfiguration() .MinimumLevel.ControlledBy(loggingLevelSwitch) .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Console() - .WriteTo.MSSqlServer(connectionString, "__Logs", autoCreateSqlTable: true, columnOptions: columnOptions) + .WriteTo.MSSqlServer(connectionString, mssqlSinkOptions, columnOptions: columnOptions) .CreateLogger(); try @@ -65,13 +71,18 @@ namespace Chatbot.Api } } - public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration) => - Host.CreateDefaultBuilder(args) + public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration) + { + var builder = Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup() - .UseConfiguration(configuration) - .UseSerilog(); + .UseConfiguration(configuration); }); + + builder.UseSerilog(); + + return builder; + } } } diff --git a/Chatbot.Api/appsettings.json b/Chatbot.Api/appsettings.json index 3ee5a91..42fcb76 100644 --- a/Chatbot.Api/appsettings.json +++ b/Chatbot.Api/appsettings.json @@ -1,5 +1,5 @@ { - "urls": "http://*:5061", + "urls": "http://*:5055", "ConnectionStrings": { "DatabaseConnection": "***REMOVED***" }, diff --git a/Chatbot.sln b/Chatbot.sln index f8f08ce..6094978 100644 --- a/Chatbot.sln +++ b/Chatbot.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30002.166 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32526.322 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chatbot.Api", "Chatbot.Api\Chatbot.Api.csproj", "{E317DE66-9513-4666-ADCC-0B7D5B652378}" EndProject @@ -25,8 +25,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Api", "Api", "{3AC727D4-4E6 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{341EE785-7F03-457F-9188-0ADB1A2B9DBD}" ProjectSection(SolutionItems) = preProject - build-amd64.sh = build-amd64.sh + buildx.sh = buildx.sh release.sh = release.sh + build.sh = build.sh EndProjectSection EndProject Global diff --git a/build-amd64.sh b/build.sh similarity index 100% rename from build-amd64.sh rename to build.sh diff --git a/buildx.sh b/buildx.sh new file mode 100644 index 0000000..15a0a64 --- /dev/null +++ b/buildx.sh @@ -0,0 +1,22 @@ +#!/bin/bash +echo "Welcome!" + +#version="1.0.1" +#platform="linux/amd64,linux/arm64" +version="1.0.1-arm64" +platform="linux/arm64" +localRegistryPass="***REMOVED***" + +echo "Login to alpine-nexus registry." +docker login --username=admin --password=$localRegistryPass alpine-nexus:8500 + +echo "Create docker image with version $version for platform $platform" +docker buildx build \ + --build-arg APP_VERSION=$version \ + --platform $platform \ + --output=type=image,push=true,registry.insecure=true \ + --push \ + --tag alpine-nexus:8500/chatbot/chatbot-api:$version \ + -f "Chatbot.Api/Dockerfile" . + +echo "Done!" \ No newline at end of file diff --git a/dependencies.props b/dependencies.props index 6726903..fd79270 100644 --- a/dependencies.props +++ b/dependencies.props @@ -1,16 +1,15 @@ - 3.1.3 - 3.2.0 - 3.0.1 - 3.1.1 - 5.2.0 - 9.0.0 - 7.0.0 + 5.0.0 + 5.0.0 + 3.1.0 + 4.0.1 + 5.7.0 + 10.1.1 + 8.1.1 6.0.0 - 5.3.1 - 3.1.3 - 1.0.0 + 5.0.12 + 1.0.2 1.0.0 \ No newline at end of file