Skip to content

Commit f598d60

Browse files
fix: use dotnet nuget update source for Docker NuGet auth
The previous approach copied credentials to ~/.nuget/config/credentials.config, which is NOT a path the .NET SDK reads on Linux. The NuGet client only reads user-level config from ~/.nuget/NuGet/NuGet.Config. Replace the broken config-layering approach with 'dotnet nuget update source', which injects credentials into the repo's nuget.config in the build stage. This preserves packageSourceMapping and uses no external tooling. Also fixes: - Semicolon (;) after dotnet restore replaced with && to fail fast - CI now passes raw PAT as BuildKit secret instead of generating XML - Uses runner.temp instead of /tmp for the PAT file
1 parent 1f6c3e0 commit f598d60

2 files changed

Lines changed: 12 additions & 25 deletions

File tree

.github/workflows/Build-Test-And-Deploy.yml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,9 @@ jobs:
6363
- name: Set up Docker Buildx
6464
uses: docker/setup-buildx-action@v4
6565

66-
- name: Generate NuGet auth config for Docker build
66+
- name: Write NuGet PAT for Docker build
6767
if: github.event_name != 'pull_request' && github.event_name != 'merge_group'
68-
env:
69-
NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_PAT }}
70-
run: |
71-
# Credentials-only config — sources and packageSourceMapping remain in nuget.config.
72-
# NuGet merges packageSourceCredentials from ~/.nuget/config/*.config independently
73-
# of packageSources, so <clear /> in nuget.config does not affect credentials.
74-
cat > /tmp/nuget-auth.config << EOF
75-
<?xml version="1.0" encoding="utf-8"?>
76-
<configuration>
77-
<packageSourceCredentials>
78-
<EssentialCSharp>
79-
<add key="Username" value="docker" />
80-
<add key="ClearTextPassword" value="${NUGET_AUTH_TOKEN}" />
81-
</EssentialCSharp>
82-
</packageSourceCredentials>
83-
</configuration>
84-
EOF
68+
run: echo "${{ secrets.AZURE_DEVOPS_PAT }}" > "${{ runner.temp }}/nuget-pat.txt"
8569

8670
# Build but no push with a PR
8771
- name: Docker build (no push)
@@ -102,7 +86,7 @@ jobs:
10286
file: ./EssentialCSharp.Web/Dockerfile
10387
context: .
10488
secrets: |
105-
"id=nugetconfig,src=/tmp/nuget-auth.config"
89+
"id=nuget_pat,src=${{ runner.temp }}/nuget-pat.txt"
10690
outputs: type=docker,dest=${{ github.workspace }}/essentialcsharpwebimage.tar
10791
cache-from: type=gha
10892
cache-to: type=gha,mode=max
@@ -112,9 +96,9 @@ jobs:
11296
name: essentialcsharpwebimage
11397
path: ${{ github.workspace }}/essentialcsharpwebimage.tar
11498

115-
- name: Clean up NuGet auth config
99+
- name: Clean up NuGet PAT
116100
if: always()
117-
run: rm -f /tmp/nuget-auth.config
101+
run: rm -f "${{ runner.temp }}/nuget-pat.txt"
118102

119103
deploy-development:
120104
if: github.event_name != 'pull_request_target' && github.event_name != 'pull_request'

EssentialCSharp.Web/Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ ENV ACCESS_TO_NUGET_FEED=$ACCESS_TO_NUGET_FEED
1818
WORKDIR /src
1919
COPY . .
2020
COPY --from=frontend-build /frontend/EssentialCSharp.Web/wwwroot/dist ./EssentialCSharp.Web/wwwroot/dist
21-
RUN --mount=type=secret,id=nugetconfig,required=false \
22-
if [ -f /run/secrets/nugetconfig ]; then \
23-
mkdir -p ~/.nuget/config && cp /run/secrets/nugetconfig ~/.nuget/config/credentials.config; \
21+
RUN --mount=type=secret,id=nuget_pat,required=false \
22+
if [ "$ACCESS_TO_NUGET_FEED" = "true" ] && [ -f /run/secrets/nuget_pat ]; then \
23+
dotnet nuget update source EssentialCSharp \
24+
--username az \
25+
--password "$(cat /run/secrets/nuget_pat)" \
26+
--store-password-in-clear-text; \
2427
fi && \
25-
dotnet restore "EssentialCSharp.Web.slnx" -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED; \
28+
dotnet restore "EssentialCSharp.Web.slnx" -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED && \
2629
dotnet build "EssentialCSharp.Web.slnx" -c Release --no-restore -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED -p:ReleaseDateAttribute=True -p:SkipFrontendBuild=true && \
2730
dotnet publish "EssentialCSharp.Web.slnx" -c Release -p:PublishDir=/app/publish -p:UseAppHost=false -p:SkipFrontendBuild=true --no-build
2831

0 commit comments

Comments
 (0)