Updated Dockerfile

This commit is contained in:
Toastie 2025-02-14 20:48:44 +13:00
parent 600625c83c
commit 13496e4a51
Signed by: toastie_t0ast
GPG key ID: 10B7576CB1C1BEDF

View file

@ -1,4 +1,4 @@
# Use the .NET 8.0 SDK as the base image for the build stage # Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source WORKDIR /source
@ -16,45 +16,34 @@ RUN dotnet restore src/EllieBot/ -r linux-musl-x64
# Copy the rest of the source code # Copy the rest of the source code
COPY . . COPY . .
# Set the working directory to the EllieBot project
WORKDIR /source/src/EllieBot WORKDIR /source/src/EllieBot
# Build and publish the EllieBot project, then clean up unnecessary files # Build for linux-musl-x64 runtime as the image is based on alpine
RUN dotnet publish -c Release -o /app --self-contained -r linux-musl-x64 --no-restore; \ RUN dotnet publish -c Release -o /app --self-contained -r linux-musl-x64 --no-restore \
mv /app/data /app/data_init; \ && mv /app/data /app/data_init \
chmod +x /app/EllieBot && chmod +x /app/EllieBot
# Use the .NET 8.0 runtime as the base image for the final stage # Final stage
FROM alpine:3.20 FROM alpine:3.20
WORKDIR /app WORKDIR /app
# Music dependencies # Music dependencies
# python3 required for yt-dlp, ffmpeg for conversion
ADD --chmod=755 https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp /usr/local/bin/yt-dlp ADD --chmod=755 https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp /usr/local/bin/yt-dlp
RUN apk add --no-cache ffmpeg python3 libsodium RUN apk add --no-cache ffmpeg python3 libsodium
# Required dependencies # Required dependencies
# libc6-compat is required for .NET 8.0 # icu-libs is required for globalization
# libstdc++ and libgcc are required for (.NET 8.0 ? or drawing?)
# icu-libs is required for C# globalization
RUN apk update; \ RUN apk update; \
apk add --no-cache libstdc++ libgcc icu-libs libc6-compat \ apk add --no-cache libstdc++ libgcc icu-libs libc6-compat \
&& rm -rf /var/cache/apk/*; && rm -rf /var/cache/apk/*;
# Copy the built application and the entrypoint script from the build stage
COPY --from=build /app ./ COPY --from=build /app ./
COPY docker-entrypoint.sh /usr/local/sbin/ COPY docker-entrypoint.sh /usr/local/sbin/
# TODO: is there a better way to link the libsodium.so?
# TODO: Temporary linking, needs a proper solution
RUN rm /app/data_init/lib/libsodium.so \ RUN rm /app/data_init/lib/libsodium.so \
&& ln -s /usr/lib/libsodium.so.26 /app/data_init/lib/libsodium.so && ln -s /usr/lib/libsodium.so.26 /app/data_init/lib/libsodium.so
# Define the data directory as a volume
VOLUME [ "/app/data" ] VOLUME [ "/app/data" ]
# Set the entrypoint and default command
ENTRYPOINT [ "/usr/local/sbin/docker-entrypoint.sh" ] ENTRYPOINT [ "/usr/local/sbin/docker-entrypoint.sh" ]
CMD [ "./EllieBot" ] CMD [ "./EllieBot" ]