mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-09-05 23:57:19 +08:00
feat: update Dockerfile to install EF Core tools and perform database migrations
This commit is contained in:
+7
-2
@@ -13,11 +13,17 @@ RUN bun run build
|
|||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||||
ARG BUILD_CONFIGURATION=Release
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
ENV DEFAULT_CONNECTION="Host=yourhost;Username=foxel;Password=foxel;Database=foxel"
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ["Foxel.csproj", "./"]
|
COPY ["Foxel.csproj", "./"]
|
||||||
RUN dotnet restore "Foxel.csproj"
|
RUN dotnet restore "Foxel.csproj"
|
||||||
COPY . .
|
COPY . .
|
||||||
WORKDIR "/src/"
|
WORKDIR "/src/"
|
||||||
|
# 安装EF Core工具并执行数据库迁移
|
||||||
|
RUN dotnet tool install --global dotnet-ef
|
||||||
|
ENV PATH="$PATH:/root/.dotnet/tools"
|
||||||
|
RUN dotnet ef migrations add InitialCreate -- --environment Production
|
||||||
|
RUN dotnet ef database update -- --environment Production
|
||||||
RUN dotnet build "./Foxel.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
RUN dotnet build "./Foxel.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
FROM build AS publish
|
FROM build AS publish
|
||||||
@@ -26,8 +32,7 @@ RUN dotnet publish "./Foxel.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:U
|
|||||||
|
|
||||||
FROM base AS final
|
FROM base AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# Format: Host=yourhost;Username=foxel;Password=foxel;Database=foxel
|
ENV DEFAULT_CONNECTION="Host=yourhost;Username=foxel;Password=foxel;Database=foxel"
|
||||||
ENV DEFAULT_CONNECTION="YourDefaultConnectionStringHere"
|
|
||||||
COPY --from=publish /app/publish .
|
COPY --from=publish /app/publish .
|
||||||
RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
|
||||||
COPY --from=build-frontend /src/View/dist /var/www/html
|
COPY --from=build-frontend /src/View/dist /var/www/html
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class DatabaseInitializer(
|
|||||||
string password = GenerateRandomPassword(6);
|
string password = GenerateRandomPassword(6);
|
||||||
string passwordHash = HashPassword(password);
|
string passwordHash = HashPassword(password);
|
||||||
|
|
||||||
logger.LogInformation("创建管理员用户,用户名: Admin,密码: {Password}", password);
|
logger.LogInformation("创建管理员用户,邮箱: you@foxel.cc,密码: {Password}", password);
|
||||||
adminUser = new User
|
adminUser = new User
|
||||||
{
|
{
|
||||||
UserName = "Admin",
|
UserName = "Admin",
|
||||||
@@ -114,8 +114,8 @@ public class DatabaseInitializer(
|
|||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine($"[重要] 管理员账户初始密码: {password},请及时修改");
|
Console.WriteLine($"[重要] 管理员账户初始密码: {password},请及时修改");
|
||||||
|
Console.WriteLine($"[重要] 请及时登录后台修改AI相关配置,系统才可正常运行");
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
|
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user