johnbridges commited on
Commit
3197bd6
·
verified ·
1 Parent(s): ce73b81

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +80 -55
Dockerfile CHANGED
@@ -1,11 +1,12 @@
1
  # syntax=docker/dockerfile:1.4
2
- # Use the official Debian 12 (Bookworm) 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 \
@@ -21,92 +22,116 @@ RUN apt-get update && \
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/Qwen3.5-2B-GGUF/resolve/main/Qwen3.5-2B-q6_k_m.gguf
 
37
 
38
- # Clone and build OpenBLAS as the non-root user
39
  RUN git clone https://github.com/OpenMathLib/OpenBLAS.git /home/user/code/models/OpenBLAS && \
40
- cd /home/user/code/models/OpenBLAS && \
41
- make -j2 > build.log 2>&1 || (tail -20 build.log && false)
 
42
 
43
- # Switch to root for the OpenBLAS installation
44
  USER root
45
- RUN cd /home/user/code/models/OpenBLAS && \
46
- make install > install.log 2>&1 || (tail -20 install.log && false) && \
 
 
47
  cp /opt/OpenBLAS/lib/libopenblas* /usr/local/lib/
48
 
49
- # Switch back to the non-root user
50
  USER user
51
 
52
- # Clone llama.cpp as the non-root user
53
- RUN git clone https://github.com/ggerganov/llama.cpp /home/user/code/models/llama.cpp
54
-
55
 
 
 
 
 
 
56
 
57
- # Install .NET 10.0 as the non-root user
58
- RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh && \
59
- chmod +x dotnet-install.sh && \
60
- ./dotnet-install.sh --channel 10.0
61
-
62
- # Set persistent environment variables
63
  ENV DOTNET_ROOT=/home/user/.dotnet
64
  ENV PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools
65
 
66
- # Verify .NET installation and current user
67
  RUN whoami && dotnet --version
68
 
69
- # Clone repositories using the GITHUB_TOKEN secret
70
  RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
71
- git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorLib.git /home/user/code/NetworkMonitorLib && \
72
- git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorLLM.git /home/user/code/NetworkMonitorLLM && \
73
- git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorData.git /home/user/code/NetworkMonitorData
74
-
75
- # Apply llama.cpp patches from NetworkMonitorLLM
 
 
 
 
 
 
76
  RUN git -C /home/user/code/models/llama.cpp apply \
