mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-25 04:04:22 -04:00
Make dockerfile more platform-agnostic
This commit is contained in:
parent
c3f181c9e0
commit
a332bda07d
1 changed files with 20 additions and 20 deletions
|
@ -1,7 +1,16 @@
|
||||||
# -- Build
|
# -- Build
|
||||||
# Use the same platform for the build image as the runtime image, so that it's easier
|
# Specify the platform here so that we pull the SDK image matching the host platform,
|
||||||
# to produce a self-contained assembly for the right platform.
|
# instead of the target platform specified during build by the `--platform` option.
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:7.0-runtime AS build
|
# Use the .NET 8.0 preview because the `--arch` option is only available in that version.
|
||||||
|
# https://github.com/dotnet/dotnet-docker/issues/4388#issuecomment-1459038566
|
||||||
|
# TODO: switch images to Alpine once .NET 8.0 is released.
|
||||||
|
# Currently, the correct preview version is only available on Debian.
|
||||||
|
# https://github.com/dotnet/dotnet-docker/blob/main/samples/selecting-tags.md
|
||||||
|
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview AS build
|
||||||
|
|
||||||
|
# Expose the target architecture set by the `docker build --platform` option, so that
|
||||||
|
# we can build the assembly for the correct platform.
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
|
|
||||||
|
@ -13,33 +22,24 @@ COPY DiscordChatExporter.Cli ./DiscordChatExporter.Cli
|
||||||
|
|
||||||
# Publish a self-contained assembly so we can use a slimmer runtime image
|
# Publish a self-contained assembly so we can use a slimmer runtime image
|
||||||
RUN dotnet publish DiscordChatExporter.Cli \
|
RUN dotnet publish DiscordChatExporter.Cli \
|
||||||
|
--configuration Release \
|
||||||
--self-contained \
|
--self-contained \
|
||||||
--use-current-runtime \
|
--use-current-runtime \
|
||||||
--configuration Release \
|
--arch $TARGETARCH \
|
||||||
--output ./publish
|
--output ./publish
|
||||||
|
|
||||||
# -- Run
|
# -- Run
|
||||||
# Use Alpine for the runtime image due to its smaller size.
|
# Use `runtime-deps` instead of `runtime` because we have a self-contained assembly
|
||||||
# Use `runtime-deps` instead of `runtime` since we're running a self-contained assembly.
|
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/runtime-deps:7.0 AS run
|
||||||
# https://github.com/dotnet/dotnet-docker/blob/main/samples/selecting-tags.md
|
|
||||||
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine
|
|
||||||
|
|
||||||
# Alpine image doesn't include timezone data, which is needed for certain date/time operations
|
|
||||||
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
|
|
||||||
RUN apk add --no-cache tzdata
|
|
||||||
|
|
||||||
# Create a non-root user to run the app, so that the output files can be accessed by the host
|
# Create a non-root user to run the app, so that the output files can be accessed by the host
|
||||||
# https://github.com/Tyrrrz/DiscordChatExporter/issues/851
|
# https://github.com/Tyrrrz/DiscordChatExporter/issues/851
|
||||||
RUN adduser --disabled-password --no-create-home dce
|
RUN adduser --disabled-password --no-create-home dce
|
||||||
USER dce
|
USER dce
|
||||||
|
|
||||||
COPY --from=build /build/publish /opt/dce
|
# This directory is exposed to the user for mounting purposes, so it's important that it always
|
||||||
|
# stays the same for backwards compatibility.
|
||||||
# Add the app directory to the PATH so that it's easier to run the app via `docker exec`
|
|
||||||
ENV PATH="$PATH:/opt/dce"
|
|
||||||
|
|
||||||
# This directory is exposed to the user for mounting purposes, so it's important
|
|
||||||
# that it stays the same for backwards compatibility.
|
|
||||||
WORKDIR /out
|
WORKDIR /out
|
||||||
|
|
||||||
ENTRYPOINT ["DiscordChatExporter.Cli"]
|
COPY --from=build /build/publish /opt/dce
|
||||||
|
ENTRYPOINT ["/opt/dce/DiscordChatExporter.Cli"]
|
Loading…
Add table
Add a link
Reference in a new issue