diff --git a/Dockerfile b/Dockerfile index e8b364e..396104b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,50 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. +### Base image +FROM registry.access.redhat.com/ubi9/ubi-minimal AS base -FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine AS base -WORKDIR /app -RUN apk add --no-cache --virtual build-deps musl-dev gcc g++ python3-dev &&\ - apk add --no-cache py3-pip tzdata &&\ - pip install yt-dlp &&\ - apk del build-deps ENV TZ=Asia/Taipei +RUN microdnf -y install python3.11 tzdata && \ + microdnf clean all && \ + ln -s /usr/bin/python3.11 /usr/bin/python3 -# Disable file locking on Unix -# https://github.com/dotnet/runtime/issues/34126#issuecomment-1104981659 -ENV DOTNET_SYSTEM_IO_DISABLEFILELOCKING=true +RUN python3 -m venv /venv +ENV PATH="/venv/bin:$PATH" -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +### Build yt-dlp +FROM base AS build_ytdlp + +RUN microdnf -y install python3.11-pip && \ + pip3.11 install yt-dlp && \ + microdnf -y remove python3.11-pip && \ + microdnf clean all + +### Build .NET +FROM registry.access.redhat.com/ubi8/dotnet-80 AS build + +USER 0 WORKDIR /src -COPY ["YoutubeLiveChatToDiscord.csproj", "."] + +COPY YoutubeLiveChatToDiscord.csproj . RUN dotnet restore "./YoutubeLiveChatToDiscord.csproj" COPY . . -WORKDIR "/src/." -RUN dotnet build "YoutubeLiveChatToDiscord.csproj" -c Release -o /app/build -FROM build AS publish -RUN dotnet publish "YoutubeLiveChatToDiscord.csproj" -c Release -o /app/publish +RUN dotnet publish "YoutubeLiveChatToDiscord.csproj" -c Release -o /src/publish -p:PublishTrimmed=true --self-contained true +### Final image FROM base AS final + +# Disable file locking on Unix +# https://github.com/dotnet/runtime/issues/34126#issuecomment-1104981659 +ENV DOTNET_SYSTEM_IO_DISABLEFILELOCKING=true + +# Determines whether a .NET Core app runs in globalization-invariant mode without access to culture-specific data and behavior. +# https://aka.ms/dotnet-missing-libicu +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true + WORKDIR /app -COPY --from=publish /app/publish . -RUN addgroup -g 1000 docker && \ - adduser -u 1000 -G docker -h /home/docker -s /bin/sh -D docker \ - && chown -R 1000:1000 . -USER docker +COPY --link --chown=1001:1001 --from=build /src/publish . +COPY --link --from=build_ytdlp /venv /venv + +USER 0 -ENTRYPOINT ["dotnet", "YoutubeLiveChatToDiscord.dll"] \ No newline at end of file +ENTRYPOINT ./YoutubeLiveChatToDiscord $@ \ No newline at end of file diff --git a/YoutubeLiveChatToDiscord.csproj b/YoutubeLiveChatToDiscord.csproj index beb59b4..54d9e7f 100644 --- a/YoutubeLiveChatToDiscord.csproj +++ b/YoutubeLiveChatToDiscord.csproj @@ -1,19 +1,18 @@ - - net6.0 +net8.0 enable enable dotnet-LiveChatToDiscord-ACE24696-7DD5-4164-8805-CF76B90CBA6C Linux . false - - + - - - + + + + - + \ No newline at end of file