File size: 4,133 Bytes
d5210e6
3197bd6
d5210e6
 
 
 
1508bf0
d5210e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3197bd6
d5210e6
 
 
 
 
 
 
3197bd6
d5210e6
 
3197bd6
c61c0e6
 
d5210e6
1508bf0
 
 
 
3197bd6
 
 
d5210e6
1508bf0
d5210e6
3197bd6
 
 
 
d5210e6
 
 
b02fa9c
 
a5a5df4
 
119e4f4
3197bd6
 
 
 
 
119e4f4
3197bd6
119e4f4
 
 
1508bf0
119e4f4
 
3197bd6
778e920
3197bd6
 
 
 
 
 
 
 
 
 
 
756a764
 
3197bd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1508bf0
d5210e6
 
1508bf0
d5210e6
3197bd6
1508bf0
d5210e6
 
 
 
 
1508bf0
3197bd6
 
 
 
 
 
d5210e6
3197bd6
d5210e6
 
3197bd6
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# syntax=docker/dockerfile:1.4

FROM debian:13

ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies
RUN apt-get update && \
    apt-get install -y \
        build-essential \
        curl \
        ca-certificates \
        git \
        cmake \
        clang \
        pkg-config \
        ccache \
        wget \
        vim \
        libicu76 \
        expect

# Create non-root user
RUN useradd -m user && \
    mkdir -p /home/user/code && \
    chown -R user:user /home/user

USER user
WORKDIR /home/user

# Create directories and download model
RUN mkdir -p /home/user/code/models && \
    mkdir -p /home/user/code/app/wwwroot && \
    wget -q \
      https://huggingface.co/Mungert/gemma-4-E4B-it-GGUF/resolve/main/gemma-4-E4B-it-q4_k_m.gguf \
      -O /home/user/code/models/gemma-4-E4B-it-q4_k_m.gguf

# Shallow clone and build OpenBLAS
RUN git clone --depth 1 \
      https://github.com/OpenMathLib/OpenBLAS.git \
      /home/user/code/models/OpenBLAS && \
    make -C /home/user/code/models/OpenBLAS -j2 \
      > /home/user/code/models/OpenBLAS/build.log 2>&1 || \
    (tail -20 /home/user/code/models/OpenBLAS/build.log && false)

# Install OpenBLAS as root
USER root

RUN make -C /home/user/code/models/OpenBLAS install \
      > /home/user/code/models/OpenBLAS/install.log 2>&1 || \
    (tail -20 /home/user/code/models/OpenBLAS/install.log && false) && \
    cp /opt/OpenBLAS/lib/libopenblas* /usr/local/lib/

USER user
# use --branch b8797 for qwen 3.5 compat may be fixed in future
RUN git clone --depth 1 \
    https://github.com/ggerganov/llama.cpp.git \
    /home/user/code/models/llama.cpp

# Install .NET 10
RUN wget https://dot.net/v1/dotnet-install.sh \
      -O /home/user/dotnet-install.sh && \
    chmod +x /home/user/dotnet-install.sh && \
    /home/user/dotnet-install.sh --channel 10.0

# Persistent .NET environment
ENV DOTNET_ROOT=/home/user/.dotnet
ENV PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools

# Verify .NET installation
RUN whoami && dotnet --version

# Clone private repositories
RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
    git clone \
      https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorLib.git \
      /home/user/code/NetworkMonitorLib && \
    git clone \
      https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorLLM.git \
      /home/user/code/NetworkMonitorLLM && \
    git clone \
      https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorData.git \
      /home/user/code/NetworkMonitorData

# Apply llama.cpp patches
#RUN git -C /home/user/code/models/llama.cpp apply \
#      /home/user/code/NetworkMonitorLLM/patches/qwen35_imrope_context_shift_fix.diff

# Build llama.cpp with OpenBLAS
RUN export PKG_CONFIG_PATH=/opt/OpenBLAS/lib/pkgconfig:$PKG_CONFIG_PATH && \
    cmake \
      -S /home/user/code/models/llama.cpp \
      -B /home/user/code/models/llama.cpp/build \
      -DGGML_BLAS=ON \
      -DGGML_BLAS_VENDOR=OpenBLAS \
      -DBLAS_INCLUDE_DIRS=/home/user/code/models/OpenBLAS \
      -DLLAMA_CURL=OFF && \
    cmake --build /home/user/code/models/llama.cpp/build \
      --config Release -j2 && \
    cp /home/user/code/models/llama.cpp/build/bin/* \
       /home/user/code/models/llama.cpp/

# Copy application files
COPY --chown=user:user appsettings.json \
    /home/user/code/app/appsettings.json

COPY --chown=user:user index.html \
    /home/user/code/app/wwwroot/index.html

# Working directory for model tasks
WORKDIR /home/user/code/models

# Hugging Face Spaces port
EXPOSE 7860

# Build .NET project
WORKDIR /home/user/code/NetworkMonitorLLM

RUN dotnet restore && \
    dotnet build -c Release

# Copy runtime files and remove sources
RUN cp -r /home/user/code/NetworkMonitorLLM/bin/Release/net10.0/* \
          /home/user/code/app/ && \
    rm -rf \
      /home/user/code/NetworkMonitorLib \
      /home/user/code/NetworkMonitorLLM \
      /home/user/code/NetworkMonitorData

# Final runtime directory
WORKDIR /home/user/code/app

CMD ["dotnet", "NetworkMonitorLLM.dll", "--urls", "http://0.0.0.0:7860"]