File size: 2,884 Bytes
d7c7c9b
 
 
 
 
 
 
 
 
 
 
 
14d341d
 
d7c7c9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f78e821
d7c7c9b
 
3368936
 
f78e821
d7c7c9b
9900ffa
 
8112753
d2808ac
 
f78e821
d7c7c9b
 
 
 
 
 
 
 
 
 
 
53d664b
 
d7c7c9b
 
 
 
 
 
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
# Use the official Debian 12 (Bookworm) base image
FROM debian:12

# Set environment variables to avoid interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install system-level dependencies as root
RUN apt-get update && \
    apt-get install -y \
        curl \
        git \
        wget \
        vim  \
        libicu-dev

# Create a non-root user and set up their environment
RUN useradd -m user && \
    mkdir -p /home/user/code && \
    chown -R user:user /home/user

# Switch to the non-root user
USER user
WORKDIR /home/user

RUN mkdir -p /home/user/code/models && \
    mkdir -p /home/user/code/app/wwwroot 


# Install .NET 9.0 as the non-root user
RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh && \
    chmod +x dotnet-install.sh && \
    ./dotnet-install.sh --channel 9.0

# Set persistent environment variables
ENV DOTNET_ROOT=/home/user/.dotnet
ENV PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools

# Verify .NET installation and current user
RUN whoami && dotnet --version

# Clone repositories using the GITHUB_TOKEN secret
RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
    git clone https://$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitor.git /home/user/code/NetworkMonitor && \
    git clone https://$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/FreeNetworkMonitorAgent.git /home/user/code/FreeNetworkMonitorAgent && \
    git clone https://$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorBlazor.git /home/user/code/NetworkMonitorBlazor


# Debug: Check if Components exists
RUN test -d /home/user/code/FreeNetworkMonitorAgent/Components && echo "Components found!" || echo "Components MISSING"

# Copy wwwroot from the cloned repo (inside container)
RUN cp -r /home/user/code/NetworkMonitorBlazor/wwwroot /home/user/code/app/
# After cloning all repositories
# Delete the symlink (if it exists) and copy the real folder
RUN rm -rf /home/user/code/NetworkMonitorBlazor/Components && \
    cp -r /home/user/code/FreeNetworkMonitorAgent/Components /home/user/code/NetworkMonitorBlazor/
# Expose port 7860 for Hugging Face Spaces
EXPOSE 7860
# Set the working directory
WORKDIR /home/user/code/NetworkMonitorBlazor

# Build the .NET project as the non-root user
RUN dotnet restore && \
    dotnet build -c Release

RUN cp -r /home/user/code/NetworkMonitorBlazor/bin/Release/net9.0/* /home/user/code/app/ && \
    rm -rf /home/user/code/NetworkMonitor /home/user/code/NetworkMonitorBlazor /home/user/code/NetworkMonitorAgent
# Copy files into the container as the non-root user
COPY --chown=user:user appsettings.json /home/user/code/app/appsettings.json

# Set the working directory to the `app` directory
WORKDIR /home/user/code/app

# Run the .NET app as the non-root user
CMD ["dotnet", "NetworkMonitorBlazor.dll", "--urls", "http://0.0.0.0:7860"]