From 2f1672df37862cdd791a34707dbdd7ea8a01f2c2 Mon Sep 17 00:00:00 2001 From: ruberoid Date: Thu, 16 Oct 2025 23:04:23 +0400 Subject: [PATCH] Optimized steps for Dockerfile's --- src/Nocr.TelegramListener.Host/Dockerfile | 46 +++++++++++------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/Nocr.TelegramListener.Host/Dockerfile b/src/Nocr.TelegramListener.Host/Dockerfile index 9ce9e24..e8e9100 100644 --- a/src/Nocr.TelegramListener.Host/Dockerfile +++ b/src/Nocr.TelegramListener.Host/Dockerfile @@ -1,14 +1,12 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app -RUN apt-get update && apt-get install -y ca-certificates && update-ca-certificates -RUN apt-get install -y curl && rm -rf /var/lib/apt/lists/* EXPOSE 80 EXPOSE 443 FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src -# Install and update CA certificates FIRST before any network operations +# Install CA certificates for custom NuGet source RUN apt-get update && \ apt-get install -y --no-install-recommends ca-certificates && \ update-ca-certificates && \ @@ -16,33 +14,31 @@ RUN apt-get update && \ COPY . . -# Create global NuGet.Config with package source mapping +# Create NuGet.Config using cat with heredoc RUN mkdir -p /root/.nuget/NuGet && \ - echo '' > /root/.nuget/NuGet/NuGet.Config && \ - echo '' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo ' ' >> /root/.nuget/NuGet/NuGet.Config && \ - echo '' >> /root/.nuget/NuGet/NuGet.Config + cat > /root/.nuget/NuGet/NuGet.Config <<'EOF' + + + + + + + + + + + + + + + +EOF -# Restore with verbose logging -RUN dotnet restore "src/Nocr.TelegramListener.Host/Nocr.TelegramListener.Host.csproj" --verbosity normal +# Publish directly (restore + build + publish in one step) WORKDIR "/src/src/Nocr.TelegramListener.Host" -RUN dotnet build "Nocr.TelegramListener.Host.csproj" -c Release -o /app/build - -FROM build AS publish RUN dotnet publish "Nocr.TelegramListener.Host.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app -COPY --from=publish /app/publish . +COPY --from=build /app/publish . ENTRYPOINT ["dotnet", "Nocr.TelegramListener.Host.dll"]