Spaces:
Running
Running
| # 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/NetworkMonitorLib.git /home/user/code/NetworkMonitorLib && \ | |
| git clone https://$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorChatRazorLib.git /home/user/code/NetworkMonitorChatRazorLib && \ | |
| git clone https://$(cat /run/secrets/GITHUB_TOKEN)@github.com/Mungert69/NetworkMonitorBlazor.git /home/user/code/NetworkMonitorBlazor | |
| # Copy wwwroot from the cloned repo (inside container) | |
| RUN cp -r /home/user/code/NetworkMonitorBlazor/wwwroot /home/user/code/app/ | |
| # After cloning all repositories | |
| 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/NetworkMonitorLib /home/user/code/NetworkMonitorBlazor /home/user/code/NetworkMonitorChatRazorLib | |
| # 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"] | |