Skip to content

Commit 1d3c483

Browse files
authored
Merge pull request #458 from nanotaboada/chore/docker-aspnet-alpine
chore(docker): switch runtime to `aspnet:10.0-alpine` (#456)
2 parents 4f7593f + c2fcd77 commit 1d3c483

3 files changed

Lines changed: 34 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ 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` (before: 113.4 MB →
59+
after: 73.9 MB compressed; measured via `docker manifest inspect` and
60+
`docker save | wc -c`); replace `apt-get` with `apk` and
61+
`useradd`/`groupadd` with `adduser`/`addgroup` accordingly (#456)
62+
- Refactor `scripts/entrypoint.sh`: add `log()` helper with timestamp prefix,
63+
replace raw `echo` calls, and print API base URL on startup (#456)
5764
- Rename `ValidateAsync_SquadNumber_BelongsToPlayerBeingUpdated_ReturnsNoErrors` to `ValidateAsync_SquadNumberBelongsToPlayerBeingUpdated_ReturnsNoErrors` to align with the 3-segment naming convention for service/validator tests (#427)
5865
- Make CSharpier step in `/pre-commit` conditional (skip with a note if not installed), consistent with the Docker and CodeRabbit steps (#427)
5966
- 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: 7 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"
@@ -39,6 +38,9 @@ LABEL org.opencontainers.image.source="https://github.com/nanotaboada/Dotnet.Sam
3938
# Set environment variables
4039
ENV ASPNETCORE_URLS=http://+:9000
4140
ENV ASPNETCORE_ENVIRONMENT=Production
41+
# Alpine images default to invariant globalization mode. Explicitly opt in since
42+
# this API uses ISO-8601 dates and ASCII data — ICU is not required.
43+
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true
4244

4345
# Copy published app from builder
4446
COPY --from=builder /app/publish/ .
@@ -57,7 +59,8 @@ COPY --chmod=555 scripts/healthcheck.sh ./healthcheck.sh
5759
COPY --from=builder /src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.db ./hold/players-sqlite3.db
5860

5961
# Add non-root user and make volume mount point writable
60-
RUN groupadd -r aspnetcore && useradd -r -g aspnetcore aspnetcore && \
62+
RUN addgroup -S aspnetcore && \
63+
adduser -S -G aspnetcore aspnetcore && \
6164
mkdir -p /storage && \
6265
chown aspnetcore:aspnetcore /storage
6366

scripts/entrypoint.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
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+
# Derive the API URL from ASPNETCORE_URLS (first entry if semicolon-separated),
33+
# replacing the wildcard host (+, 0.0.0.0) with localhost for display purposes.
34+
_raw_url=$(printf '%s' "${ASPNETCORE_URLS:-http://+:9000}" | cut -d';' -f1)
35+
API_URL=$(printf '%s' "$_raw_url" | sed 's|+|localhost|g; s|0\.0\.0\.0|localhost|g')
36+
log "🔌 API endpoints | $API_URL"
2537
exec "$@"

0 commit comments

Comments
 (0)