From a721f7d56be31500db50d438d2418bd106f6dc69 Mon Sep 17 00:00:00 2001
From: ashhley04
Date: Mon, 20 Oct 2025 20:49:22 +0530
Subject: [PATCH 1/2] Add Docker support for local development (closes #2)
---
Dockerfile | 33 +++++++++++++++++++++++-----
README.md | 6 +++++
apps.py | 15 +++++++++++++
docker-compose.yml | 55 ++++++++++++++++++++--------------------------
prometheus.yml | 22 +++++++------------
req.txt | 4 ++--
6 files changed, 83 insertions(+), 52 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index 75cda53..808ae13 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,9 +1,32 @@
-FROM python:3.8.8-slim
+# Use full Python image (not slim) to avoid missing system libs
+FROM python:3.11
-COPY . .
+# Set working directory
+WORKDIR /app
+
+# Install required system dependencies for pandas & scikit-learn
+RUN apt-get update && apt-get install -y \
+ gcc \
+ g++ \
+ make \
+ build-essential \
+ libopenblas-dev \
+ liblapack-dev \
+ gfortran \
+ && rm -rf /var/lib/apt/lists/*
+
+# Copy requirements first to leverage Docker cache
+COPY req.txt .
-RUN pip install -r req.txt
+# Upgrade pip and install Python dependencies
+RUN pip install --upgrade pip setuptools wheel --no-cache-dir \
+ && pip install --no-cache-dir -r req.txt
+
+# Copy application files
+COPY . .
-RUN python data_prepare.py
+# Expose FastAPI port
+EXPOSE 8000
-CMD uvicorn --host=0.0.0.0 app:app
+# Run FastAPI app
+CMD ["uvicorn", "apps:app", "--host", "0.0.0.0", "--port", "8000"]
diff --git a/README.md b/README.md
index ced1223..24c1ec7 100644
--- a/README.md
+++ b/README.md
@@ -92,3 +92,9 @@ https://hub.docker.com/r/aryansharma04/systemmonitoring
+## 🚀 Running the SystemMonitoring Stack with Docker
+
+### Build and Start
+```bash
+docker-compose up --build
+
diff --git a/apps.py b/apps.py
index e69de29..75085db 100644
--- a/apps.py
+++ b/apps.py
@@ -0,0 +1,15 @@
+from fastapi import FastAPI
+from prometheus_fastapi_instrumentator import Instrumentator
+
+app = FastAPI()
+
+# Create metrics endpoint
+Instrumentator().instrument(app).expose(app)
+
+@app.get("/")
+def read_root():
+ return {"message": "Hello World"}
+
+@app.get("/health")
+def health_check():
+ return {"status": "ok"}
diff --git a/docker-compose.yml b/docker-compose.yml
index add7530..3b82143 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,52 +1,45 @@
-version: "3.8"
+version: "3.9"
services:
- app:
+ # FastAPI App
+ fastapi:
build: .
- restart: unless-stopped
- container_name: reco-app
+ container_name: systemmonitoring_app
ports:
- - 8000:8000
+ - "8000:8000"
+ depends_on:
+ - prometheus
networks:
- example-network:
- ipv4_address: 172.16.238.10
+ - monitoring
+ # Prometheus
prometheus:
image: prom/prometheus:latest
- restart: unless-stopped
container_name: prometheus
- ports:
- - 9090:9090
volumes:
- - ./prometheus.yml:/etc/prometheus/prometheus.yml
- command:
- - "--config.file=/etc/prometheus/prometheus.yml"
+ - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
+ ports:
+ - "9090:9090"
networks:
- example-network:
- ipv4_address: 172.16.238.11
+ - monitoring
+ # Grafana
grafana:
image: grafana/grafana:latest
- restart: unless-stopped
- user: "472"
container_name: grafana
+ environment:
+ - GF_SECURITY_ADMIN_USER=admin
+ - GF_SECURITY_ADMIN_PASSWORD=admin
+ - GF_INSTALL_PLUGINS=grafana-piechart-panel,grafana-clock-panel
+ volumes:
+ - ./provisioning:/etc/grafana/provisioning:ro
+ ports:
+ - "3000:3000"
depends_on:
- prometheus
- ports:
- - 3000:3000
- volumes:
- - ./provisioning/:/etc/grafana/provisioning/
- env_file:
- - ./config.monitoring
networks:
- example-network:
- ipv4_address: 172.16.238.12
+ - monitoring
networks:
- example-network:
- name: example-network
+ monitoring:
driver: bridge
- ipam:
- driver: default
- config:
- - subnet: 172.16.238.0/24
diff --git a/prometheus.yml b/prometheus.yml
index 1961fcd..97c09b9 100644
--- a/prometheus.yml
+++ b/prometheus.yml
@@ -1,20 +1,14 @@
global:
- scrape_interval: 1m
+ scrape_interval: 15s
evaluation_interval: 15s
external_labels:
- monitor: "reco-app"
-
-rule_files:
+ monitor: "systemmonitoring"
scrape_configs:
- # - job_name: "prometheus"
-
- # static_configs:
- # - targets: ["localhost:9090"]
+ - job_name: "prometheus"
+ static_configs:
+ - targets: ["prometheus:9090"]
- - job_name: "reco-app"
- dns_sd_configs:
- - names: ["reco-app"]
- port: 8000
- type: A
- refresh_interval: 30s
+ - job_name: "fastapi"
+ static_configs:
+ - targets: ["fastapi:8000"]
diff --git a/req.txt b/req.txt
index 55a6dcb..28c5bf2 100644
--- a/req.txt
+++ b/req.txt
@@ -1,8 +1,8 @@
pandas==1.3.5
fastapi==0.70.1
starlette==0.16.0
-pydantic==1.9.0
+pydantic<2
prometheus_client==0.12.0
prometheus_fastapi_instrumentator==5.7.1
uvicorn==0.16.0
-scikit-learn==1.0.2
\ No newline at end of file
+scikit-learn==1.2.2
From 88d725f42872296b8e128e49cb10f3e6eaaa68e1 Mon Sep 17 00:00:00 2001
From: ashhley04
Date: Fri, 24 Oct 2025 13:25:37 +0530
Subject: [PATCH 2/2] Fix: skip Docker login for PRs and build/push Docker
image
---
.github/workflows/docker-image.yml | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml
index aa65f55..cdbeb17 100644
--- a/.github/workflows/docker-image.yml
+++ b/.github/workflows/docker-image.yml
@@ -19,17 +19,25 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
+ # 👇 Only log in to Docker Hub for non-pull-request events
- name: Log in to Docker Hub
+ if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
+ # 👇 Skip message for PRs
+ - name: Skip Docker login on pull requests
+ if: github.event_name == 'pull_request'
+ run: echo "Skipping Docker login — secrets are unavailable in PRs."
+
+ # 👇 Build and push Docker image
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
- push: true
+ push: ${{ github.event_name != 'pull_request' }}
tags: aryansharma04/systemmonitoring:latest
- name: Clean up images