From 02f688a6cbfc41e3f3517b83cca7efa84001ad28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=98=8E=E9=94=8B?= Date: Tue, 28 Nov 2023 10:54:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86dockerfile=E6=9B=B4=E6=96=B0=E4=B8=BA8?= =?UTF-8?q?.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/web/Liuliu.Demo.WebApi/Dockerfile | 47 +++++----- .../web/Liuliu.Demo.WebApi/appsettings.json | 93 ++++++++++++++++++- 2 files changed, 117 insertions(+), 23 deletions(-) diff --git a/samples/web/Liuliu.Demo.WebApi/Dockerfile b/samples/web/Liuliu.Demo.WebApi/Dockerfile index 4fa2893e1..036740335 100644 --- a/samples/web/Liuliu.Demo.WebApi/Dockerfile +++ b/samples/web/Liuliu.Demo.WebApi/Dockerfile @@ -1,39 +1,44 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. +#See https://aka.ms/customizecontainer to learn how to customize your debug container and 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 +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER app WORKDIR /app EXPOSE 80 EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release WORKDIR /src -COPY ["samples/web/Liuliu.Demo.WebApi/Liuliu.Demo.WebApi.csproj", "samples/web/Liuliu.Demo.WebApi/"] -COPY ["src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj", "src/OSharp.EntityFrameworkCore.Sqlite/"] -COPY ["src/OSharp.EntityFrameworkCore/OSharp.EntityFrameworkCore.csproj", "src/OSharp.EntityFrameworkCore/"] +COPY ["src/OSharp.Utils/OSharp.Utils.csproj", "src/OSharp.Utils/"] COPY ["src/OSharp/OSharp.csproj", "src/OSharp/"] -COPY ["src/OSharp.MiniProfiler/OSharp.MiniProfiler.csproj", "src/OSharp.MiniProfiler/"] -COPY ["src/OSharp.AspNetCore/OSharp.AspNetCore.csproj", "src/OSharp.AspNetCore/"] -COPY ["src/OSharp.Swagger/OSharp.Swagger.csproj", "src/OSharp.Swagger/"] -COPY ["src/OSharp.Log4Net/OSharp.Log4Net.csproj", "src/OSharp.Log4Net/"] COPY ["src/OSharp.AutoMapper/OSharp.AutoMapper.csproj", "src/OSharp.AutoMapper/"] -COPY ["src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj", "src/OSharp.Hosting.Apis/"] -COPY ["src/OSharp.Hosting.EntityConfiguration/OSharp.Hosting.EntityConfiguration.csproj", "src/OSharp.Hosting.EntityConfiguration/"] -COPY ["src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj", "src/OSharp.Hosting.Core/"] -COPY ["src/OSharp.Authorization.Functions/OSharp.Authorization.Functions.csproj", "src/OSharp.Authorization.Functions/"] -COPY ["src/OSharp.Identity/OSharp.Identity.csproj", "src/OSharp.Identity/"] -COPY ["src/OSharp.Authorization.Datas/OSharp.Authorization.Datas.csproj", "src/OSharp.Authorization.Datas/"] +COPY ["src/OSharp.AspNetCore/OSharp.AspNetCore.csproj", "src/OSharp.AspNetCore/"] +COPY ["src/OSharp.EntityFrameworkCore/OSharp.EntityFrameworkCore.csproj", "src/OSharp.EntityFrameworkCore/"] COPY ["src/OSharp.EntityFrameworkCore.MySql/OSharp.EntityFrameworkCore.MySql.csproj", "src/OSharp.EntityFrameworkCore.MySql/"] -COPY ["src/OSharp.Hangfire/OSharp.Hangfire.csproj", "src/OSharp.Hangfire/"] COPY ["src/OSharp.EntityFrameworkCore.PostgreSql/OSharp.EntityFrameworkCore.PostgreSql.csproj", "src/OSharp.EntityFrameworkCore.PostgreSql/"] -COPY ["src/OSharp.Redis/OSharp.Redis.csproj", "src/OSharp.Redis/"] +COPY ["src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj", "src/OSharp.EntityFrameworkCore.Sqlite/"] COPY ["src/OSharp.EntityFrameworkCore.SqlServer/OSharp.EntityFrameworkCore.SqlServer.csproj", "src/OSharp.EntityFrameworkCore.SqlServer/"] -RUN dotnet restore "samples/web/Liuliu.Demo.WebApi/Liuliu.Demo.WebApi.csproj" +COPY ["src/OSharp.Identity/OSharp.Identity.csproj", "src/OSharp.Identity/"] +COPY ["src/OSharp.Authorization.Functions/OSharp.Authorization.Functions.csproj", "src/OSharp.Authorization.Functions/"] +COPY ["src/OSharp.Authorization.Datas/OSharp.Authorization.Datas.csproj", "src/OSharp.Authorization.Datas/"] +COPY ["src/OSharp.Log4Net/OSharp.Log4Net.csproj", "src/OSharp.Log4Net/"] +COPY ["src/OSharp.MiniProfiler/OSharp.MiniProfiler.csproj", "src/OSharp.MiniProfiler/"] +COPY ["src/OSharp.Redis/OSharp.Redis.csproj", "src/OSharp.Redis/"] +COPY ["src/OSharp.Swagger/OSharp.Swagger.csproj", "src/OSharp.Swagger/"] +COPY ["src/OSharp.Hangfire/OSharp.Hangfire.csproj", "src/OSharp.Hangfire/"] +COPY ["src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj", "src/OSharp.Hosting.Core/"] +COPY ["src/OSharp.Hosting.EntityConfiguration/OSharp.Hosting.EntityConfiguration.csproj", "src/OSharp.Hosting.EntityConfiguration/"] +COPY ["src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj", "src/OSharp.Hosting.Apis/"] +COPY ["samples/web/Liuliu.Demo.WebApi/Liuliu.Demo.WebApi.csproj", "samples/web/Liuliu.Demo.WebApi/"] + +RUN dotnet restore "./samples/web/Liuliu.Demo.WebApi/./Liuliu.Demo.WebApi.csproj" COPY . . WORKDIR "/src/samples/web/Liuliu.Demo.WebApi" -RUN dotnet build "Liuliu.Demo.WebApi.csproj" -c Release -o /app/build +RUN dotnet build "./Liuliu.Demo.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/build FROM build AS publish -RUN dotnet publish "Liuliu.Demo.WebApi.csproj" -c Release -o /app/publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./Liuliu.Demo.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false FROM base AS final WORKDIR /app diff --git a/samples/web/Liuliu.Demo.WebApi/appsettings.json b/samples/web/Liuliu.Demo.WebApi/appsettings.json index 93b64d37a..a4e379804 100644 --- a/samples/web/Liuliu.Demo.WebApi/appsettings.json +++ b/samples/web/Liuliu.Demo.WebApi/appsettings.json @@ -1,4 +1,4 @@ -{ +{ "Logging": { "LogLevel": { "Default": "Information", @@ -6,5 +6,94 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "CaptchaOptions": { + "CaptchaType": 9, // 验证码类型 + "CodeLength": 4, // 验证码长度, 要放在CaptchaType设置后 当类型为算术表达式时,长度代表操作的个数 + "ExpirySeconds": 60, // 验证码过期秒数 + "IgnoreCase": true, // 比较时是否忽略大小写 + "StoreageKeyPrefix": "Common:Captcha:", // 存储键前缀 + "ImageOption": { + "Animation": true, // 是否启用动画 + "FontSize": 32, // 字体大小 + "Width": 100, // 验证码宽度 + "Height": 40, // 验证码高度 + "BubbleMinRadius": 5, // 气泡最小半径 + "BubbleMaxRadius": 15, // 气泡最大半径 + "BubbleCount": 5, // 气泡数量 + "BubbleThickness": 1.5, // 气泡边沿厚度 + "InterferenceLineCount": 4, // 干扰线数量 + "FontFamily": "actionj" // 包含中文时请使用kaiti。可设置字体:actionj,epilog,fresnel,headache,lexo,prefix,progbot,ransom,robot,scandal,kaiti + } + }, + "OSharp": { + "DbContexts": { + "SqlServer": { + "DbContextTypeName": "OSharp.Entity.DefaultDbContext,OSharp.EntityFrameworkCore", + "ConnectionString": "Server=127.0.0.1;Database=osharpns-api-dev;User Id=sa;Password=Abc123456!;TrustServerCertificate=True;", + "DatabaseType": "SqlServer", + "AuditEntityEnabled": true, + "AutoMigrationEnabled": true + } + }, + "MailSender": { + "Host": "smtp.66soft.net", + "Port": 465, + "EnableSsl": true, + "DisplayName": "OSharp邮件发送", + "UserName": "osharpsender@66soft.net", + "Password": "Cculm3WYoAjuEbwl" + }, + "Jwt": { + "Issuer": "osharp identity", + "Audience": "osharp api client", + "Secret": "{8619F7C3-B53C-4B85-99F0-983D351ECD82}", + "AccessExpireMins": 20, + "RefreshExpireMins": 10080, // 7天 + "IsRefreshAbsoluteExpired": false, + "Enabled": true + }, + "Cookie": { + "Enabled": true + }, + "Mvc": { + "IsLowercaseJsonProperty": true, + "IsLowercaseUrls": true + }, + "Cors": { + "PolicyName": "MyCors", + "AllowAnyHeader": true, + "WithMethods": [ "POST", "PUT", "DELETE" ], + "WithOrigins": [], + "Enabled": true + }, + "Redis": { + "Configuration": "localhost", + "InstanceName": "Liuliu.Demo:" + }, + "Swagger": { + "Endpoints": [ + { + "Title": "框架API", + "Version": "v1", + "Url": "/swagger/v1/swagger.json" + }, + { + "Title": "业务API", + "Version": "buss", + "Url": "/swagger/buss/swagger.json" + } + ], + "RoutePrefix": "swagger", + "IsHideSchemas": false, + "MiniProfiler": false, + "Enabled": true + }, + "Hangfire": { + "WorkerCount": 20, + //"StorageConnectionString": "Server=.;Database=osharpns.hangfire-dev;User Id=sa;Password=Abc123456!;MultipleActiveResultSets=true", + "DashboardUrl": "/hangfire", + "Roles": "" + } + } }