Skip to content

Commit

Permalink
chore: update base image, target framework, and dependencies
Browse files Browse the repository at this point in the history
- Change base image from `mcr.microsoft.com/dotnet/sdk:6.0` to `registry.access.redhat.com/ubi9/ubi-minimal`
- Update `TZ` environment variable to `Asia/Taipei`
- Update base image from `registry.access.redhat.com/ubi8/dotnet-80` to `base`
- Update target framework from `net6.0` to `net8.0`
- Update `PackageReference` versions for `Discord.Net.Webhook`, `Microsoft.Extensions.Hosting`, and `YoutubeDLSharp`
- Remove `COPY ["YoutubeLiveChatToDiscord.csproj", "."]`
- Remove `RUN dotnet build "YoutubeLiveChatToDiscord.csproj" -c Release -o /app/build`
- Remove `FROM build AS publish`
- Change `dotnet publish` command to include additional parameters
- Remove `dotnet publish` command for copying output files
- Update `ENTRYPOINT` command to `./YoutubeLiveChatToDiscord $@`
- Remove last line of the Dockerfile
- No changes in `YoutubeLiveChatToDiscord.csproj`

Signed-off-by: 陳鈞 <[email protected]>
  • Loading branch information
jim60105 committed Dec 2, 2023
1 parent 3738369 commit 647cdd6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
59 changes: 37 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
ENTRYPOINT ./YoutubeLiveChatToDiscord $@
15 changes: 7 additions & 8 deletions YoutubeLiveChatToDiscord.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-LiveChatToDiscord-ACE24696-7DD5-4164-8805-CF76B90CBA6C</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>.</DockerfileContext>
<ServerGarbageCollection>false</ServerGarbageCollection>
</PropertyGroup>

</PropertyGroup>
<ItemGroup>
<PackageReference Include="Discord.Net.Webhook" Version="3.8.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="Discord.Net.Webhook" Version="3.13.0" />

<PackageReference Include="YoutubeDLSharp" Version="0.4.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />

</ItemGroup>
</Project>
</Project>

0 comments on commit 647cdd6

Please sign in to comment.