diff --git a/.gitignore b/.gitignore index 4a0e7bf..1f86ad5 100644 --- a/.gitignore +++ b/.gitignore @@ -265,4 +265,4 @@ src/MyWebLog/wwwroot/img/bit-badger src/MyWebLog/appsettings.Production.json # SQLite database files -src/MyWebLog/*.db* +src/MyWebLog/data/*.db* diff --git a/src/Dockerfile b/src/Dockerfile index d05e417..48fd7e8 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build WORKDIR /mwl COPY ./MyWebLog.sln ./ COPY ./Directory.Build.props ./ @@ -9,7 +9,7 @@ RUN dotnet restore COPY . ./ WORKDIR /mwl/MyWebLog -RUN dotnet publish -f net7.0 -c Release -r linux-x64 --no-self-contained -p:PublishSingleFile=false +RUN dotnet publish -f net8.0 -c Release -r linux-x64 --no-self-contained -p:PublishSingleFile=false FROM alpine AS theme RUN apk add --no-cache zip @@ -19,12 +19,13 @@ RUN zip default-theme.zip ./default-theme/* COPY ./admin-theme ./admin-theme/ RUN zip admin-theme.zip ./admin-theme/* -FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine as final +FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine as final WORKDIR /app RUN apk add --no-cache icu-libs ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false -COPY --from=build /mwl/MyWebLog/bin/Release/net7.0/linux-x64/publish/ ./ +COPY --from=build /mwl/MyWebLog/bin/Release/net8.0/linux-x64/publish/ ./ COPY --from=theme /themes/*.zip /app/ +RUN mkdir themes EXPOSE 80 CMD [ "dotnet", "/app/MyWebLog.dll" ] diff --git a/src/MyWebLog/Handlers/Admin.fs b/src/MyWebLog/Handlers/Admin.fs index f535f84..91904fd 100644 --- a/src/MyWebLog/Handlers/Admin.fs +++ b/src/MyWebLog/Handlers/Admin.fs @@ -482,7 +482,7 @@ module Theme = do! ThemeAssetCache.refreshTheme themeId data TemplateCache.invalidateTheme themeId // Save the .zip file - use file = new FileStream($"{themeId}-theme.zip", FileMode.Create) + use file = new FileStream($"./themes/{themeId}-theme.zip", FileMode.Create) do! themeFile.CopyToAsync file do! addMessage ctx { UserMessage.Success with @@ -517,7 +517,7 @@ module Theme = | _ -> match! data.Theme.Delete (ThemeId themeId) with | true -> - let zippedTheme = $"{themeId}-theme.zip" + let zippedTheme = $"./themes/{themeId}-theme.zip" if File.Exists zippedTheme then File.Delete zippedTheme do! addMessage ctx { UserMessage.Success with Message = $"Theme ID {themeId} deleted successfully" } return! all next ctx diff --git a/src/MyWebLog/Program.fs b/src/MyWebLog/Program.fs index 382a013..d9918f1 100644 --- a/src/MyWebLog/Program.fs +++ b/src/MyWebLog/Program.fs @@ -98,7 +98,7 @@ module DataImplementation = log.LogInformation $"Using PostgreSQL database {conn.Database}" PostgresData(log, Json.configure (JsonSerializer.CreateDefault())) else - createSQLite "Data Source=./myweblog.db;Cache=Shared" + createSQLite "Data Source=./data/myweblog.db;Cache=Shared" open System.Threading.Tasks @@ -176,7 +176,7 @@ let main args = let _ = builder.Services.AddScoped(fun sp -> Sqlite.Configuration.dbConn ()) let _ = builder.Services.AddScoped() // Use SQLite for caching as well - let cachePath = defaultArg (Option.ofObj (cfg.GetConnectionString "SQLiteCachePath")) "./session.db" + let cachePath = defaultArg (Option.ofObj (cfg.GetConnectionString "SQLiteCachePath")) "./data/session.db" let _ = builder.Services.AddSqliteCache(fun o -> o.CachePath <- cachePath) () | :? PostgresData as postgres -> @@ -214,9 +214,12 @@ let main args = printfn $"""Unrecognized command "{it}" - valid commands are:""" showHelp () | None -> task { - // Load all themes in the application directory - for themeFile in Directory.EnumerateFiles(".", "*-theme.zip") do - do! Maintenance.loadTheme [| ""; themeFile |] app.Services + // Load admin and default themes, and all themes in the /themes directory + do! Maintenance.loadTheme [| ""; "./admin-theme.zip" |] app.Services + do! Maintenance.loadTheme [| ""; "./default-theme.zip" |] app.Services + if Directory.Exists "./themes" then + for themeFile in Directory.EnumerateFiles("./themes", "*-theme.zip") do + do! Maintenance.loadTheme [| ""; themeFile |] app.Services let _ = app.UseForwardedHeaders() diff --git a/src/sqlite.Dockerfile b/src/sqlite.Dockerfile index cf71ceb..68b895f 100644 --- a/src/sqlite.Dockerfile +++ b/src/sqlite.Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /mwl COPY ./MyWebLog.sln ./ COPY ./Directory.Build.props ./ @@ -9,7 +9,7 @@ RUN dotnet restore COPY . ./ WORKDIR /mwl/MyWebLog -RUN dotnet publish -f net7.0 -c Release -r linux-x64 +RUN dotnet publish -f net8.0 -c Release -r linux-x64 FROM alpine AS theme RUN apk add --no-cache zip @@ -19,10 +19,11 @@ RUN zip default-theme.zip ./default-theme/* COPY ./admin-theme ./admin-theme/ RUN zip admin-theme.zip ./admin-theme/* -FROM mcr.microsoft.com/dotnet/aspnet:7.0 as final +FROM mcr.microsoft.com/dotnet/aspnet:8.0 as final WORKDIR /app -COPY --from=build /mwl/MyWebLog/bin/Release/net7.0/linux-x64/publish/ ./ +COPY --from=build /mwl/MyWebLog/bin/Release/net8.0/linux-x64/publish/ ./ COPY --from=theme /themes/*.zip /app/ +RUN mkdir data themes EXPOSE 80 CMD [ "/app/MyWebLog" ]