forked from microsoft/kernel-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
62 lines (47 loc) · 1.71 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
ARG BUILD_IMAGE_TAG="8.0-jammy"
ARG RUN_IMAGE_TAG="8.0-alpine"
#########################################################################
# build and publish
#########################################################################
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
ARG BUILD_CONFIGURATION=Release
ARG TARGETARCH
ARG TARGETPLATFORM
ARG BUILDPLATFORM
WORKDIR /src
COPY ["service/Service/Service.csproj", "service/Service/"]
RUN dotnet restore "./service/Service/./Service.csproj"
COPY ["extensions", "extensions"]
COPY ["tools", "tools"]
COPY ["service", "service"]
WORKDIR "/src/service/Service"
RUN dotnet build "./Service.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Service.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
#########################################################################
# run
#########################################################################
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
# Non-root user that will run the service
ARG USER=km
RUN mkdir -p /app && \
# Create user
# useradd --create-home --user-group $USER --shell /bin/bash && \
adduser -D -h /app -s /bin/sh $USER && \
# Allow user to access the build
chown -R $USER:$USER /app
# Define current user
USER $USER
# Used by .NET and KM to load appsettings.Production.json
ENV ASPNETCORE_ENVIRONMENT Production
ENV ASPNETCORE_URLS http://+:9001
WORKDIR /app
EXPOSE 9001
FROM base AS final
WORKDIR /app
RUN mkdir -p /app/publish
COPY --from=publish --chown=km:km /app/publish .
RUN chmod 0550 /app/publish
# Define executable
ENTRYPOINT ["dotnet", "Microsoft.KernelMemory.ServiceAssembly.dll"]