elliebot/Dockerfile

60 lines
2.1 KiB
Text
Raw Normal View History

# Use the .NET 8.0 SDK as the base image for the build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
2024-06-18 11:48:54 +00:00
WORKDIR /source
# Copy the .csproj files for each project
2024-06-18 11:48:54 +00:00
COPY src/Ellie.Marmalade/*.csproj src/Ellie.Marmalade/
COPY src/EllieBot/*.csproj src/EllieBot/
COPY src/EllieBot.Coordinator/*.csproj src/EllieBot.Coordinator/
COPY src/EllieBot.Generators/*.csproj src/EllieBot.Generators/
COPY src/EllieBot.Voice/*.csproj src/EllieBot.Voice/
# Restore the dependencies for the EllieBot project
2024-06-18 11:48:54 +00:00
RUN dotnet restore src/EllieBot/
# Copy the rest of the source code
2024-06-18 11:48:54 +00:00
COPY . .
# Set the working directory to the EllieBot project
2024-06-18 11:48:54 +00:00
WORKDIR /source/src/EllieBot
# Build and publish the EllieBot project, then clean up unnecessary files
2024-06-18 11:48:54 +00:00
RUN set -xe; \
dotnet --version; \
dotnet publish -c Release -o /app --no-restore; \
mv /app/data /app/data_init; \
rm -Rf libopus* libsodium* opus.* runtimes/win* runtimes/osx* runtimes/linux-arm* runtimes/linux-mips*; \
find /app -type f -exec chmod -x {} \; ;\
chmod +x /app/EllieBot
# Use the .NET 8.0 runtime as the base image for the final stage
FROM mcr.microsoft.com/dotnet/runtime:8.0
2024-06-18 11:48:54 +00:00
WORKDIR /app
# Create a new user, install dependencies, and set up sudoers file
2024-06-18 11:48:54 +00:00
RUN set -xe; \
useradd -m ellie; \
apt-get update; \
apt-get install -y --no-install-recommends libopus0 libsodium23 libsqlite3-0 curl ffmpeg python3 sudo; \
echo 'Defaults>ellie env_keep+="ASPNETCORE_* DOTNET_* EllieBot_* shard_id total_shards TZ"' > /etc/sudoers.d/ellie; \
curl -Lo /usr/local/bin/yt-dlp https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp; \
chmod a+rx /usr/local/bin/yt-dlp; \
apt-get autoremove -y; \
apt-get autoclean -y
# Copy the built application and the entrypoint script from the build stage
2024-06-18 11:48:54 +00:00
COPY --from=build /app ./
COPY docker-entrypoint.sh /usr/local/sbin
# Set environment variables
2024-06-18 11:48:54 +00:00
ENV shard_id=0
ENV total_shards=1
ENV EllieBot__creds=/app/data/creds.yml
# Define the data directory as a volume
2024-06-18 11:48:54 +00:00
VOLUME [" /app/data "]
# Set the entrypoint and default command
2024-06-18 11:48:54 +00:00
ENTRYPOINT [ "/usr/local/sbin/docker-entrypoint.sh" ]
CMD dotnet EllieBot.dll "$shard_id" "$total_shards"