DiscordChatExporter/DiscordChatExporter.Cli.dockerfile

52 lines
2.3 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-10 17:05:27 -05:00
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.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-10-31 17:40:41 -04:00
WORKDIR /tmp/dce
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-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-10 17:05:27 -05:00
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/runtime-deps:7.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"
LABEL org.opencontainers.image.url="https://github.com/Tyrrrz/DiscordChatExporter"
LABEL org.opencontainers.image.source="https://github.com/Tyrrrz/DiscordChatExporter/blob/master/DiscordChatExporter.Cli.dockerfile"
LABEL org.opencontainers.image.licenses="MIT"
2023-11-11 09:27:17 -05:00
# Alpine image doesn't come with the ICU libraries pre-installed, so we need to install them manually
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-05-10 15:02:50 -04:00
# Create a non-root user to run the app, so that the output files can be accessed by the host
2023-01-05 07:20:49 -05:00
# https://github.com/Tyrrrz/DiscordChatExporter/issues/851
2023-05-10 15:02:50 -04:00
RUN adduser --disabled-password --no-create-home dce
USER dce
2023-01-05 07:20:49 -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-10-31 17:40:41 -04:00
COPY --from=build /tmp/dce/DiscordChatExporter.Cli/bin/publish /opt/dce
2023-05-10 17:06:30 -04:00
ENTRYPOINT ["/opt/dce/DiscordChatExporter.Cli"]