-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using new way of building docker image
- Loading branch information
1 parent
1e0fa29
commit 42b5c08
Showing
1 changed file
with
31 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |