From 52708bd2c2fd24516162ba619f56ed5b3502e748 Mon Sep 17 00:00:00 2001 From: Jeff Leung Date: Sat, 13 Jan 2024 12:15:55 -0800 Subject: [PATCH] Add self contained runtime deployment --- .../Dockerfile.alpine-selfcontained | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 AS1024.GeoFeed/Dockerfile.alpine-selfcontained diff --git a/AS1024.GeoFeed/Dockerfile.alpine-selfcontained b/AS1024.GeoFeed/Dockerfile.alpine-selfcontained new file mode 100644 index 0000000..6dc834d --- /dev/null +++ b/AS1024.GeoFeed/Dockerfile.alpine-selfcontained @@ -0,0 +1,54 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM alpine:latest AS base +ENV \ + # UID of the non-root user 'app' + APP_UID=1654 \ + # Configure web servers to bind to port 8080 when present + ASPNETCORE_HTTP_PORTS=8080 \ + # Enable detection of running in a container + DOTNET_RUNNING_IN_CONTAINER=true \ + # Set the invariant mode since ICU package isn't included (see https://github.com/dotnet/announcements/issues/20) + DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true + +RUN apk add --upgrade --no-cache \ + ca-certificates-bundle \ + \ + # .NET dependencies + libgcc \ + libssl3 \ + libstdc++ \ + zlib + +# Create a non-root user and group +RUN addgroup \ + --gid=$APP_UID \ + app \ + && adduser \ + --uid=$APP_UID \ + --ingroup=app \ + --disabled-password \ + app +WORKDIR /app +USER app +EXPOSE 8080 + +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build +ARG BUILD_CONFIGURATION=Release +ARG TARGETARCH +WORKDIR /src +COPY ["AS1024.GeoFeed/AS1024.GeoFeed.csproj", "AS1024.GeoFeed/"] +RUN dotnet restore "./AS1024.GeoFeed/./AS1024.GeoFeed.csproj" -a $TARGETARCH +COPY . . +WORKDIR "/src/AS1024.GeoFeed" +RUN dotnet build "./AS1024.GeoFeed.csproj" -c $BUILD_CONFIGURATION -o /app/build -a $TARGETARCH /p:StaticLink=true + +FROM --platform=$BUILDPLATFORM build AS publish +ARG BUILD_CONFIGURATION=Release +ARG TARGETARCH +RUN dotnet publish "./AS1024.GeoFeed.csproj" -c $BUILD_CONFIGURATION -o /app/publish -a $TARGETARCH --self-contained + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["/app/AS1024.GeoFeed"] \ No newline at end of file