DiscordChatExporter/DiscordChatExporter.Cli.dockerfile

59 lines
2.4 KiB
Text
Raw Normal View History

2023-01-05 07:20:49 -05:00
# -- Build
2023-05-10 17:06:30 -04:00
# Specify the platform here so that we pull the SDK image matching the host platform,
# instead of the target platform specified during build by the `--platform` option.
2023-11-14 13:05:15 -05:00
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
2023-05-10 17:06:30 -04:00
# Expose the target architecture set by the `docker build --platform` option, so that
# we can build the assembly for the correct platform.
ARG TARGETARCH
2023-11-23 10:51:37 -05:00
# Allow setting the assembly version from the build command
ARG VERSION=0.0.0
2023-11-14 16:31:12 -05:00
WORKDIR /tmp/app
2022-06-18 15:37:24 -04:00
COPY favicon.ico .
COPY NuGet.config .
COPY Directory.Build.props .
COPY DiscordChatExporter.Core DiscordChatExporter.Core
COPY DiscordChatExporter.Cli DiscordChatExporter.Cli
2022-06-18 15:37:24 -04:00
2023-05-10 15:02:50 -04:00
# Publish a self-contained assembly so we can use a slimmer runtime image
RUN dotnet publish DiscordChatExporter.Cli \
2023-11-23 10:51:37 -05:00
-p:Version=$VERSION \
2023-08-22 14:36:50 -04:00
-p:CSharpier_Bypass=true \
2023-11-01 09:30:15 -04:00
--configuration Release \
--self-contained \
--use-current-runtime \
2023-05-10 17:06:30 -04:00
--arch $TARGETARCH \
2023-10-31 17:40:41 -04:00
--output DiscordChatExporter.Cli/bin/publish/
2022-06-18 15:37:24 -04:00
2023-01-05 07:20:49 -05:00
# -- Run
2023-05-10 17:06:30 -04:00
# Use `runtime-deps` instead of `runtime` because we have a self-contained assembly
2023-11-14 13:05:15 -05:00
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine AS run
2023-01-05 07:20:49 -05:00
2023-11-09 06:11:59 -05:00
LABEL org.opencontainers.image.title="DiscordChatExporter.Cli"
2023-11-07 08:02:41 -05:00
LABEL org.opencontainers.image.description="DiscordChatExporter is an application that can be used to export message history from any Discord channel to a file."
LABEL org.opencontainers.image.authors="tyrrrz.me"
2023-11-23 10:51:37 -05:00
LABEL org.opencontainers.image.source="https://github.com/Tyrrrz/DiscordChatExporter"
2023-11-07 08:02:41 -05:00
LABEL org.opencontainers.image.licenses="MIT"
2023-11-15 17:38:18 -05:00
# Alpine image doesn't come with the ICU libraries pre-installed, so we need to install them manually.
# We need the full ICU data because we allow the user to specify any locale for formatting purposes.
RUN apk add --no-cache icu-libs
2023-11-11 09:48:26 -05:00
RUN apk add --no-cache icu-data-full
2023-11-11 09:27:17 -05:00
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
2023-11-11 09:56:49 -05:00
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
2023-11-11 09:27:17 -05:00
2023-11-15 17:38:18 -05:00
# Use a non-root user to ensure that the files shared with the host are accessible by the host user.
# We can use the default user provided by the base image for this purpose.
2023-11-15 08:18:13 -05:00
# https://github.com/Tyrrrz/DiscordChatExporter/issues/851
USER app
2023-11-15 08:18:13 -05:00
2023-05-10 17:06:30 -04:00
# This directory is exposed to the user for mounting purposes, so it's important that it always
# stays the same for backwards compatibility.
WORKDIR /out
2022-10-16 09:34:31 -04:00
2023-11-15 08:18:13 -05:00
COPY --from=build /tmp/app/DiscordChatExporter.Cli/bin/publish /opt/app
2023-11-14 16:31:12 -05:00
ENTRYPOINT ["/opt/app/DiscordChatExporter.Cli"]