diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..30528df --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: Python CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install dependencies + run: pip install -r req.txt + + - name: Syntax check + run: python -m py_compile $(find . -name "*.py") diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..0731374 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,30 @@ +name: Docker Build & Push + +on: + push: + branches: [ "main" ] + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build & Push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: aryansharma04/systemmonitoring:latest + cache-from: type=registry,ref=aryansharma04/systemmonitoring:cache + cache-to: type=registry,ref=aryansharma04/systemmonitoring:cache,mode=max diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index cdbeb17..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: CI/CD Pipeline for Docker - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - 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: ${{ github.event_name != 'pull_request' }} - tags: aryansharma04/systemmonitoring:latest - - - name: Clean up images - run: docker image prune -af diff --git a/Dockerfile b/Dockerfile index 808ae13..503fe78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,32 @@ -# Use full Python image (not slim) to avoid missing system libs -FROM python:3.11 +# ---------- Stage 1: Build dependencies ---------- +FROM python:3.11-slim AS builder -# Set working directory WORKDIR /app -# Install required system dependencies for pandas & scikit-learn -RUN apt-get update && apt-get install -y \ - gcc \ - g++ \ - make \ +RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ libopenblas-dev \ liblapack-dev \ gfortran \ && rm -rf /var/lib/apt/lists/* -# Copy requirements first to leverage Docker cache COPY 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 +RUN pip install --upgrade pip \ + && pip install --no-cache-dir -r req.txt \ + && pip install --no-cache-dir uvicorn -# Copy application files +# ---------- Stage 2: Final lightweight image ---------- +FROM python:3.11-slim + +WORKDIR /app + +# Copy only installed packages (fast!) +COPY --from=builder /usr/local /usr/local + +# Copy app code COPY . . -# Expose FastAPI port EXPOSE 8000 -# Run FastAPI app CMD ["uvicorn", "apps:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/SystemMonitoring b/SystemMonitoring new file mode 160000 index 0000000..93769c8 --- /dev/null +++ b/SystemMonitoring @@ -0,0 +1 @@ +Subproject commit 93769c8898407deda1c4b5ac07672efbaa60c918 diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..5e5f16f Binary files /dev/null and b/__pycache__/__init__.cpython-312.pyc differ diff --git a/__pycache__/apps.cpython-312.pyc b/__pycache__/apps.cpython-312.pyc new file mode 100644 index 0000000..7ef52f2 Binary files /dev/null and b/__pycache__/apps.cpython-312.pyc differ diff --git a/tests/__pycache__/conftest.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/conftest.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000..7d59b6b Binary files /dev/null and b/tests/__pycache__/conftest.cpython-312-pytest-8.4.2.pyc differ diff --git a/tests/__pycache__/test_data_processing.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/test_data_processing.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000..91c8472 Binary files /dev/null and b/tests/__pycache__/test_data_processing.cpython-312-pytest-8.4.2.pyc differ diff --git a/tests/__pycache__/test_endpoints.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/test_endpoints.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000..509d6c4 Binary files /dev/null and b/tests/__pycache__/test_endpoints.cpython-312-pytest-8.4.2.pyc differ diff --git a/tests/__pycache__/test_integration.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/test_integration.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000..36bac02 Binary files /dev/null and b/tests/__pycache__/test_integration.cpython-312-pytest-8.4.2.pyc differ diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..85d7212 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,6 @@ +import os +import sys + +# Get the parent directory of tests (project root) +project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, project_root) \ No newline at end of file diff --git a/tests/test_data_processing.py b/tests/test_data_processing.py new file mode 100644 index 0000000..87983b5 --- /dev/null +++ b/tests/test_data_processing.py @@ -0,0 +1,4 @@ +def test_sample_data(): + data = [1, 2, 3] + result = sum(data) + assert result == 6 diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py new file mode 100644 index 0000000..d287c1c --- /dev/null +++ b/tests/test_endpoints.py @@ -0,0 +1,17 @@ +from fastapi.testclient import TestClient +import sys +import os +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from apps import app + +client = TestClient(app) + +def test_root_endpoint(): + response = client.get("/") + assert response.status_code == 200 + assert response.json() == {"message": "Hello World"} # matches your code + +def test_health_endpoint(): + response = client.get("/health") + assert response.status_code == 200 + assert response.json() == {"status": "ok"} # matches your code diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..4911aeb --- /dev/null +++ b/tests/test_integration.py @@ -0,0 +1,4 @@ +def test_integration_example(): + x = 5 + y = 10 + assert x + y == 15