Skip to content

Commit 5eadb5d

Browse files
nanotaboadaclaude
andcommitted
chore(docker): switch runtime to aspnet:10.0-alpine (#456)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4f7593f commit 5eadb5d

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ This project uses famous football stadiums (A-Z) that hosted FIFA World Cup matc
5454

5555
### Changed
5656

57+
- Switch runtime base image from `mcr.microsoft.com/dotnet/aspnet:10.0` (Debian)
58+
to `mcr.microsoft.com/dotnet/aspnet:10.0-alpine` to reduce image size
59+
(~100–150 MB); replace `apt-get` with `apk` and `useradd`/`groupadd` with
60+
`adduser`/`addgroup` accordingly (#456)
61+
- Refactor `scripts/entrypoint.sh`: add `log()` helper with timestamp prefix,
62+
replace raw `echo` calls, and print API base URL on startup (#456)
5763
- Rename `ValidateAsync_SquadNumber_BelongsToPlayerBeingUpdated_ReturnsNoErrors` to `ValidateAsync_SquadNumberBelongsToPlayerBeingUpdated_ReturnsNoErrors` to align with the 3-segment naming convention for service/validator tests (#427)
5864
- Make CSharpier step in `/pre-commit` conditional (skip with a note if not installed), consistent with the Docker and CodeRabbit steps (#427)
5965
- Add "Verify tag commit is reachable from master" step to CD workflow using `git merge-base --is-ancestor` before any build or publish steps (#439)

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ RUN dotnet publish -c Release -o /app/publish
2222
# Stage 2: Runtime
2323
# This stage creates the final, minimal image to run the application.
2424
# ------------------------------------------------------------------------------
25-
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
25+
FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS runtime
2626

2727
WORKDIR /app
2828

2929
# Install curl for health check
30-
RUN apt-get update && apt-get install -y --no-install-recommends curl && \
31-
rm -rf /var/lib/apt/lists/*
30+
RUN apk add --no-cache curl
3231

3332
# Metadata labels for the image. These are useful for registries and inspection.
3433
LABEL org.opencontainers.image.title="🧪 Web API made with .NET 10 (LTS) and ASP.NET Core"
@@ -57,7 +56,8 @@ COPY --chmod=555 scripts/healthcheck.sh ./healthcheck.sh
5756
COPY --from=builder /src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.db ./hold/players-sqlite3.db
5857

5958
# Add non-root user and make volume mount point writable
60-
RUN groupadd -r aspnetcore && useradd -r -g aspnetcore aspnetcore && \
59+
RUN addgroup -S aspnetcore && \
60+
adduser -S -G aspnetcore aspnetcore && \
6161
mkdir -p /storage && \
6262
chown aspnetcore:aspnetcore /storage
6363

scripts/entrypoint.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
#!/bin/sh
22
set -e
33

4+
# Helper function for formatted logging
5+
log() {
6+
local message="$1"
7+
echo "[ENTRYPOINT] $(date '+%Y/%m/%d - %H:%M:%S') | $message"
8+
return 0
9+
}
10+
411
IMAGE_STORAGE_PATH="/app/hold/players-sqlite3.db"
512
VOLUME_STORAGE_PATH="/storage/players-sqlite3.db"
613

7-
echo "✔ Starting container..."
14+
log "✔ Starting container..."
815

916
if [ ! -f "$VOLUME_STORAGE_PATH" ]; then
10-
echo "⚠️ No existing database file found in volume."
17+
log "⚠️ No existing database file found in volume."
1118
if [ -f "$IMAGE_STORAGE_PATH" ]; then
12-
echo "🔄 Copying database file to writable volume..."
19+
log "🔄 Copying database file to writable volume..."
1320
cp "$IMAGE_STORAGE_PATH" "$VOLUME_STORAGE_PATH"
14-
echo "✔ Database initialized at $VOLUME_STORAGE_PATH"
21+
log "✔ Database initialized at $VOLUME_STORAGE_PATH"
1522
else
16-
echo "⚠️ Database file missing at $IMAGE_STORAGE_PATH"
23+
log "⚠️ Database file missing at $IMAGE_STORAGE_PATH"
1724
exit 1
1825
fi
1926
else
20-
echo "✔ Existing database file found. Skipping seed copy."
27+
log "✔ Existing database file found. Skipping seed copy."
2128
fi
2229

23-
echo "✔ Ready!"
24-
echo "🚀 Launching app..."
30+
log "✔ Ready!"
31+
log "🚀 Launching app..."
32+
log "🔌 API endpoints | http://localhost:9000"
2533
exec "$@"

0 commit comments

Comments
 (0)