Skip to content

Commit 97a1933

Browse files
refactor: replace nuget update source with user-level NuGet.Config write
Instead of mutating the project-level nuget.config with backup/restore, write a credentials-only XML to /root/.nuget/NuGet/NuGet.Config inside the BuildKit secret mount. NuGet merges packageSourceCredentials from the user-level config independently of <clear /> in packageSources, so packageSourceMapping and source definitions in nuget.config are fully preserved. The credentials file is removed at end of the same RUN layer. Also fixes: - ! -f → ! -s (fail-fast if secret is empty, not just missing) - No more backup/restore dance or nuget.config mutation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8b22bdb commit 97a1933

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

EssentialCSharp.Web/Dockerfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ WORKDIR /src
1919
COPY . .
2020
COPY --from=frontend-build /frontend/EssentialCSharp.Web/wwwroot/dist ./EssentialCSharp.Web/wwwroot/dist
2121
RUN --mount=type=secret,id=nuget_pat,required=false \
22-
if [ "$ACCESS_TO_NUGET_FEED" = "true" ] && [ ! -f /run/secrets/nuget_pat ]; then \
23-
echo "ERROR: ACCESS_TO_NUGET_FEED=true but nuget_pat secret is missing" >&2; exit 1; \
22+
if [ "$ACCESS_TO_NUGET_FEED" = "true" ] && [ ! -s /run/secrets/nuget_pat ]; then \
23+
echo "ERROR: ACCESS_TO_NUGET_FEED=true but nuget_pat secret is missing or empty" >&2; exit 1; \
2424
fi && \
25-
cp nuget.config nuget.config.bak && \
2625
if [ "$ACCESS_TO_NUGET_FEED" = "true" ]; then \
27-
dotnet nuget update source EssentialCSharp \
28-
--username az \
29-
--password "$(cat /run/secrets/nuget_pat)" \
30-
--store-password-in-clear-text; \
26+
mkdir -p /root/.nuget/NuGet && \
27+
printf '<?xml version="1.0" encoding="utf-8"?>\n<configuration>\n <packageSourceCredentials>\n <EssentialCSharp>\n <add key="Username" value="az" />\n <add key="ClearTextPassword" value="%s" />\n </EssentialCSharp>\n </packageSourceCredentials>\n</configuration>\n' \
28+
"$(cat /run/secrets/nuget_pat)" > /root/.nuget/NuGet/NuGet.Config; \
3129
fi && \
3230
dotnet restore "EssentialCSharp.Web.slnx" -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED && \
3331
dotnet build "EssentialCSharp.Web.slnx" -c Release --no-restore -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED -p:ReleaseDateAttribute=True -p:SkipFrontendBuild=true && \
3432
dotnet publish "EssentialCSharp.Web.slnx" -c Release -p:PublishDir=/app/publish -p:UseAppHost=false -p:SkipFrontendBuild=true --no-build && \
35-
mv nuget.config.bak nuget.config
33+
rm -f /root/.nuget/NuGet/NuGet.Config
3634

3735
FROM base AS final
3836
WORKDIR /app

0 commit comments

Comments
 (0)