Skip to content

Commit 8b22bdb

Browse files
fix: address review comments - inline secret, fail-fast on missing PAT
- Remove temp PAT file entirely; pass secret inline to docker/build-push-action using "nuget_pat=${{ secrets.AZURE_DEVOPS_PAT }}" format (eliminates temp file creation, permissions concern, and cleanup step) - Add fail-fast in Dockerfile: if ACCESS_TO_NUGET_FEED=true but secret missing, exit 1 with a clear error message instead of silently failing with a 401 later Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 691f4af commit 8b22bdb

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

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

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

66-
- name: Write NuGet PAT for Docker build
67-
if: github.event_name != 'pull_request' && github.event_name != 'merge_group'
68-
run: echo -n "${{ secrets.AZURE_DEVOPS_PAT }}" > ${{ runner.temp }}/nuget-pat.txt
69-
7066
# Build but no push with a PR
7167
- name: Docker build (no push)
7268
if: github.event_name == 'pull_request' || github.event_name == 'merge_group'
@@ -86,7 +82,7 @@ jobs:
8682
file: ./EssentialCSharp.Web/Dockerfile
8783
context: .
8884
secrets: |
89-
"id=nuget_pat,src=${{ runner.temp }}/nuget-pat.txt"
85+
"nuget_pat=${{ secrets.AZURE_DEVOPS_PAT }}"
9086
outputs: type=docker,dest=${{ github.workspace }}/essentialcsharpwebimage.tar
9187
cache-from: type=gha
9288
cache-to: type=gha,mode=max
@@ -96,10 +92,6 @@ jobs:
9692
name: essentialcsharpwebimage
9793
path: ${{ github.workspace }}/essentialcsharpwebimage.tar
9894

99-
- name: Clean up NuGet PAT file
100-
if: always()
101-
run: rm -f ${{ runner.temp }}/nuget-pat.txt
102-
10395
deploy-development:
10496
if: github.event_name != 'pull_request_target' && github.event_name != 'pull_request'
10597
runs-on: ubuntu-latest

EssentialCSharp.Web/Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#syntax=docker/dockerfile:1.2
1+
# syntax=docker/dockerfile:1.4
22

33
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble-chiseled AS base
44
WORKDIR /app
@@ -19,18 +19,20 @@ 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-
cp nuget.config nuget.config.bak && \
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; \
24+
fi && \
25+
cp nuget.config nuget.config.bak && \
26+
if [ "$ACCESS_TO_NUGET_FEED" = "true" ]; then \
2427
dotnet nuget update source EssentialCSharp \
25-
--username docker \
28+
--username az \
2629
--password "$(cat /run/secrets/nuget_pat)" \
27-
--store-password-in-clear-text \
28-
--configfile nuget.config; \
30+
--store-password-in-clear-text; \
2931
fi && \
3032
dotnet restore "EssentialCSharp.Web.slnx" -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED && \
3133
dotnet build "EssentialCSharp.Web.slnx" -c Release --no-restore -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED -p:ReleaseDateAttribute=True -p:SkipFrontendBuild=true && \
3234
dotnet publish "EssentialCSharp.Web.slnx" -c Release -p:PublishDir=/app/publish -p:UseAppHost=false -p:SkipFrontendBuild=true --no-build && \
33-
if [ -f nuget.config.bak ]; then mv nuget.config.bak nuget.config; fi
35+
mv nuget.config.bak nuget.config
3436

3537
FROM base AS final
3638
WORKDIR /app

0 commit comments

Comments
 (0)