Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml → compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ services:

volumes:
storage:
name: dotnet-samples-aspnetcore-webapi_storage
2 changes: 1 addition & 1 deletion scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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..."
Expand Down
4 changes: 2 additions & 2 deletions scripts/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<PropertyGroup>
<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
<ProjectReference Include="..\..\src\Dotnet.Samples.AspNetCore.WebApi\Dotnet.Samples.AspNetCore.WebApi.csproj" />
</ItemGroup>

<PropertyGroup>
<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
</PropertyGroup>

</Project>