Mungert commited on
Commit
dc89243
·
verified ·
1 Parent(s): e2ef977

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +129 -71
Dockerfile CHANGED
@@ -1,105 +1,163 @@
1
  # syntax=docker/dockerfile:1.4
2
- # Use the official Debian base image
3
- FROM debian:13
4
 
5
- # Set environment variables to avoid interactive prompts during package installation
 
 
 
 
6
  ENV DEBIAN_FRONTEND=noninteractive
7
 
8
- # Install system-level dependencies as root
9
  RUN apt-get update && \
10
- apt-get install -y \
11
  build-essential \
12
- curl \
13
- ca-certificates \
14
- git \
15
  cmake \
16
- clang \
17
  pkg-config \
18
- ccache \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  wget \
20
- vim \
21
  libicu76 \
22
- expect
 
23
 
24
- # Create a non-root user and set up their environment
25
- RUN useradd -m user && \
26
- mkdir -p /home/user/code && \
27
- chown -R user:user /home/user
28
 
29
- # Switch to the non-root user
30
  USER user
31
  WORKDIR /home/user
32
 
33
- RUN mkdir -p /home/user/code/models && \
34
- mkdir -p /home/user/code/app/wwwroot && \
35
- cd /home/user/code/models && \
36
- wget -q https://huggingface.co/Mungert/Mellum2-12B-A2.5B-Instruct-GGUF/resolve/main/Mellum2-12B-A2.5B-Instruct-mxfp4_moe.gguf
37
- # Clone and build OpenBLAS as the non-root user
38
- RUN git clone https://github.com/OpenMathLib/OpenBLAS.git /home/user/code/models/OpenBLAS && \
39
- cd /home/user/code/models/OpenBLAS && \
40
- make -j2 > build.log 2>&1 || (tail -20 build.log && false)
41
-
42
- # Switch to root for the OpenBLAS installation
43
- USER root
44
- RUN cd /home/user/code/models/OpenBLAS && \
45
- make install > install.log 2>&1 || (tail -20 install.log && false) && \
46
- cp /opt/OpenBLAS/lib/libopenblas* /usr/local/lib/
47
-
48
- # Switch back to the non-root user
49
- USER user
50
 
51
- # Clone llama.cpp as the non-root user
52
- RUN git clone https://github.com/ggerganov/llama.cpp /home/user/code/models/llama.cpp
53
 
 
54
 
 
 
 
 
 
 
 
55
 
56
- # Install .NET 10.0 as the non-root user
57
- RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh && \
58
- chmod +x dotnet-install.sh && \
59
- ./dotnet-install.sh --channel 10.0
60
 
61
- # Set persistent environment variables
62
- ENV DOTNET_ROOT=/home/user/.dotnet
63
- ENV PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools
 
 
64
 
65
- # Verify .NET installation and current user
66
- RUN whoami && dotnet --version
67
 
68
- # Clone repositories using the GITHUB_TOKEN secret
69
- RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
70
- git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorLib.git /home/user/code/NetworkMonitorLib && \
71
- git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorLLM.git /home/user/code/NetworkMonitorLLM
72
 
 
73
 
