A comprehensive collection of 10 Python scripts for DevOps operations. All scripts are well-documented, type-annotated, and include comprehensive tests. These scripts serve as examples and templates for various DevOps tasks.
This repository provides example implementations of common DevOps operations using Python. Each script demonstrates best practices, error handling, and command-line interface design that can be adapted to your specific needs.
Manages cloud infrastructure provisioning for AWS, GCP, and Azure.
- Multi-cloud provider support
- VPC, subnet, and cluster creation
- Environment-specific configurations
- Examples showing provider abstractions
Usage:
python scripts/provision_infrastructure.py --provider aws --mode provisionHandles Kubernetes deployments, services, and configurations.
- Deployment, service, ConfigMap, and Secret management
- YAML manifest generation
- Namespace support
Usage:
python scripts/k8s_deploy.py --namespace production --deploy --deployment myappManages Docker containers and images.
- Container lifecycle management (run, stop, remove)
- Image building and operations
- Log viewing and resource cleanup
Usage:
python scripts/docker_manager.py run --image nginx --name webserverGenerates CI/CD pipeline configurations.
- GitHub Actions, GitLab CI, and Jenkins pipeline generation
- Customizable job templates
- Platform-specific configurations
Usage:
python scripts/cicd_generator.py --platform github --output .github/workflows/ci.ymlSystem metrics collection and log monitoring.
- CPU, memory, disk, and network monitoring
- Process information
- Docker container logs
- Continuous monitoring loop
Usage:
python scripts/monitoring.py --monitor --interval 5 --duration 300Security vulnerability scanning and auditing.
- Hardcoded secrets detection
- SQL injection vulnerability checks
- Code injection detection
- Weak hashing algorithm detection
Usage:
python scripts/security_audit.py --scan directory --directory ./srcDatabase backup and restore operations.
- PostgreSQL, MySQL, MongoDB, and SQLite support
- Backup compression
- Automated cleanup
Usage:
python scripts/database_backup.py --database postgresql --name mydbGit workflow automation.
- Commit, push, and pull operations
- Branch management
- Status monitoring
Usage:
python scripts/git_operations.py commit --message "Update configuration"Terraform configuration management.
- Terraform operations (init, plan, apply, destroy)
- State management
- Configuration validation
Usage:
python scripts/terraform_manager.py --dir terraform apply --auto-approveConfiguration file management.
- Config file backup and restore
- Environment variable management
- YAML/JSON/INI support
Usage:
python scripts/config_manager.py env set --key API_KEY --value secret123All scripts include comprehensive test suites:
# Run all tests
python tests/test_all.py
# Run specific test file
python tests/test_provision_infrastructure.py
python tests/test_k8s_deploy.py
python tests/test_docker_manager.py
python tests/test_security_audit.py
python tests/test_database_backup.py
python tests/test_git_operations.py
python tests/test_terraform_manager.py
python tests/test_config_manager.pypip install -r requirements.txt- Python 3.7+
- PyYAML 6.0+
For full functionality with all providers:
- boto3 (AWS)
- google-cloud-storage (GCP)
- azure-storage-blob (Azure)
- psycopg2-binary (PostgreSQL)
- mysql-connector-python (MySQL)
- pymongo (MongoDB)
- docker (Docker SDK)
- kubernetes (Kubernetes client)
.
├── scripts/ # All Python scripts
│ ├── provision_infrastructure.py
│ ├── k8s_deploy.py
│ ├── docker_manager.py
│ ├── cicd_generator.py
│ ├── monitoring.py
│ ├── security_audit.py
│ ├── database_backup.py
│ ├── git_operations.py
│ ├── terraform_manager.py
│ └── config_manager.py
├── docs/ # Documentation
│ ├── provision_infrastructure.md
│ ├── k8s_deploy.md
│ ├── docker_manager.md
│ ├── cicd_generator.md
│ ├── monitoring.md
│ ├── security_audit.md
│ ├── database_backup.md
│ ├── git_operations.md
│ ├── terraform_manager.md
│ └── config_manager.md
├── tests/ # Test files
│ ├── test_provision_infrastructure.py
│ ├── test_k8s_deploy.py
│ ├── test_docker_manager.py
│ ├── test_security_audit.py
│ ├── test_database_backup.py
│ ├── test_git_operations.py
│ ├── test_terraform_manager.py
│ ├── test_config_manager.py
│ └── test_all.py
├── logs/ # Output directory for logs
├── backups/ # Backup directory
├── requirements.txt # Python dependencies
└── README.md # This file
Each script includes comprehensive documentation with:
- Usage examples
- Command reference
- Configuration details
- Architecture diagrams
- Workflow sequences
- provision_infrastructure.md - Cloud infrastructure provisioning
- k8s_deploy.md - Kubernetes deployment management
- docker_manager.md - Docker container operations
- cicd_generator.md - CI/CD pipeline generation
- monitoring.md - System monitoring and logging
- security_audit.md - Security vulnerability scanning
- database_backup.md - Database backup and restore
- git_operations.md - Git workflow automation
- terraform_manager.md - Terraform configuration management
- config_manager.md - Configuration file management
- Add your script to the
scripts/directory - Include comprehensive docstrings
- Add type annotations
- Create corresponding tests in
tests/ - Add documentation in
docs/ - Update this README
These scripts are designed as examples and templates that demonstrate:
- Clean, modular Python code
- Proper error handling
- Command-line interface design
- Type annotations
- Comprehensive testing
- Documentation standards
You can:
- Learn by studying the implementations
- Adapt the scripts to your specific needs
- Extend with additional features
- Reference for similar operations
- Always review the code before using in production
- Customize configurations to your environment
- Test thoroughly in development before deployment
- Add logging for production use
- Implement error handling appropriate to your use case
- Securely manage credentials and sensitive data
- Monitor script outputs and logs
- Document any customizations made
This project is provided as-is for educational and reference purposes.
For issues or questions:
- Review the inline documentation in each script
- Check the detailed documentation in
docs/ - Examine the test files for usage examples
- Create an issue in the repository
- 10 complete scripts demonstrating DevOps operations
- 8 test files with comprehensive test coverage
- 10 detailed documentation files with mermaid diagrams
- Type annotations throughout all scripts
- Error handling for common scenarios
- Command-line interfaces with argparse
- Logging capabilities
- Modular design for easy customization
- Extensive examples and usage patterns
python scripts/docker_manager.py \
build \
--dockerfile Dockerfile \
--tag myapp:latest
python scripts/docker_manager.py \
run \
--image myapp:latest \
--name myapp \
--port 8080:8080python scripts/provision_infrastructure.py \
--provider aws \
--mode provision \
--project-id my-projectpython scripts/monitoring.py \
--monitor \
--interval 5 \
--duration 60- Clone the repository
- Install dependencies:
pip install -r requirements.txt - Review the scripts in
scripts/ - Run the tests:
python tests/test_all.py - Customize as needed for your use case
These scripts are example implementations designed to demonstrate:
- Python programming best practices
- DevOps automation techniques
- Command-line tool design
- Testing and documentation standards
Use them as reference implementations and adapt them to suit your specific needs. They are not production-ready out-of-the-box and may require additional configuration and testing for actual deployment.