77
- /home/user/code/NetworkMonitorLLM/patches/qwen35_imrope_context_shift_fix.diff
78
- # /home/user/code/NetworkMonitorLLM/patches/qwen35_session_tokens_insert_fix.diff \
79
- # /home/user/code/NetworkMonitorLLM/patches/qwen35_mrope_kv_restore_fix.diff
80
-
81
- # Build llama.cpp with OpenBLAS support after patches
82
- RUN cd /home/user/code/models/llama.cpp && \
83
- export PKG_CONFIG_PATH=/opt/OpenBLAS/lib/pkgconfig:$PKG_CONFIG_PATH && \
84
- cmake -B build -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DBLAS_INCLUDE_DIRS=/home/user/code/models/OpenBLAS -DLLAMA_CURL=OFF && \
85
- cmake --build build --config Release -j2 && \
86
- cp /home/user/code/models/llama.cpp/build/bin/* /home/user/code/models/llama.cpp/
87
-
88
- # Copy files into the container as the non-root user
89
- COPY --chown=user:user appsettings.json /home/user/code/app/appsettings.json
90
- COPY --chown=user:user index.html /home/user/code/app/wwwroot/index.html
91
-
92
-
93
- # Set the working directory for the build-qwen-3 script
 
 
 
 
 
 
 
94
  WORKDIR /home/user/code/models
95
 
96
-
97
- # Expose port 7860 for Hugging Face Spaces
98
  EXPOSE 7860
99
- # Set the working directory
 
100
  WORKDIR /home/user/code/NetworkMonitorLLM
101
 
102
- # Build the .NET project as the non-root user
103
  RUN dotnet restore && \
104
  dotnet build -c Release
105
 
106
- RUN cp -r /home/user/code/NetworkMonitorLLM/bin/Release/net10.0/* /home/user/code/app/ && \
107
- rm -rf /home/user/code/NetworkMonitorLib /home/user/code/NetworkMonitorLLM /home/user/code/NetworkMonitorData
 
 
 
 
 
108
 
109
- # Set the working directory to the `app` directory
110
  WORKDIR /home/user/code/app
111
 
112
- CMD ["dotnet", "NetworkMonitorLLM.dll", "--urls", "http://0.0.0.0:7860"]
 
 
1
  # syntax=docker/dockerfile:1.4
2
+
3
+ # Use the official Debian 13 base image
4
  FROM debian:13
5
 
6
+ # Avoid interactive prompts during package installation
7
  ENV DEBIAN_FRONTEND=noninteractive
8
 
9
+ # Install system dependencies
10
  RUN apt-get update && \
11
  apt-get install -y \
12
  build-essential \
 
22
  libicu76 \
23
  expect
24
 
25
+ # Create non-root user
26
  RUN useradd -m user && \
27
  mkdir -p /home/user/code && \
28
  chown -R user:user /home/user
29
 
30
+ # Switch to non-root user
31
  USER user
32
  WORKDIR /home/user
33
 
34
+ # Create directories and download model
35
  RUN mkdir -p /home/user/code/models && \
36
  mkdir -p /home/user/code/app/wwwroot && \
37
+ wget -q \
38
+ https://huggingface.co/Mungert/Qwen3.5-2B-GGUF/resolve/main/Qwen3.5-2B-q6_k_m.gguf \
39
+ -O /home/user/code/models/Qwen3.5-2B-q6_k_m.gguf
40
 
41
+ # Clone and build OpenBLAS
42
  RUN git clone https://github.com/OpenMathLib/OpenBLAS.git /home/user/code/models/OpenBLAS && \
43
+ make -C /home/user/code/models/OpenBLAS -j2 \
44
+ > /home/user/code/models/OpenBLAS/build.log 2>&1 || \
45
+ (tail -20 /home/user/code/models/OpenBLAS/build.log && false)
46
 
47
+ # Switch to root for installation
48
  USER root
49
+
50
+ RUN make -C /home/user/code/models/OpenBLAS install \
51
+ > /home/user/code/models/OpenBLAS/install.log 2>&1 || \
52
+ (tail -20 /home/user/code/models/OpenBLAS/install.log && false) && \
53
  cp /opt/OpenBLAS/lib/libopenblas* /usr/local/lib/
54
 
55
+ # Switch back to non-root user
56
  USER user
57
 
58
+ # Clone llama.cpp and checkout specific commit
59
+ RUN git clone https://github.com/ggerganov/llama.cpp /home/user/code/models/llama.cpp && \
60
+ git -C /home/user/code/models/llama.cpp checkout 5d14e5d
61
 
62
+ # Install .NET 10
63
+ RUN wget https://dot.net/v1/dotnet-install.sh \
64
+ -O /home/user/dotnet-install.sh && \
65
+ chmod +x /home/user/dotnet-install.sh && \
66
+ /home/user/dotnet-install.sh --channel 10.0
67
 
68
+ # Persistent .NET environment
 
 
 
 
 
69
  ENV DOTNET_ROOT=/home/user/.dotnet
70
  ENV PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools
71
 
72
+ # Verify installation
73
  RUN whoami && dotnet --version
74
 
75
+ # Clone private repositories
76
  RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
77
+ git clone \
78
+ https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorLib.git \
79
+ /home/user/code/NetworkMonitorLib && \
80
+ git clone \
81
+ https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorLLM.git \
82
+ /home/user/code/NetworkMonitorLLM && \
83
+ git clone \
84
+ https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorData.git \
85
+ /home/user/code/NetworkMonitorData
86
+
87
+ # Apply llama.cpp patches
88
  RUN git -C /home/user/code/models/llama.cpp apply \
89
+ /home/user/code/NetworkMonitorLLM/patches/qwen35_imrope_context_shift_fix.diff
90
+
91
+ # Build llama.cpp with OpenBLAS
92
+ RUN export PKG_CONFIG_PATH=/opt/OpenBLAS/lib/pkgconfig:$PKG_CONFIG_PATH && \
93
+ cmake \
94
+ -S /home/user/code/models/llama.cpp \
95
+ -B /home/user/code/models/llama.cpp/build \
96
+ -DGGML_BLAS=ON \
97
+ -DGGML_BLAS_VENDOR=OpenBLAS \
98
+ -DBLAS_INCLUDE_DIRS=/home/user/code/models/OpenBLAS \
99
+ -DLLAMA_CURL=OFF && \
100
+ cmake --build /home/user/code/models/llama.cpp/build \
101
+ --config Release -j2 && \
102
+ cp /home/user/code/models/llama.cpp/build/bin/* \
103
+ /home/user/code/models/llama.cpp/
104
+
105
+ # Copy application files
106
+ COPY --chown=user:user appsettings.json \
107
+ /home/user/code/app/appsettings.json
108
+
109
+ COPY --chown=user:user index.html \
110
+ /home/user/code/app/wwwroot/index.html
111
+
112
+ # Working directory for model-related tasks
113
  WORKDIR /home/user/code/models
114
 
115
+ # Expose Hugging Face Spaces port
 
116
  EXPOSE 7860
117
+
118
+ # Switch to project directory
119
  WORKDIR /home/user/code/NetworkMonitorLLM
120
 
121
+ # Restore and build .NET project
122
  RUN dotnet restore && \
123
  dotnet build -c Release
124
 
125
+ # Copy published files into app directory and clean up sources
126
+ RUN cp -r /home/user/code/NetworkMonitorLLM/bin/Release/net10.0/* \
127
+ /home/user/code/app/ && \
128
+ rm -rf \
129
+ /home/user/code/NetworkMonitorLib \
130
+ /home/user/code/NetworkMonitorLLM \
131
+ /home/user/code/NetworkMonitorData
132
 
133
+ # Final runtime directory
134
  WORKDIR /home/user/code/app
135
 
136
+ # Start application
137
+ CMD ["dotnet", "NetworkMonitorLLM.dll", "--urls", "http://0.0.0.0:7860"]