???: did some docker stuff. The Project can run, but the db needs to be linked from outside, or it does not work.

This commit is contained in:
limited_dev 2023-02-12 21:38:00 +01:00
parent db1d4822d4
commit f0fbb11824
4 changed files with 13 additions and 4 deletions

1
DockerRunCommand Normal file
View file

@ -0,0 +1 @@
docker run --rm -it -p8080:80 -v/home/limited_dev/Documents/Code/School/imageboard/ImageBoardServerApp/Data/Nils.db:/app/Data/Nils.db ade4c760feb9

View file

@ -16,6 +16,4 @@ RUN dotnet publish "ImageBoardServerApp/ImageBoardServerApp.csproj" -c Release -
FROM base AS final FROM base AS final
WORKDIR /app WORKDIR /app
COPY --from=publish /app/publish . COPY --from=publish /app/publish .
RUN dotnet tool install --global dotnet-ef
RUN dotnet ef database update
ENTRYPOINT ["dotnet", "ImageBoardServerApp.dll"] ENTRYPOINT ["dotnet", "ImageBoardServerApp.dll"]

View file

@ -11,7 +11,9 @@ internal sealed class AppDBContext : DbContext
public DbSet<ReportData> Reports { get; set; } public DbSet<ReportData> Reports { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlite("Data Source=./Data/Nils.db"); {
optionsBuilder.UseSqlite("Data Source=./Data/Nils.db");
}
protected override void OnModelCreating(ModelBuilder mb) protected override void OnModelCreating(ModelBuilder mb)
{ {

View file

@ -1,4 +1,5 @@
using ImageBoardServerApp.Auth; using ImageBoardServerApp.Auth;
using ImageBoardServerApp.Data;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
@ -10,6 +11,7 @@ builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor(); builder.Services.AddServerSideBlazor();
builder.Services.AddScoped<ProtectedSessionStorage>(); builder.Services.AddScoped<ProtectedSessionStorage>();
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthenticationStateProvider>(); builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthenticationStateProvider>();
builder.Services.AddSingleton<AppDBContext>();
var app = builder.Build(); var app = builder.Build();
@ -30,4 +32,10 @@ app.UseRouting();
app.MapBlazorHub(); app.MapBlazorHub();
app.MapFallbackToPage("/_Host"); app.MapFallbackToPage("/_Host");
using (var serviceScope = app.Services.CreateScope())
{
var context = serviceScope.ServiceProvider.GetService<AppDBContext>();
context.Database.EnsureCreated();
}
app.Run(); app.Run();