From 38e657d325a3560d40ec85128b99ce4d31bf5cef Mon Sep 17 00:00:00 2001 From: Nano Taboada <87288+nanotaboada@users.noreply.github.com> Date: Sat, 24 May 2025 06:32:19 -0300 Subject: [PATCH 1/5] chore(container): rename Docker Compose file to preferred canonical form --- docker-compose.yml => compose.yml | 1 + 1 file changed, 1 insertion(+) rename docker-compose.yml => compose.yml (86%) diff --git a/docker-compose.yml b/compose.yml similarity index 86% rename from docker-compose.yml rename to compose.yml index 6eabc7a..57e2a98 100644 --- a/docker-compose.yml +++ b/compose.yml @@ -15,3 +15,4 @@ services: volumes: storage: + name: dotnet-samples-aspnetcore-webapi_storage From fb04961d19e229be210db50c595f03a43b51276d Mon Sep 17 00:00:00 2001 From: Nano Taboada <87288+nanotaboada@users.noreply.github.com> Date: Sat, 24 May 2025 06:35:54 -0300 Subject: [PATCH 2/5] chore(container): simplify creation of dynamically allocated system user --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 37f94c9..c7429c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,10 +57,10 @@ COPY --chmod=555 scripts/healthcheck.sh ./healthcheck.sh # Copy pre-seeded SQLite database as init bundle COPY --from=builder /src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.db ./docker-compose/players-sqlite3.db -# Create non-root user and make volume mount point writable -RUN adduser --disabled-password --gecos '' aspnetcore && \ +# Add non-root user and make volume mount point writable +RUN adduser --system --disabled-password --group aspnetcore && \ mkdir -p /storage && \ - chown -R aspnetcore:aspnetcore /storage + chown aspnetcore:aspnetcore /storage USER aspnetcore From ee00508fb6c62255c0cabd1c15210c95e75f7cbc Mon Sep 17 00:00:00 2001 From: Nano Taboada <87288+nanotaboada@users.noreply.github.com> Date: Sat, 24 May 2025 07:29:51 -0300 Subject: [PATCH 3/5] chore(container): adjust health check script defaults --- scripts/healthcheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index 9f5a04b..e3a9877 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -1,5 +1,5 @@ #!/bin/sh set -e -# Simple health check using curl -curl --fail http://localhost:9000/health +# Minimal curl-based health check with timeout and error reporting +curl --fail --silent --show-error --connect-timeout 1 --max-time 2 http://localhost:9000/health From 31fd98c06626e2afc48fd453c15488370ba98716 Mon Sep 17 00:00:00 2001 From: Nano Taboada <87288+nanotaboada@users.noreply.github.com> Date: Sat, 24 May 2025 07:30:47 -0300 Subject: [PATCH 4/5] chore(container): adjust COPY commands to include trailing slashes --- Dockerfile | 16 ++++++++-------- scripts/entrypoint.sh | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index c7429c8..1ed2a3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,11 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS builder WORKDIR /src # Restore dependencies -COPY src/Dotnet.Samples.AspNetCore.WebApi/*.csproj ./Dotnet.Samples.AspNetCore.WebApi/ +COPY src/Dotnet.Samples.AspNetCore.WebApi/*.csproj ./Dotnet.Samples.AspNetCore.WebApi/ RUN dotnet restore ./Dotnet.Samples.AspNetCore.WebApi # Copy source code and pre-seeded SQLite database -COPY src/Dotnet.Samples.AspNetCore.WebApi ./Dotnet.Samples.AspNetCore.WebApi +COPY src/Dotnet.Samples.AspNetCore.WebApi/ ./Dotnet.Samples.AspNetCore.WebApi/ WORKDIR /src/Dotnet.Samples.AspNetCore.WebApi @@ -41,21 +41,21 @@ ENV ASPNETCORE_URLS=http://+:9000 ENV ASPNETCORE_ENVIRONMENT=Production # Copy published app from builder -COPY --from=builder /app/publish . +COPY --from=builder /app/publish/ . # Copy metadata docs for container registries (e.g.: GitHub Container Registry) COPY --chmod=444 README.md ./ -COPY --chmod=555 assets ./assets +COPY --chmod=555 assets/ ./assets/ # https://rules.sonarsource.com/docker/RSPEC-6504/ # Copy entrypoint and healthcheck scripts COPY --chmod=555 scripts/entrypoint.sh ./entrypoint.sh COPY --chmod=555 scripts/healthcheck.sh ./healthcheck.sh - - -# Copy pre-seeded SQLite database as init bundle -COPY --from=builder /src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.db ./docker-compose/players-sqlite3.db +# The 'hold' is our storage compartment within the image. Here, we copy a +# pre-seeded SQLite database file, which Compose will mount as a persistent +# 'storage' volume when the container starts up. +COPY --from=builder /src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.db ./hold/players-sqlite3.db # Add non-root user and make volume mount point writable RUN adduser --system --disabled-password --group aspnetcore && \ diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 4f0d58d..2642076 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e -IMAGE_STORAGE_PATH="/app/docker-compose/players-sqlite3.db" +IMAGE_STORAGE_PATH="/app/hold/players-sqlite3.db" VOLUME_STORAGE_PATH="/storage/players-sqlite3.db" echo "✔ Starting container..." From 5f54549ec0b58a359b471791f8e25e8266103dcf Mon Sep 17 00:00:00 2001 From: Nano Taboada <87288+nanotaboada@users.noreply.github.com> Date: Sat, 24 May 2025 07:51:49 -0300 Subject: [PATCH 5/5] chore: reduce publish output by setting SatelliteResourceLanguages to en-US --- .../Dotnet.Samples.AspNetCore.WebApi.csproj | 4 ++++ .../Dotnet.Samples.AspNetCore.WebApi.Tests.csproj | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj b/src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj index 77cd3ef..e9a3dd9 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj @@ -39,4 +39,8 @@ $(NoWarn);1591 + + en-US + + diff --git a/test/Dotnet.Samples.AspNetCore.WebApi.Tests/Dotnet.Samples.AspNetCore.WebApi.Tests.csproj b/test/Dotnet.Samples.AspNetCore.WebApi.Tests/Dotnet.Samples.AspNetCore.WebApi.Tests.csproj index e36759d..222c967 100644 --- a/test/Dotnet.Samples.AspNetCore.WebApi.Tests/Dotnet.Samples.AspNetCore.WebApi.Tests.csproj +++ b/test/Dotnet.Samples.AspNetCore.WebApi.Tests/Dotnet.Samples.AspNetCore.WebApi.Tests.csproj @@ -27,4 +27,8 @@ + + en-US + +