Repository: ai_deploy_openai.sh
This repository contains a powerful AI-assisted deployment script for containerized microservices using Docker Compose and Kafka. The script integrates the OpenAI API to automatically detect errors, generate fix suggestions, and create detailed fix reports for every deployment step.
- Overview
- Features
- Deployment Steps
- Health Checks
- Fix Reports
- Deployment & AI-Fix Workflow
- Benefits
- Future Enhancements
- Usage
ai_deploy_openai.sh is a robust DevOps deployment assistant that automates the deployment of microservices. It handles starting/stopping containers and Kafka topics, analyzes errors using AI, provides actionable fix suggestions, and maintains an audit trail of logs and reports.
Ideal for web services, APIs, and microservice architectures where deployment complexity can lead to errors.
- Full Deployment Automation: Stops and cleans old containers, prunes Docker resources, rebuilds services, and launches Zookeeper, Kafka, and application services.
- Kafka Topic Management: Creates Kafka topics with automatic existence checks.
- AI-Powered Error Detection and Fixes: On failure, the script sends error logs to OpenAI, retrieves a suggested fix, and generates a Fix Report.
- Detailed Logging: Maintains logs for all deployment steps and errors.
- Health Checks: Verifies running containers, Kafka/Zookeeper ports, Kafka topics, and API endpoints.
- Descriptive Fix Reports: Timestamped reports contain error logs and AI-recommended fixes for traceability.
-
Full System Cleanup
- Stops all containers and removes volumes.
- Prunes Docker system resources.
- Kills any leftover Kafka/Flask/Python processes.
-
Fresh Start Procedure
- Rebuilds all Docker services.
- Starts Zookeeper, Kafka, and remaining services.
- Waits for proper initialization.
-
Verification Steps
- Checks running Docker containers.
- Creates Kafka topics safely (avoiding duplicates).
- Tests API endpoints with example data.
- Validates Kafka message flow.
After deployment, the script performs automated health verification:
- Docker container status.
- Zookeeper and Kafka port reachability.
- Kafka topic test (produce and consume message).
- API endpoint response check (HTTP 200).
Whenever a step fails, the script:
- Saves the error log in
Logs/with timestamped file names. - Sends the error to OpenAI API to generate a fix suggestion.
- Creates a Fix Report in
FixReports/with:- Path to the error file.
- AI suggested fix description.
- Step name and timestamp.
This ensures full traceability and actionable steps for developers.
flowchart TD
A[Start Deployment] --> B[Full System Cleanup]
B --> C[Rebuild Docker Services]
C --> D[Start Zookeeper]
D --> E[Start Kafka]
E --> F[Start All Other Services]
F --> G[Check Running Containers]
G --> H[Create Kafka Topics]
H --> I[Test API Endpoint]
I --> J[Check Kafka Messages]
J --> K[Health Check]
%% Health Check Branches
K --> K1[Docker Containers Running?]
K --> K2[Zookeeper Port Reachable?]
K --> K3[Kafka Port Reachable?]
K --> K4[Kafka Topic Test]
K --> K5[API Endpoint Test]
%% AI Fix Integration
J --> L{Step Failed?}
L -->|Yes| M[Save Error Log in Logs/]
M --> N[Send Error to OpenAI]
N --> O[Receive AI Suggested Fix]
O --> P[Save Fix Report in FixReports/]
P --> Q[Retry Step if Needed]
L -->|No| R[Step Successful]
%% End
K1 --> S[Deployment Complete]
K2 --> S
K3 --> S
K4 --> S
K5 --> S
R --> S