From e06587114551a863f4d7a3c2e39799b492ad0283 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Sun, 21 Aug 2022 22:40:44 -0400 Subject: [PATCH] revert some things --- .dockerignore | 4 +- Dockerfile | 37 ++++++++++++------- Dockerfile.old | 12 ++++++ .../Filters/ETagFilter.cs | 23 +++++++++++- src/TerribleDev.Blog.Web/Startup.cs | 3 +- .../TerribleDev.Blog.Web.csproj | 1 + .../Views/Shared/_Layout.cshtml | 3 +- .../wwwroot/css/dark.old.css | 13 +++++++ src/TerribleDev.Blog.Web/wwwroot/css/site.css | 14 ------- 9 files changed, 77 insertions(+), 33 deletions(-) create mode 100644 Dockerfile.old create mode 100644 src/TerribleDev.Blog.Web/wwwroot/css/dark.old.css diff --git a/.dockerignore b/.dockerignore index df2e0fe..809f31e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,6 +4,6 @@ .gitignore .vs .vscode -*/bin -*/obj +**/bin +**/obj **/.toolstarget \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f4e1cfd..c2b5591 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,26 @@ -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env +# https://hub.docker.com/_/microsoft-dotnet +FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY ./src/TerribleDev.Blog.Web/*.csproj . +RUN dotnet restore -r linux-musl-x64 /p:PublishReadyToRunComposite=true + +# copy everything else and build app +COPY ./src/TerribleDev.Blog.Web/ . +RUN dotnet publish -c release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRunComposite=true /p:PublishSingleFile=true +RUN date +%s > /app/buildtime.txt +# final stage/image +FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-alpine-amd64 WORKDIR /app +COPY --from=build /app ./ -# Copy csproj and restore as distinct layers -COPY *.sln . -COPY . . -RUN dotnet restore +# See: https://github.com/dotnet/announcements/issues/20 +# Uncomment to enable globalization APIs (or delete) +# ENV \ +# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ +# LC_ALL=en_US.UTF-8 \ +# LANG=en_US.UTF-8 +# RUN apk add --no-cache icu-libs -# Copy everything else and build -COPY . . -RUN dotnet publish -c Release -o out - -# Build runtime image -FROM mcr.microsoft.com/dotnet/aspnet:6.0 -WORKDIR /app -COPY --from=build-env /app/out . -ENTRYPOINT ["dotnet", "TerribleDev.Blog.Web.dll"] \ No newline at end of file +ENTRYPOINT ["./TerribleDev.Blog.Web"] \ No newline at end of file diff --git a/Dockerfile.old b/Dockerfile.old new file mode 100644 index 0000000..6cf455a --- /dev/null +++ b/Dockerfile.old @@ -0,0 +1,12 @@ +FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build +WORKDIR /app + +# Copy everything else and build +COPY /src/TerribleDev.Blog.Web . +RUN dotnet publish -c release -o /out -r linux-musl-x64 --self-contained true /p:PublishTrimmed=true /p:PublishReadyToRunComposite=true /p:PublishSingleFile=true +RUN date +%s > /out/buildtime.txt +# Build runtime image +FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-alpine-amd64 +WORKDIR /app +COPY --from=build /app/out . +ENTRYPOINT ["./TerribleDev.Blog.Web"] \ No newline at end of file diff --git a/src/TerribleDev.Blog.Web/Filters/ETagFilter.cs b/src/TerribleDev.Blog.Web/Filters/ETagFilter.cs index 08e257f..55fac1e 100644 --- a/src/TerribleDev.Blog.Web/Filters/ETagFilter.cs +++ b/src/TerribleDev.Blog.Web/Filters/ETagFilter.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Concurrent; +using System.IO; +using System.Linq; using System.Security.Cryptography; using System.Text; using Microsoft.AspNetCore.Mvc; @@ -9,7 +11,26 @@ namespace TerribleDev.Blog.Web.Filters { public class StaticETag: ActionFilterAttribute { - public static string staticEtag = "\"" + MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString())).ToHexString().Substring(0,8) + "\""; + static StaticETag() + { + string etagString; + if(File.Exists("buildtime.txt")) + { + Console.WriteLine("buildtime.txt found"); + etagString = File.ReadAllText("buildtime.txt"); + } + else + { + Console.WriteLine("buildtime.txt not found"); + Console.WriteLine("Directory list"); + Console.WriteLine(Directory.GetFiles(".", "*", SearchOption.AllDirectories).Aggregate((a, b) => a + "\n" + b)); + var unixTime = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString(); + Console.WriteLine("Using Unix Time for Etag: " + unixTime); + etagString = unixTime; + } + StaticETag.staticEtag = "\"" + MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(etagString)).ToHexString().Substring(0,8) + "\""; + } + public static string staticEtag; public static ConcurrentDictionary cache = new ConcurrentDictionary(); public override void OnActionExecuted(ActionExecutedContext context) { diff --git a/src/TerribleDev.Blog.Web/Startup.cs b/src/TerribleDev.Blog.Web/Startup.cs index efcf01e..e6051f8 100644 --- a/src/TerribleDev.Blog.Web/Startup.cs +++ b/src/TerribleDev.Blog.Web/Startup.cs @@ -89,6 +89,7 @@ namespace TerribleDev.Blog.Web // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { + Console.WriteLine("ETag Detected As: " + StaticETag.staticEtag); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); @@ -163,4 +164,4 @@ namespace TerribleDev.Blog.Web }); } } -} +} \ No newline at end of file diff --git a/src/TerribleDev.Blog.Web/TerribleDev.Blog.Web.csproj b/src/TerribleDev.Blog.Web/TerribleDev.Blog.Web.csproj index 8f7537d..b721545 100644 --- a/src/TerribleDev.Blog.Web/TerribleDev.Blog.Web.csproj +++ b/src/TerribleDev.Blog.Web/TerribleDev.Blog.Web.csproj @@ -4,6 +4,7 @@ net6.0 InProcess Linux + linux-musl-x64 diff --git a/src/TerribleDev.Blog.Web/Views/Shared/_Layout.cshtml b/src/TerribleDev.Blog.Web/Views/Shared/_Layout.cshtml index 62e8310..731efa7 100644 --- a/src/TerribleDev.Blog.Web/Views/Shared/_Layout.cshtml +++ b/src/TerribleDev.Blog.Web/Views/Shared/_Layout.cshtml @@ -42,7 +42,8 @@ Skip to main content
- + @* *@ +
diff --git a/src/TerribleDev.Blog.Web/wwwroot/css/dark.old.css b/src/TerribleDev.Blog.Web/wwwroot/css/dark.old.css new file mode 100644 index 0000000..f0236b9 --- /dev/null +++ b/src/TerribleDev.Blog.Web/wwwroot/css/dark.old.css @@ -0,0 +1,13 @@ +@media (prefers-color-scheme: dark) { + :root { + --headline: #f0f0f0; + --body-text-color: #ffffff; + --block-quote-left-border: #d1dced; + --code-block-background-color: #4a4a4a; + --primary-background: #323131; + --link-color: #3faff9; + /* --link-visited: #d8dbde; */ + --border-color: #bdcad2; + --horizontal-rule: #626468; + } +} \ No newline at end of file diff --git a/src/TerribleDev.Blog.Web/wwwroot/css/site.css b/src/TerribleDev.Blog.Web/wwwroot/css/site.css index 1929ca4..d0a1a0e 100644 --- a/src/TerribleDev.Blog.Web/wwwroot/css/site.css +++ b/src/TerribleDev.Blog.Web/wwwroot/css/site.css @@ -13,20 +13,6 @@ --nav-bar-text-color: var(--primary-background); } -@media (prefers-color-scheme: dark) { - :root { - --headline: #f0f0f0; - --body-text-color: #ffffff; - --block-quote-left-border: #d1dced; - --code-block-background-color: #4a4a4a; - --primary-background: #323131; - --link-color: #3faff9; - /* --link-visited: #d8dbde; */ - --border-color: #bdcad2; - --horizontal-rule: #626468; - } -} - html { font-family: Arial, Helvetica, sans-serif; }