Use Alpine as the base image in docker, publish a self-contained app (#974)

pull/980/head
Velithris 2 years ago committed by GitHub
parent fc07f8da6c
commit db45b49af7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,7 @@
# Build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
WORKDIR /build
COPY favicon.ico ./
COPY NuGet.config ./
@ -7,16 +9,30 @@ COPY Directory.Build.props ./
COPY DiscordChatExporter.Core ./DiscordChatExporter.Core
COPY DiscordChatExporter.Cli ./DiscordChatExporter.Cli
RUN dotnet publish DiscordChatExporter.Cli --configuration Release --output ./publish
RUN dotnet publish DiscordChatExporter.Cli \
--self-contained \
--use-current-runtime \
--configuration Release \
--output ./publish
# Run
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS run
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine
RUN useradd dce
# tzdata is needed for DateTimeOffset.ToLocalTime (for TimeZoneInfo.Local, to be precise)
RUN apk add --no-cache tzdata
RUN adduser \
--disabled-password \
--no-create-home \
dce
USER dce
COPY --from=build /build/publish /opt/discord_chat_exporter
COPY --from=build ./publish ./
WORKDIR ./out
# Need to keep this as /out for backwards compatibility with documentation.
# A lot of people have this directory mounted in their scripts files, so
# changing it would break existing workflows.
WORKDIR /out
ENTRYPOINT ["dotnet", "../DiscordChatExporter.Cli.dll"]
# Having it in PATH is convenient for interactive shell sessions,
# which may be useful for debugging.
ENV PATH="$PATH:/opt/discord_chat_exporter"
ENTRYPOINT ["DiscordChatExporter.Cli"]

@ -1,5 +1,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
namespace DiscordChatExporter.Core.Discord.Data.Common;
@ -39,7 +40,8 @@ public readonly partial record struct FileSize(long TotalBytes)
}
[ExcludeFromCodeCoverage]
public override string ToString() => $"{GetLargestWholeNumberValue():0.##} {GetLargestWholeNumberSymbol()}";
public override string ToString() =>
string.Create(CultureInfo.InvariantCulture, $"{GetLargestWholeNumberValue():0.##} {GetLargestWholeNumberSymbol()}");
}
public partial record struct FileSize

Loading…
Cancel
Save