diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..20b53c4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +services: + internalgateways: + container_name: clean-internalgateways + restart: always + build: + context: . + dockerfile: ./gateways/KonSoft.InternalGateway/Dockerfile + environment: + - ASPNETCORE_ENVIRONMENT=Test + - AgileConfig__AppId=KonSoft.InternalGateway + - AgileConfig__Name=KonSoft.InternalGateway + - AgileConfig__Nodes=https://config.konsoft.top/ + - AgileConfig__Secret=DBE31703-14F9-4B01-893D-900B8380CE04 + + authserver: + container_name: clean-authserver + restart: always + build: + context: . + dockerfile: ./applications/KonSoft.AuthServer/Dockerfile + environment: + - ASPNETCORE_ENVIRONMENT=Test + - AgileConfig__AppId=KonSoft.AuthServer + - AgileConfig__Name=KonSoft.AuthServer + - AgileConfig__Nodes=https://config.konsoft.top/ + - AgileConfig__Secret=DBE31703-14F9-4B01-893D-900B8380CE04 + + adminservice: + container_name: clean-adminservice + restart: always + build: + context: . + dockerfile: ./microservices/KonSoft.Admin.HttpApi.Host/Dockerfile + environment: + - ASPNETCORE_ENVIRONMENT=Test + - AgileConfig__AppId=KonSoft.Admin.HttpApi.Host + - AgileConfig__Name=KonSoft.Admin.HttpApi.Host + - AgileConfig__Nodes=https://config.konsoft.top/ + - AgileConfig__Secret=DBE31703-14F9-4B01-893D-900B8380CE04 \ No newline at end of file diff --git a/gateways/KonSoft.InternalGateway/Controllers/WeatherForecastController.cs b/gateways/KonSoft.InternalGateway/Controllers/WeatherForecastController.cs deleted file mode 100644 index ca53b86..0000000 --- a/gateways/KonSoft.InternalGateway/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace KonSoft.InternalGateway.Controllers; - -[ApiController] -[Route("[controller]")] -public class WeatherForecastController : ControllerBase -{ - private static readonly string[] Summaries = - [ - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - ]; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } -} \ No newline at end of file diff --git a/gateways/KonSoft.InternalGateway/Dockerfile b/gateways/KonSoft.InternalGateway/Dockerfile new file mode 100644 index 0000000..19e12f9 --- /dev/null +++ b/gateways/KonSoft.InternalGateway/Dockerfile @@ -0,0 +1,29 @@ +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER $APP_UID +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["NuGet.Config", "."] +COPY ["gateways/KonSoft.InternalGateway/KonSoft.InternalGateway.csproj", "gateways/KonSoft.InternalGateway/"] +COPY ["shared/KonSoft.Shared.Hosting.Gateways/KonSoft.Shared.Hosting.Gateways.csproj", "shared/KonSoft.Shared.Hosting.Gateways/"] +COPY ["shared/KonSoft.Shared.Hosting.AspNetCore/KonSoft.Shared.Hosting.AspNetCore.csproj", "shared/KonSoft.Shared.Hosting.AspNetCore/"] +COPY ["shared/KonSoft.Shared.Hosting/KonSoft.Shared.Hosting.csproj", "shared/KonSoft.Shared.Hosting/"] +COPY ["shared/KonSoft.Shared.Localization/KonSoft.Shared.Localization.csproj", "shared/KonSoft.Shared.Localization/"] +RUN dotnet restore "./gateways/KonSoft.InternalGateway/KonSoft.InternalGateway.csproj" +COPY . . +WORKDIR "/src/gateways/KonSoft.InternalGateway" +RUN dotnet build "./KonSoft.InternalGateway.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./KonSoft.InternalGateway.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "KonSoft.InternalGateway.dll"] \ No newline at end of file diff --git a/gateways/KonSoft.InternalGateway/InternalGatewayModule.cs b/gateways/KonSoft.InternalGateway/InternalGatewayModule.cs new file mode 100644 index 0000000..f046065 --- /dev/null +++ b/gateways/KonSoft.InternalGateway/InternalGatewayModule.cs @@ -0,0 +1,17 @@ +using KonSoft.Shared.Hosting.Gateways; +using Volo.Abp; +using Volo.Abp.Modularity; + +namespace KonSoft.InternalGateway +{ + [DependsOn( + typeof(KonSoftSharedHostingGatewaysModule) + )] + public class InternalGatewayModule : AbpModule + { + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + + } + } +} diff --git a/gateways/KonSoft.InternalGateway/KonSoft.InternalGateway.csproj b/gateways/KonSoft.InternalGateway/KonSoft.InternalGateway.csproj index 5419ef0..4bd0fa3 100644 --- a/gateways/KonSoft.InternalGateway/KonSoft.InternalGateway.csproj +++ b/gateways/KonSoft.InternalGateway/KonSoft.InternalGateway.csproj @@ -4,10 +4,18 @@ net8.0 enable enable + 98521e87-fe4a-4555-8c3b-e83559a64e03 + Linux + ..\.. - + + + + + + diff --git a/gateways/KonSoft.InternalGateway/Program.cs b/gateways/KonSoft.InternalGateway/Program.cs index 8264bac..ae03f33 100644 --- a/gateways/KonSoft.InternalGateway/Program.cs +++ b/gateways/KonSoft.InternalGateway/Program.cs @@ -1,25 +1,37 @@ -var builder = WebApplication.CreateBuilder(args); +using KonSoft.InternalGateway; +using KonSoft.Shared.Hosting.AspNetCore; +using Serilog; -// Add services to the container. +var assemblyName = typeof(Program).Assembly.GetName().Name!; +SerilogConfigurationHelper.Configure(assemblyName); -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); - -var app = builder.Build(); - -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) +try { - app.UseSwagger(); - app.UseSwaggerUI(); + var builder = WebApplication.CreateBuilder(args); + builder.Configuration + .AddAgileConfig(option => + { + option.ENV = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"; + }); + builder.Host + .AddAppSettingsSecretsJson() + .UseAutofac() + .UseSerilog(); + builder.Services.AddReverseProxy() + .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy")); + await builder.AddApplicationAsync(); + var app = builder.Build(); + await app.InitializeApplicationAsync(); + await app.RunAsync(); + + return 0; } - -app.UseHttpsRedirection(); - -app.UseAuthorization(); - -app.MapControllers(); - -app.Run(); \ No newline at end of file +catch (Exception ex) +{ + Log.Fatal(ex, $"{assemblyName} terminated unexpectedly!"); + return 1; +} +finally +{ + await Log.CloseAndFlushAsync(); +} \ No newline at end of file diff --git a/gateways/KonSoft.InternalGateway/Properties/launchSettings.json b/gateways/KonSoft.InternalGateway/Properties/launchSettings.json index 407c599..ed7fdeb 100644 --- a/gateways/KonSoft.InternalGateway/Properties/launchSettings.json +++ b/gateways/KonSoft.InternalGateway/Properties/launchSettings.json @@ -1,33 +1,24 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:15968", - "sslPort": 44395 - } - }, +{ "profiles": { "http": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "http://localhost:5090", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5090" }, "https": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "https://localhost:7264;http://localhost:5090", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7264;http://localhost:5090" }, "IIS Express": { "commandName": "IISExpress", @@ -36,6 +27,26 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_HTTPS_PORTS": "8081", + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": true + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:15968", + "sslPort": 44395 } } -} +} \ No newline at end of file diff --git a/gateways/KonSoft.InternalGateway/WeatherForecast.cs b/gateways/KonSoft.InternalGateway/WeatherForecast.cs deleted file mode 100644 index 9b07419..0000000 --- a/gateways/KonSoft.InternalGateway/WeatherForecast.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace KonSoft.InternalGateway; - -public class WeatherForecast -{ - public DateOnly Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } -} \ No newline at end of file diff --git a/gateways/KonSoft.InternalGateway/appsettings.json b/gateways/KonSoft.InternalGateway/appsettings.json index 10f68b8..8b93288 100644 --- a/gateways/KonSoft.InternalGateway/appsettings.json +++ b/gateways/KonSoft.InternalGateway/appsettings.json @@ -1,9 +1,8 @@ { - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" + "AgileConfig": { + "appId": "KonSoft.InternalGateway", + "name": "KonSoft.InternalGateway", + "nodes": "https://config.konsoft.top/", + "secret": "DBE31703-14F9-4B01-893D-900B8380CE04" + } } diff --git a/microservices/KonSoft.Admin.HttpApi.Host/Dockerfile b/microservices/KonSoft.Admin.HttpApi.Host/Dockerfile index 582ca45..183f46b 100644 --- a/microservices/KonSoft.Admin.HttpApi.Host/Dockerfile +++ b/microservices/KonSoft.Admin.HttpApi.Host/Dockerfile @@ -4,7 +4,6 @@ WORKDIR /app EXPOSE 8080 -# 此阶段用于生成服务项目 FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src diff --git a/microservices/KonSoft.Admin.HttpApi.Host/KonSoft.Admin.HttpApi.Host.csproj b/microservices/KonSoft.Admin.HttpApi.Host/KonSoft.Admin.HttpApi.Host.csproj index 5debc82..cee14aa 100644 --- a/microservices/KonSoft.Admin.HttpApi.Host/KonSoft.Admin.HttpApi.Host.csproj +++ b/microservices/KonSoft.Admin.HttpApi.Host/KonSoft.Admin.HttpApi.Host.csproj @@ -17,6 +17,10 @@ + + + + diff --git a/microservices/KonSoft.Admin.HttpApi.Host/Properties/launchSettings.json b/microservices/KonSoft.Admin.HttpApi.Host/Properties/launchSettings.json index dfbbc2f..4660c69 100644 --- a/microservices/KonSoft.Admin.HttpApi.Host/Properties/launchSettings.json +++ b/microservices/KonSoft.Admin.HttpApi.Host/Properties/launchSettings.json @@ -1,5 +1,4 @@ { - "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { "http": { "commandName": "Project", @@ -8,6 +7,18 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "applicationUrl": "https://localhost:44354" + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "environmentVariables": { + "ASPNETCORE_HTTPS_PORTS": "8081", + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": true } - } + }, + "$schema": "http://json.schemastore.org/launchsettings.json" } \ No newline at end of file diff --git a/shared/KonSoft.Shared.Hosting.Gateways/Class1.cs b/shared/KonSoft.Shared.Hosting.Gateways/Class1.cs deleted file mode 100644 index 50833c3..0000000 --- a/shared/KonSoft.Shared.Hosting.Gateways/Class1.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace KonSoft.Shared.Hosting.Gateways; - -public class Class1 -{ -} \ No newline at end of file diff --git a/shared/KonSoft.Shared.Hosting.Gateways/KonSoft.Shared.Hosting.Gateways.csproj b/shared/KonSoft.Shared.Hosting.Gateways/KonSoft.Shared.Hosting.Gateways.csproj index 51a05d1..d380fd6 100644 --- a/shared/KonSoft.Shared.Hosting.Gateways/KonSoft.Shared.Hosting.Gateways.csproj +++ b/shared/KonSoft.Shared.Hosting.Gateways/KonSoft.Shared.Hosting.Gateways.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/shared/KonSoft.Shared.Hosting.Gateways/KonSoftSharedHostingGatewaysModule.cs b/shared/KonSoft.Shared.Hosting.Gateways/KonSoftSharedHostingGatewaysModule.cs new file mode 100644 index 0000000..a412920 --- /dev/null +++ b/shared/KonSoft.Shared.Hosting.Gateways/KonSoftSharedHostingGatewaysModule.cs @@ -0,0 +1,11 @@ +using KonSoft.Shared.Hosting.AspNetCore; +using Volo.Abp.Modularity; + +namespace KonSoft.Shared.Hosting.Gateways; + +[DependsOn( + typeof(KonSoftSharedHostingAspNetCoreModule) + )] +public class KonSoftSharedHostingGatewaysModule : AbpModule +{ +} \ No newline at end of file