diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/HuanMengProject.sln b/HuanMengProject.sln index 0760ebd..97bce27 100644 --- a/HuanMengProject.sln +++ b/HuanMengProject.sln @@ -46,6 +46,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HuanMeng.MiaoYu.WebApi", "s EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TextCensorFilterTest", "src\9-test\TextCensorFilterTest\TextCensorFilterTest.csproj", "{CF7FEDBA-FC1A-4D6D-92F1-6882B5143E0A}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "解决方案项", "解决方案项", "{054999FD-BE65-4520-90B7-5228975F1229}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/README.md b/README.md index 13244bc..594790e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,18 @@ # HuanMengProject 开发文档 +## docker 发布 +```sh +# 在解决方案下运行 +docker build -t miaoyu:dev-0.0.3 -f src/2-api/HuanMeng.MiaoYu.WebApi/Dockerfile . +# 运行 +docker run -d -p 90:90 -v E://disk/output:/app/output --name webapi miaoyu:dev-0.0.3 +# 运行。挂载日志文件夹 +docker run -d -p 90:90 -v E://disk/output:/app/output --name webapi miaoyu:dev-0.0.3 + +## 设置最大内存 +--memory=3g + +``` ### 项目说明 ```sh diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Dockerfile b/src/2-api/HuanMeng.MiaoYu.WebApi/Dockerfile new file mode 100644 index 0000000..b9c0a1f --- /dev/null +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Dockerfile @@ -0,0 +1,56 @@ +# ָûʹõ .NET 8.0 ASP.NET Core ʱ +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base + +# Է root ûУ߰ȫ +#USER app + +# ڵĹĿ¼Ϊ /app/diskIJĿ¼ +WORKDIR /app/disk + +# 90 ˿ڣⲿӦ +EXPOSE 90 + +# ù׶Σʹ .NET 8.0 SDK +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build + +# һòĬΪ Release +ARG BUILD_CONFIGURATION=Release + +# ù׶εĹĿ¼Ϊ /src +WORKDIR /src + +# Ŀļеָ·ںԭ +COPY ["src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj", "2-api/HuanMeng.MiaoYu.WebApi/"] +COPY ["src/0-core/HuanMeng.DotNetCore/HuanMeng.DotNetCore.csproj", "0-core/HuanMeng.DotNetCore/"] +COPY ["src/0-core/HuanMeng.MiaoYu.Code/HuanMeng.MiaoYu.Code.csproj", "0-core/HuanMeng.MiaoYu.Code/"] +COPY ["src/0-core/HuanMeng.MiaoYu.Model/HuanMeng.MiaoYu.Model.csproj", "0-core/HuanMeng.MiaoYu.Model/"] + +# ԭĿ +RUN dotnet restore "2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj" + +# Դļ +COPY . . + +# лĿ¼ Web API ĿĿ¼ +WORKDIR "/src/src/2-api/HuanMeng.MiaoYu.WebApi" + +# Ŀ /app/disk/build Ŀ¼ +RUN dotnet build "./HuanMeng.MiaoYu.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/disk/build + +# ÷׶Σ build ׶οʼ +FROM build AS publish + +# ʹ Release ÷Ŀ /app/disk/publish Ŀ¼ AppHost +RUN dotnet publish "./HuanMeng.MiaoYu.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/disk/publish /p:UseAppHost=false + +# о񣬻 base +FROM base AS final + +# лĿ¼ /app/disk +WORKDIR /app/disk + +# ׶εƵվ +COPY --from=publish /app/disk/publish . + +# Ӧóڵ㣬 Web API Ӧ +ENTRYPOINT ["dotnet", "HuanMeng.MiaoYu.WebApi.dll"] diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj b/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj index e7d797c..6687090 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj @@ -6,6 +6,8 @@ false enable True + Linux + ..\..\.. @@ -13,6 +15,7 @@ + diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Properties/launchSettings.json b/src/2-api/HuanMeng.MiaoYu.WebApi/Properties/launchSettings.json index e0b1ecb..3c03bb8 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Properties/launchSettings.json +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Properties/launchSettings.json @@ -1,23 +1,14 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:20926", - "sslPort": 0 - } - }, +{ "profiles": { "http": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "http://localhost:5083", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5083" }, "IIS Express": { "commandName": "IISExpress", @@ -26,6 +17,24 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:20926", + "sslPort": 0 } } -} +} \ No newline at end of file