添加docker发布
This commit is contained in:
parent
b18eabb9fc
commit
818eb95bbd
30
.dockerignore
Normal file
30
.dockerignore
Normal file
|
|
@ -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/**
|
||||||
|
|
@ -46,6 +46,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HuanMeng.MiaoYu.WebApi", "s
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TextCensorFilterTest", "src\9-test\TextCensorFilterTest\TextCensorFilterTest.csproj", "{CF7FEDBA-FC1A-4D6D-92F1-6882B5143E0A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TextCensorFilterTest", "src\9-test\TextCensorFilterTest\TextCensorFilterTest.csproj", "{CF7FEDBA-FC1A-4D6D-92F1-6882B5143E0A}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "解决方案项", "解决方案项", "{054999FD-BE65-4520-90B7-5228975F1229}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
README.md = README.md
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|
|
||||||
13
README.md
13
README.md
|
|
@ -1,5 +1,18 @@
|
||||||
# HuanMengProject 开发文档
|
# 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
|
```sh
|
||||||
|
|
|
||||||
56
src/2-api/HuanMeng.MiaoYu.WebApi/Dockerfile
Normal file
56
src/2-api/HuanMeng.MiaoYu.WebApi/Dockerfile
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
# 该指令用于设置基础镜像,使用的是 .NET 8.0 ASP.NET Core 运行时镜像
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||||
|
|
||||||
|
# 以非 root 用户身份运行,以提高安全性
|
||||||
|
#USER app
|
||||||
|
|
||||||
|
# 设置容器内的工作目录为 /app/disk,后续的操作都会基于这个目录
|
||||||
|
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"]
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
<PublishAot>false</PublishAot>
|
<PublishAot>false</PublishAot>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
<DockerfileContext>..\..\..</DockerfileContext>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -13,6 +15,7 @@
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.7" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
|
||||||
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
|
||||||
<PackageReference Include="Serilog" Version="4.0.0" />
|
<PackageReference Include="Serilog" Version="4.0.0" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,14 @@
|
||||||
{
|
{
|
||||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
|
||||||
"iisSettings": {
|
|
||||||
"windowsAuthentication": false,
|
|
||||||
"anonymousAuthentication": true,
|
|
||||||
"iisExpress": {
|
|
||||||
"applicationUrl": "http://localhost:20926",
|
|
||||||
"sslPort": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"http": {
|
"http": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "swagger",
|
"launchUrl": "swagger",
|
||||||
"applicationUrl": "http://localhost:5083",
|
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
},
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"applicationUrl": "http://localhost:5083"
|
||||||
},
|
},
|
||||||
"IIS Express": {
|
"IIS Express": {
|
||||||
"commandName": "IISExpress",
|
"commandName": "IISExpress",
|
||||||
|
|
@ -26,6 +17,24 @@
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user