diff --git a/Dockerfile b/Dockerfile index 37f94c9..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,26 +41,26 @@ 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 +# 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 - -# 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 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 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..." 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 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 + +