74
- # Build llama.cpp with OpenBLAS support after patches
75
- RUN cd /home/user/code/models/llama.cpp && \
76
- export PKG_CONFIG_PATH=/opt/OpenBLAS/lib/pkgconfig:$PKG_CONFIG_PATH && \
77
- cmake -B build -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DBLAS_INCLUDE_DIRS=/home/user/code/models/OpenBLAS -DLLAMA_CURL=OFF && \
78
- cmake --build build --config Release -j2 && \
79
- cp /home/user/code/models/llama.cpp/build/bin/* /home/user/code/models/llama.cpp/
 
 
 
 
 
 
 
 
80
 
81
- # Copy files into the container as the non-root user
82
- COPY --chown=user:user appsettings.json /home/user/code/app/appsettings.json
83
- COPY --chown=user:user index.html /home/user/code/app/wwwroot/index.html
 
 
 
84
 
 
 
85
 
86
- # Set the working directory for the build-qwen-3 script
87
- WORKDIR /home/user/code/models
 
 
 
 
 
88
 
 
 
89
 
90
- # Expose port 7860 for Hugging Face Spaces
91
- EXPOSE 7860
92
- # Set the working directory
93
- WORKDIR /home/user/code/NetworkMonitorLLM
94
 
95
- # Build the .NET project as the non-root user
96
- RUN dotnet restore && \
97
- dotnet build -c Release
 
 
 
 
 
 
 
 
 
98
 
99
- RUN cp -r /home/user/code/NetworkMonitorLLM/bin/Release/net10.0/* /home/user/code/app/ && \
100
- rm -rf /home/user/code/NetworkMonitorLib /home/user/code/NetworkMonitorLLM
101
 
102
- # Set the working directory to the `app` directory
 
 
 
 
 
 
 
 
 
 
 
 
103
  WORKDIR /home/user/code/app
104
 
105
- CMD ["dotnet", "NetworkMonitorLLM.dll", "--urls", "http://0.0.0.0:7860"]
 
 
 
1
  # syntax=docker/dockerfile:1.4
 
 
2
 
3
+ # ============================================================
4
+ # Stage 1: Build llama.cpp
5
+ # ============================================================
6
+ FROM debian:13 AS llama-build
7
+
8
  ENV DEBIAN_FRONTEND=noninteractive
9
 
 
10
  RUN apt-get update && \
11
+ apt-get install -y --no-install-recommends \
12
  build-essential \
 
 
 
13
  cmake \
14
+ git \
15
  pkg-config \
16
+ libopenblas-dev && \
17
+ rm -rf /var/lib/apt/lists/*
18
+
19
+ WORKDIR /build
20
+
21
+ RUN git clone --depth 1 https://github.com/ggml-org/llama.cpp.git
22
+
23
+ WORKDIR /build/llama.cpp
24
+
25
+ RUN cmake -B build \
26
+ -DCMAKE_BUILD_TYPE=Release \
27
+ -DGGML_BLAS=ON \
28
+ -DGGML_BLAS_VENDOR=OpenBLAS \
29
+ -DLLAMA_CURL=OFF && \
30
+ cmake --build build --config Release -j2
31
+
32
+ RUN mkdir -p /out/llama && \
33
+ cp -a build/bin/. /out/llama/
34
+
35
+
36
+ # ============================================================
37
+ # Stage 2: Build .NET application
38
+ # ============================================================
39
+ FROM debian:13 AS dotnet-build
40
+
41
+ ENV DEBIAN_FRONTEND=noninteractive
42
+
43
+ RUN apt-get update && \
44
+ apt-get install -y --no-install-recommends \
45
+ ca-certificates \
46
  wget \
47
+ git \
48
  libicu76 \
49
+ libssl3t64 && \
50
+ rm -rf /var/lib/apt/lists/*
51
 
52
+ RUN useradd -m user
 
 
 
53
 
 
54
  USER user
55
  WORKDIR /home/user
56
 
57
+ RUN wget -q https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh && \
58
+ chmod +x dotnet-install.sh && \
59
+ ./dotnet-install.sh --channel 10.0 && \
60
+ rm dotnet-install.sh
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
+ ENV DOTNET_ROOT=/home/user/.dotnet
63
+ ENV PATH="${PATH}:${DOTNET_ROOT}:${DOTNET_ROOT}/tools"
64
 
65
+ WORKDIR /home/user/code
66
 
67
+ RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
68
+ git clone --depth 1 \
69
+ https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorLib.git \
70
+ /home/user/code/NetworkMonitorLib && \
71
+ git clone --depth 1 \
72
+ https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorLLM.git \
73
+ /home/user/code/NetworkMonitorLLM
74
 
75
+ WORKDIR /home/user/code/NetworkMonitorLLM
 
 
 
76
 
77
+ RUN dotnet restore && \
78
+ dotnet publish \
79
+ -c Release \
80
+ --no-self-contained \
81
+ -o /out/app
82
 
 
 
83
 
84
+ # ============================================================
85
+ # Stage 3: Runtime image
86
+ # ============================================================
87
+ FROM debian:13 AS runtime
88
 
89
+ ENV DEBIAN_FRONTEND=noninteractive
90
 
91
+ RUN apt-get update && \
92
+ apt-get install -y --no-install-recommends \
93
+ ca-certificates \
94
+ wget \
95
+ curl \
96
+ libicu76 \
97
+ libssl3t64 \
98
+ libgssapi-krb5-2 \
99
+ libstdc++6 \
100
+ libgcc-s1 \
101
+ libopenblas0-pthread \
102
+ expect \
103
+ tzdata && \
104
+ rm -rf /var/lib/apt/lists/*
105
 
106
+ RUN useradd -m user && \
107
+ mkdir -p \
108
+ /home/user/code/app/wwwroot \
109
+ /home/user/code/models/llama.cpp \
110
+ /home/user/code/models && \
111
+ chown -R user:user /home/user
112
 
113
+ USER user
114
+ WORKDIR /home/user
115
 
116
+ # Install only the ASP.NET Core runtime - NOT the full SDK
117
+ RUN wget -q https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh && \
118
+ chmod +x dotnet-install.sh && \
119
+ ./dotnet-install.sh \
120
+ --channel 10.0 \
121
+ --runtime aspnetcore && \
122
+ rm dotnet-install.sh
123
 
124
+ ENV DOTNET_ROOT=/home/user/.dotnet
125
+ ENV PATH="${PATH}:${DOTNET_ROOT}:${DOTNET_ROOT}/tools"
126
 
127
+ # Copy only the compiled llama.cpp binaries
128
+ COPY --from=llama-build --chown=user:user \
129
+ /out/llama/ \
130
+ /home/user/code/models/llama.cpp/
131
 
132
+ # Copy only the published .NET application
133
+ COPY --from=dotnet-build --chown=user:user \
134
+ /out/app/ \
135
+ /home/user/code/app/
136
+
137
+ COPY --chown=user:user \
138
+ appsettings.json \
139
+ /home/user/code/app/appsettings.json
140
+
141
+ COPY --chown=user:user \
142
+ index.html \
143
+ /home/user/code/app/wwwroot/index.html
144
 
 
 
145
 
146
+ # ============================================================
147
+ # Model
148
+ # ============================================================
149
+ WORKDIR /home/user/code/models
150
+
151
+ RUN wget -q \
152
+ https://huggingface.co/Mungert/Mellum2-12B-A2.5B-Instruct-GGUF/resolve/main/Mellum2-12B-A2.5B-Instruct-mxfp4_moe.gguf \
153
+ -O Mellum2-12B-A2.5B-Instruct-mxfp4_moe.gguf
154
+
155
+
156
+ # ============================================================
157
+ # Application
158
+ # ============================================================
159
  WORKDIR /home/user/code/app
160
 
161
+ EXPOSE 7860
162
+
163
+ CMD ["dotnet", "NetworkMonitorLLM.dll", "--urls", "http://0.0.0.0:7860"]