Skip to content

Feature/lhlai 236 setup cicd#33

Closed
fakebizprez wants to merge 39 commits intomasterfrom
feature/lhlai-236-setup-cicd
Closed

Feature/lhlai 236 setup cicd#33
fakebizprez wants to merge 39 commits intomasterfrom
feature/lhlai-236-setup-cicd

Conversation

@fakebizprez
Copy link
Copy Markdown
Member

@fakebizprez fakebizprez commented Jan 3, 2026

greptile

Summary by CodeRabbit

  • New Features

    • Added REST API with Bearer token authentication and Swagger documentation
    • Integrated Slack webhook alerts for temperature and humidity thresholds with configurable cooldown
    • Added health check and system metrics endpoints
    • Enabled periodic status updates via webhooks
    • Added Cloudflare tunnel support for secure remote access
  • Infrastructure

    • Introduced Docker-based deployment with resource limits and health monitoring
    • Added systemd service files for production deployment
    • Implemented GitHub Actions CI/CD pipeline
  • Documentation

    • Expanded README with API endpoints, deployment options, and feature guides
    • Added comprehensive deployment and architecture documentation

✏️ Tip: You can customize this high-level summary in your review settings.

fakebizprez and others added 30 commits December 30, 2025 20:51
- Add webhook_service.py with Slack integration
- Implement threshold-based alerts (temp high/low, humidity high/low)
- Add periodic status updates via APScheduler
- Add webhook management API endpoints (/api/webhook/*)
- Include retry logic with exponential backoff
- Add 5-minute cooldown to prevent alert spam
- Add webhook documentation and quickstart guide
- Add test files for webhook and periodic updates
- Update requirements.txt with requests and APScheduler

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Token should be generated manually and stored in .env file.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update CLAUDE.md with webhook endpoints and configuration
- Update README.md with webhook setup instructions
- Update Dockerfile for new dependencies
- Add handoff documentation directory

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add Flask-RESTX for improved API structure and Swagger documentation
- Introduce new webhook management endpoints: GET, PUT, POST for configuration, enabling, and disabling webhooks
- Update requirements.txt to include flask-restx dependency
- Refactor existing webhook routes to utilize Flask-RESTX resources

This update enhances the API's usability and maintainability while providing better documentation for webhook interactions.
- Change 'url' field in webhook_config_input model to be optional for partial updates
- Update description for 'url' to clarify its requirement during new webhook creation
- Remove global security setting from API definition to allow public access to Swagger UI, while maintaining endpoint protection via decorators

This update improves the flexibility of webhook configuration and enhances API accessibility.
Co-authored-by: baz-reviewer[bot] <174234987+baz-reviewer[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Created comprehensive test suite for Flask-RESTX webhook configuration API
to ensure the bug fix at line 495 works correctly.

Test coverage includes:
- Creating webhook config when service doesn't exist (critical bug fix test)
- Creating webhook config with missing URL (validation test)
- Updating existing webhook configuration
- Getting webhook config (exists and not exists scenarios)
- Creating webhook with alert thresholds
- Invalid threshold validation
- Authentication and authorization tests

All 9 tests pass successfully, verifying the AttributeError fix prevents
crashes when creating new webhook service via API.

Related to commit 9ffd7cb
Replace return statements with webhooks_ns.abort() in webhook endpoints
to prevent @marshal_with decorator from dropping error keys during
serialization.

Affected endpoints:
- POST /api/webhook/test (400 and 500 responses)
- POST /api/webhook/enable (400 response)
- POST /api/webhook/disable (400 response)
- Check for existing URL before allowing partial updates without URL
- Preserve existing config values during partial updates instead of
  using hardcoded defaults
- Prevents creating WebhookConfig with empty URL when webhook service
  exists but has no config
feat: Integrate Flask-RESTX for webhook management API
Flask-RESTX validation returns {message, errors} format which differs
from the existing {error, details} format that clients expect.
Manual validation in the handler still runs with consistent error format.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…ature.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Flask-RESTX min/max constraints are OpenAPI docs only and not enforced
at runtime. Add validate_webhook_config() to enforce:
- retry_count: 1-10
- retry_delay: 1-60 seconds
- timeout: 5-120 seconds

Returns 400 with clear error message on violation.
…t of project restructuring. These documents are no longer needed for the current implementation and have been replaced by updated documentation practices.
…or project

- Added CLAUDE.md to provide guidance on project architecture, API endpoints, and development commands.
- Updated README.md to reflect the transition to Raspberry Pi 4 and included production deployment strategies.
- Enhanced Dockerfile and docker-compose.yml with health checks and resource limits for optimized performance.
- Introduced WSGI entry point for production deployment and a startup script for easier service management.
- Added systemd service configuration for automated deployment and monitoring.
- Included detailed production deployment guide in docs/PI4_DEPLOYMENT.md.
- Updated various files to ensure consistency with the new Raspberry Pi 4 setup and improved documentation practices.
- Add generate_error_id() for tracking errors across logs and responses
- Use logging.exception() to capture full stack traces in logs
- Return error_id instead of internal exception details to clients
- Improves security by not exposing internals while aiding debugging
- Updated API response to mask webhook URLs, revealing only the scheme and host to prevent exposure of sensitive tokens.
- Introduced a new function to handle URL masking in the WebhookService and updated relevant logging statements.
- Added unit tests to verify that webhook URLs are masked correctly in API responses.
…ng and logging

- Added new log entries in temp_monitor.log for webhook service configuration issues and API access attempts with invalid tokens.
- Enhanced error handling in temp_monitor.py by replacing specific error messages with a generic 'Internal server error' for health and metrics endpoints, while using logging.exception for better error tracking.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
- App now exits with code 1 if BEARER_TOKEN is not set instead of
  running in a degraded state with broken API endpoints
- Fixed README documentation that incorrectly stated token was
  "auto-generated if not provided"
Convert test_webhook.py from placeholder print statements to proper
unittest framework with 29 tests across 8 test classes:

- Use unittest.mock.patch to capture payloads without network calls
- Verify Slack payload structure (attachments, color, text, ts, fields)
- Assert field content, ordering, and short flags
- Confirm requests.post is never called when enabled=False
- Test all message types: basic, alerts, status updates, system events
…, locator, pattern finder, web search researcher, and commit commands. These files are no longer needed as part of the project restructuring and have been replaced by updated documentation practices.
…or project

- Introduced AGENTS.md to provide detailed guidance on project architecture, API endpoints, and development commands.
- Documented core layers including Flask application, webhook service, and API models.
- Outlined public and protected routes, configuration settings, key design patterns, and testing strategies.
- Included common issues and solutions to assist developers in troubleshooting.
fakebizprez and others added 9 commits January 1, 2026 06:51
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
- Updated the subproject commit reference from d898f21 to 5ec4fba in the exception-details file.
Resolve merge conflicts by accepting error correlation ID additions:
- Webhook config update error handler
- Test webhook error handler
- Health check error handler
- System metrics collection error
- Metrics endpoint error handler

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Updated project title and description for better clarity.
- Enhanced the features section with detailed descriptions and added new features like Swagger documentation and Docker support.
- Reorganized installation and configuration instructions for improved readability.
- Added a comprehensive table of contents for easier navigation.
- Included new sections on webhook notifications, alert thresholds, and troubleshooting.
- Removed outdated installation steps and streamlined the quick start guide.
- Deleted the exception-details subproject as it is no longer needed.
- Replaced instances of 'docker-compose' with 'docker compose' across AGENTS.md, CLAUDE.md, README.md, and PI4_DEPLOYMENT.md for uniformity and to align with the latest Docker CLI standards.
- Introduced CLOUDFLARED_TOKEN in .env.example for Cloudflare Tunnel configuration.
- Added cloudflared service to docker-compose.yml for tunnel management.
- Updated README and PI4_DEPLOYMENT.md to include instructions for setting up the Cloudflare Tunnel.
- Created LICENSE file to clarify project licensing.
Add environment selection input (production/testing) to workflow_dispatch
trigger, allowing developers to manually deploy feature branches to the
self-hosted runner for testing before merging to main.

Changes:
- Add 'environment' input with production/testing options (defaults to testing)
- Clarify deploy_ref description (remove "manual runs only")
- Add deployment info display step showing event, ref, and environment
- Document deploy conditions in workflow comments
- Clarified the optional nature of SLACK_WEBHOOK_URL in .env.example and README.md.
- Enhanced health check command in docker-compose.yml for better monitoring.
- Added cloudflare profile support in docker-compose.yml and updated deployment instructions in PI4_DEPLOYMENT.md.
- Improved GitHub Actions workflow to validate required secrets and streamline .env creation.
- Removed outdated HANDOFF.md documentation as part of project cleanup.
- Changed STATUS_UPDATE_ENABLED to true in ci.yml to activate status updates.
- Added STATUS_UPDATE_ON_STARTUP to ensure updates are sent at startup.
@linear
Copy link
Copy Markdown

linear bot commented Jan 3, 2026

LHLAI-236 Setup CI/CD

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Jan 3, 2026

Skipped: This PR does not contain any of your configured labels: (greptile)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 3, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request transforms a basic Raspberry Pi temperature monitor into a production-ready Flask application with Slack webhook notifications, API-driven configuration, health checks, Docker/systemd deployment infrastructure, and comprehensive documentation. It introduces webhook service, API models, WSGI entry point, test suites, and CI/CD automation.

Changes

Cohort / File(s) Summary
Configuration & Dependencies
.env.example, requirements.txt
Added CLOUDFLARED_TOKEN, webhook configuration (URL, retry, timeout), alert thresholds (temp/humidity min/max), and periodic status update settings. Expanded dependencies with flask-restx, requests, waitress, and psutil.
Core Application Logic
temp_monitor.py, webhook_service.py, api_models.py, wsgi.py
Introduced Flask-RESTX API endpoints for webhook management (/api/webhook/{config,test,enable,disable}), background sensor thread integration, health (/health) and metrics (/metrics) endpoints. Added WebhookService class with Slack notification logic, cooldown-based alerting, status updates, and system events. Defined API models and validation for webhook config and alert thresholds. Created WSGI entry point for production deployment.
Deployment & Infrastructure
Dockerfile, docker-compose.yml, start_production.sh, deployment/systemd/temp-monitor*.service
Switched from direct Python to Waitress WSGI server with health checks and resource limits. Added cloudflared tunnel service option, memory constraints, and readiness probing. Created systemd units for Docker Compose and standalone service with security capabilities, restart policies, and logging. Added production startup script with dependency validation.
CI/CD Automation
.github/workflows/ci.yml
Introduced GitHub Actions workflow with test job (Python 3.9, pytest modules) and conditional deployment job (secrets validation, .env generation, Docker Compose deployment to self-hosted runner).
Testing
test_webhook_api.py, test_webhook.py, test_periodic_updates.py, test_api_models.py
Added comprehensive test suites for webhook API endpoints (config/test/enable/disable with auth), webhook service payload validation (alerts, status, system events, cooldowns), periodic update timing logic, and validation functions for webhook config and thresholds.
Documentation
README.md, CLAUDE.md, AGENTS.md, docs/PI4_DEPLOYMENT.md, LICENSE, thoughts/tasks/...
Completely rewrote README with production deployment paths, API endpoints, bearer token authentication, Slack webhook setup, and troubleshooting. Added comprehensive architecture guides (CLAUDE.md, AGENTS.md), Pi 4 deployment guide with health checks and backup procedures, MIT license, and research notes on Pydantic validation strategy.
Version Control & Cleanup
.gitignore, generate_token.py
Updated .gitignore to ignore .claude/ directory. Removed generate_token.py in favor of environment-based configuration and documentation-driven token generation.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Sensor as Sensor Thread
    participant App as Flask App
    participant WS as Webhook Service
    participant Slack as Slack API
    
    rect rgb(220, 240, 220)
    Note over Sensor,Slack: Temperature Alert Flow
    Sensor->>Sensor: Read temp/humidity
    Sensor->>App: Update readings
    App->>WS: check_and_alert(temp, humidity)
    alt Temperature exceeds threshold
        WS->>WS: Check cooldown & enabled
        alt Can send alert
            WS->>WS: Format Slack payload<br/>(color, icon, fields)
            WS->>Slack: POST webhook<br/>(with retry logic)
            Slack-->>WS: 200 OK
            WS->>WS: Mark alert sent<br/>(set cooldown)
            WS-->>App: {alert_type: true}
        else Still in cooldown
            WS-->>App: {alert_type: false}
        end
    else Within normal range
        WS-->>App: {alert_type: false}
    end
    end
    
    rect rgb(220, 220, 240)
    Note over Sensor,Slack: Periodic Status Update Flow
    Sensor->>WS: send_status_update(<br/>temp, humidity, cpu_temp)
    WS->>WS: Format status payload<br/>(fields: temp, humidity, CPU, timestamp)
    WS->>Slack: POST webhook<br/>(with timeout & retries)
    Slack-->>WS: 200 OK
    WS-->>Sensor: success: true
    end
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly Related PRs

  • Write a CLAUDE.md #9: Touches CLAUDE.md documentation; this PR significantly rewrites and expands CLAUDE.md as part of the broader documentation refresh for production readiness.

Poem

🐰 Hop, hop—the monitor grows so smart!
With webhooks singing Slack alerts from the start,
Health checks and thresholds, a thread that won't tire,
Docker and Waitress lift spirits higher!
From Pi to production, we've built quite a sight, 🚀

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da64f2f and 71589af.

⛔ Files ignored due to path filters (1)
  • temp_monitor.log is excluded by !**/*.log
📒 Files selected for processing (24)
  • .env.example
  • .github/workflows/ci.yml
  • .gitignore
  • AGENTS.MD
  • CLAUDE.md
  • Dockerfile
  • LICENSE
  • README.md
  • api_models.py
  • deployment/systemd/temp-monitor-compose.service
  • deployment/systemd/temp-monitor.service
  • docker-compose.yml
  • docs/PI4_DEPLOYMENT.md
  • generate_token.py
  • requirements.txt
  • start_production.sh
  • temp_monitor.py
  • test_api_models.py
  • test_periodic_updates.py
  • test_webhook.py
  • test_webhook_api.py
  • thoughts/tasks/issue-24-pydantic-validation/2025-12-31-research.md
  • webhook_service.py
  • wsgi.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

This was linked to issues Jan 3, 2026
@fakebizprez
Copy link
Copy Markdown
Member Author

@

@fakebizprez fakebizprez closed this Jan 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include Cloudflared Tunnel Self-Hosted Runners Setup CI/CD

1 participant