1
Fork 0
mirror of https://gitlab.com/Kwoth/nadekobot.git synced 2024-10-02 20:13:13 +00:00
nadekobot/Dockerfile

60 lines
2.1 KiB
Docker
Raw Permalink Normal View History

2024-05-15 07:29:08 +00:00
# Use the .NET 8.0 SDK as the base image for the build stage
2024-05-09 10:31:46 +00:00
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source
2024-05-15 07:29:08 +00:00
# Copy the .csproj files for each project
COPY src/Nadeko.Medusa/*.csproj src/Nadeko.Medusa/
COPY src/NadekoBot/*.csproj src/NadekoBot/
COPY src/NadekoBot.Coordinator/*.csproj src/NadekoBot.Coordinator/
COPY src/NadekoBot.Generators/*.csproj src/NadekoBot.Generators/
2024-05-09 06:56:57 +00:00
COPY src/NadekoBot.Voice/*.csproj src/NadekoBot.Voice/
2022-07-27 04:37:04 +00:00
COPY NuGet.Config ./
2024-05-15 07:29:08 +00:00
# Restore the dependencies for the NadekoBot project
RUN dotnet restore src/NadekoBot/
2024-05-15 07:29:08 +00:00
# Copy the rest of the source code
COPY . .
2024-05-15 07:29:08 +00:00
# Set the working directory to the NadekoBot project
WORKDIR /source/src/NadekoBot
2024-05-15 07:29:08 +00:00
# Build and publish the NadekoBot project, then clean up unnecessary files
2021-09-27 00:10:18 +00:00
RUN set -xe; \
dotnet --version; \
dotnet publish -c Release -o /app --no-restore; \
mv /app/data /app/data_init; \
2024-05-09 12:21:48 +00:00
rm -Rf libopus* libsodium* opus.* runtimes/win* runtimes/osx* runtimes/linux-arm* runtimes/linux-mips*; \
2021-09-27 00:10:18 +00:00
find /app -type f -exec chmod -x {} \; ;\
chmod +x /app/NadekoBot
2024-05-15 07:29:08 +00:00
# Use the .NET 8.0 runtime as the base image for the final stage
2024-05-09 10:31:46 +00:00
FROM mcr.microsoft.com/dotnet/runtime:8.0
WORKDIR /app
2021-09-27 00:10:18 +00:00
2024-05-15 07:29:08 +00:00
# Create a new user, install dependencies, and set up sudoers file
2021-09-27 00:10:18 +00:00
RUN set -xe; \
useradd -m nadeko; \
apt-get update; \
2024-05-15 07:29:08 +00:00
apt-get install -y --no-install-recommends libsqlite3-0 curl ffmpeg sudo python3; \
2021-09-27 00:10:18 +00:00
echo 'Defaults>nadeko env_keep+="ASPNETCORE_* DOTNET_* NadekoBot_* shard_id total_shards TZ"' > /etc/sudoers.d/nadeko; \
2023-08-16 07:14:39 +00:00
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; \
2022-05-26 15:01:06 +00:00
apt-get autoremove -y; \
apt-get autoclean -y
2021-09-27 00:10:18 +00:00
2024-05-15 07:29:08 +00:00
# Copy the built application and the entrypoint script from the build stage
COPY --from=build /app ./
2021-09-27 00:10:18 +00:00
COPY docker-entrypoint.sh /usr/local/sbin
2024-05-15 07:29:08 +00:00
# Set environment variables
2021-09-27 00:10:18 +00:00
ENV shard_id=0
ENV total_shards=1
ENV NadekoBot__creds=/app/data/creds.yml
2021-09-27 00:10:18 +00:00
2024-05-15 07:29:08 +00:00
# Define the data directory as a volume
2022-04-10 11:54:49 +00:00
VOLUME [ "/app/data" ]
2024-05-15 07:29:08 +00:00
# Set the entrypoint and default command
2021-09-27 00:10:18 +00:00
ENTRYPOINT [ "/usr/local/sbin/docker-entrypoint.sh" ]
2024-05-16 20:52:58 +00:00
CMD dotnet NadekoBot.dll "$shard_id" "$total_shards"