############################################### # Build stage # ############################################### FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build # Docker buildx supplies the value for this arg ARG TARGETPLATFORM # Determine proper runtime value for .NET RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ RID=linux-x64 ; \ elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ RID=linux-arm64 ; \ elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ RID=linux-arm ; \ fi \ && echo "RID=$RID" > /tmp/rid.txt # Set up Node ARG NODE_VERSION=20 RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \ && apt-get update \ && apt-get install -y nodejs \ && npm install -g npm@latest && \ rm -rf /var/lib/apt/lists/* # Copy required project files WORKDIR /source COPY . ./ # Restore project dependencies and tools WORKDIR /source/src/Admin RUN npm ci RUN . /tmp/rid.txt && dotnet restore -r $RID # Build project RUN npm run build RUN . /tmp/rid.txt && dotnet publish \ -c release \ --no-restore \ --self-contained \ /p:PublishSingleFile=true \ -r $RID \ -o out ############################################### # App stage # ############################################### FROM mcr.microsoft.com/dotnet/aspnet:8.0 ARG TARGETPLATFORM LABEL com.bitwarden.product="bitwarden" ENV ASPNETCORE_ENVIRONMENT=Production ENV ASPNETCORE_URLS=http://+:5000 ENV SSL_CERT_DIR=/etc/bitwarden/ca-certificates EXPOSE 5000 RUN apt-get update \ && apt-get install -y --no-install-recommends \ gosu \ curl \ && rm -rf /var/lib/apt/lists/* # Copy app from the build stage WORKDIR /app COPY --from=build /source/src/Admin/out /app COPY ./src/Admin/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh HEALTHCHECK CMD curl -f http://localhost:5000/alive || exit 1 ENTRYPOINT ["/entrypoint.sh"]