mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-12 11:12:44 +00:00
docker: optimize dockerfiles for multi platform builds
This commit is contained in:
@@ -1,26 +1,50 @@
|
||||
FROM 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
|
||||
ENV DOTNET_TC_QuickJitForLoops="1" DOTNET_ReadyToRun="0" DOTNET_TieredPGO="1" DOTNET_SYSTEM_GLOBALIZATION_INVARIANT="true"
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
# copy projects
|
||||
COPY Streetwriters.Data/*.csproj ./Streetwriters.Data/
|
||||
COPY Streetwriters.Common/*.csproj ./Streetwriters.Common/
|
||||
COPY Streetwriters.Identity/*.csproj ./Streetwriters.Identity/
|
||||
|
||||
# restore dependencies
|
||||
RUN dotnet restore -v d /app/Streetwriters.Identity/Streetwriters.Identity.csproj --use-current-runtime
|
||||
RUN dotnet restore -v d /src/Streetwriters.Identity/Streetwriters.Identity.csproj --use-current-runtime
|
||||
|
||||
# copy everything else
|
||||
COPY Streetwriters.Data/ ./Streetwriters.Data/
|
||||
COPY Streetwriters.Common/ ./Streetwriters.Common/
|
||||
COPY Streetwriters.Identity/ ./Streetwriters.Identity/
|
||||
|
||||
WORKDIR /app/Streetwriters.Identity/
|
||||
ENV DOTNET_TC_QuickJitForLoops="1" DOTNET_ReadyToRun="0" DOTNET_TieredPGO="1" DOTNET_SYSTEM_GLOBALIZATION_INVARIANT="true"
|
||||
RUN dotnet publish -c Release -o /app/out --use-current-runtime --self-contained false --no-restore
|
||||
WORKDIR /src/Streetwriters.Identity/
|
||||
|
||||
# final stage/image
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||
RUN dotnet build -c Release -o /app/build -a $TARGETARCH
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish -c Release -o /app/publish \
|
||||
#--runtime alpine-x64 \
|
||||
--self-contained true \
|
||||
/p:PublishTrimmed=true \
|
||||
/p:PublishSingleFile=true \
|
||||
-a $TARGETARCH
|
||||
|
||||
FROM --platform=$BUILDPLATFORM base AS final
|
||||
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
|
||||
COPY --from=build /app/out .
|
||||
ENTRYPOINT ["dotnet", "Streetwriters.Identity.dll"]
|
||||
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["./Streetwriters.Identity"]
|
||||
Reference in New Issue
Block a user