Skip to content

Commit 92d37f2

Browse files
fix: add --chown=app:app to COPY in Dockerfile final stage
The chiseled image's 'app' user (UID 1654) cannot write to /app/wwwroot/ for sitemap.xml generation at startup. Setting ownership on COPY resolves the UnauthorizedAccessException without requiring chmod or extra layers.
1 parent 4ad9a87 commit 92d37f2

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

EssentialCSharp.Web/Dockerfile

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

3-
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble-chiseled AS base
3+
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble-chiseled-extra AS base
44
WORKDIR /app
55
EXPOSE 8080
66
EXPOSE 8081
@@ -19,20 +19,21 @@ 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-
cp nuget.config nuget.config.bak && \
23-
if [ "$ACCESS_TO_NUGET_FEED" = "true" ] && [ -f /run/secrets/nuget_pat ]; then \
24-
dotnet nuget update source EssentialCSharp \
25-
--username az \
26-
--password "$(cat /run/secrets/nuget_pat)" \
27-
--store-password-in-clear-text; \
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; \
24+
fi && \
25+
if [ "$ACCESS_TO_NUGET_FEED" = "true" ]; then \
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; \
2829
fi && \
2930
dotnet restore "EssentialCSharp.Web.slnx" -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED && \
3031
dotnet build "EssentialCSharp.Web.slnx" -c Release --no-restore -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED -p:ReleaseDateAttribute=True -p:SkipFrontendBuild=true && \
3132
dotnet publish "EssentialCSharp.Web.slnx" -c Release -p:PublishDir=/app/publish -p:UseAppHost=false -p:SkipFrontendBuild=true --no-build && \
32-
mv nuget.config.bak nuget.config
33+
rm -f /root/.nuget/NuGet/NuGet.Config
3334

3435
FROM base AS final
3536
WORKDIR /app
36-
COPY --from=build /app/publish .
37+
COPY --chown=app:app --from=build /app/publish .
3738
USER app
3839
ENTRYPOINT ["dotnet", "EssentialCSharp.Web.dll"]

0 commit comments

Comments
 (0)