Compare commits

...

3 Commits

3 changed files with 39 additions and 2 deletions

View File

@ -129,7 +129,7 @@ namespace Apimanager_backend.Controllers
// 5. 创建存储目录 // 5. 创建存储目录
var uploadsFolder = Path.Combine(basePath); var uploadsFolder = Path.Combine(basePath,"uploads");
var filePath = Path.Combine(uploadsFolder, "logo.png"); var filePath = Path.Combine(uploadsFolder, "logo.png");
// 7. 处理并保存图片 // 7. 处理并保存图片
@ -188,7 +188,7 @@ namespace Apimanager_backend.Controllers
// 3. 保存到网站根目录 // 3. 保存到网站根目录
var icoPath = Path.Combine(_environment.WebRootPath, "favicon.ico"); var icoPath = Path.Combine(basePath,"uploads", "favicon.ico");
using (var stream = new FileStream(icoPath, FileMode.Create)) using (var stream = new FileStream(icoPath, FileMode.Create))
{ {
await file.CopyToAsync(stream); await file.CopyToAsync(stream);

View File

@ -6,6 +6,7 @@ using Apimanager_backend.Filters.ExceptionFilter;
using Apimanager_backend.Services; using Apimanager_backend.Services;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Serilog; using Serilog;
using Serilog.Sinks.MariaDB.Extensions; using Serilog.Sinks.MariaDB.Extensions;
@ -158,6 +159,13 @@ app.Use(async (context, next) =>
}); });
*/ */
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "uploads")),
RequestPath = "/uploads"
});
app.MapControllers(); app.MapControllers();
app.Run(); app.Run();

29
Dockerfile Normal file
View File

@ -0,0 +1,29 @@
# 使用 .NET 8.0 SDK 作为构建环境
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
# 1. 复制解决方案文件和所有项目的.csproj文件自动包含所有项目
COPY *.sln .
COPY */*.csproj ./
# 为每个项目创建目录并移动.csproj文件到正确位置
RUN for file in $(ls *.csproj); do mkdir -p ${file%.*}/ && mv $file ${file%.*}/; done
# 2. 恢复所有项目的依赖
RUN dotnet restore "Apimanager_backend.sln"
# 3. 复制所有源代码
COPY . .
# 4. 构建并发布主项目假设Apimanager_backend是启动项目
WORKDIR /src/Apimanager_backend
RUN dotnet publish -c Release -o /app/publish --no-restore
# 5. 使用运行时镜像
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/publish .
# 6. 配置容器
ENV ASPNETCORE_ENVIRONMENT=Development
EXPOSE 8080
ENTRYPOINT ["dotnet", "Apimanager_backend.dll"]