Skip to content

Commit

Permalink
Using new way of building docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
merschformann committed Nov 3, 2024
1 parent 1e0fa29 commit 42b5c08
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions SC.Service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
ARG TARGETARCH
ARG BUILDPLATFORM

WORKDIR /src
COPY . .
RUN dotnet restore "SC.Service/SC.Service.csproj"
WORKDIR "/src/SC.Service"
RUN dotnet build "SC.Service.csproj" -c Release -o /app/build
RUN dotnet publish "SC.Service.csproj" -c Release -o /app/publish
RUN dotnet build "SC.Service.csproj" -c Release -o /app/build -a $TARGETARCH

FROM build AS publish
RUN dotnet publish "SC.Service.csproj" -c Release -o /app/publish \
--self-contained true \
/p:PublishTrimmed=true \
/p:PublishSingleFile=true \
-a $TARGETARCH

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
FROM --platform=$BUILDPLATFORM base AS final
LABEL org.opencontainers.image.source="https://github.com/merschformann/sardine-can"
ARG TARGETARCH
ARG BUILDPLATFORM

# create a new user and change directory ownership
RUN adduser --disabled-password \
--home /app \
--gecos '' dotnetuser && chown -R dotnetuser /app

# impersonate into the new user
USER dotnetuser
WORKDIR /app
EXPOSE 80
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "SC.Service.dll"]

COPY --from=publish /app/publish .
ENTRYPOINT ["./SC.Service"]

0 comments on commit 42b5c08

Please sign in to comment.