AI-powered CLI tool that automatically generates, builds, and tests Dockerfiles for existing scripts using LLM providers (Default: OpenAI's GPT-4o-mini).
This project creates a generic tool that can wrap any script with Docker containers, automatically build and test them to ensure they work correctly.
nitzanScriptWrap/
├── scripts/ # Example scripts with documentation
│ ├── line_counter/
│ │ ├── line_counter.sh # Bash script example
│ │ └── README.md # Usage documentation
│ └── vowel_counter/
│ ├── vowel_counter.js # Node.js script example
│ └── README.md # Usage documentation
├── src/ # Source code
│ ├── cli.ts # Main CLI interface
│ ├── config.ts # Generic LLM configuration
│ ├── llm-factory.ts # LLM provider factory
│ ├── providers/ # LLM provider implementations
│ ├── docker.ts # Docker operations
│ ├── security.ts # Input sanitization
│ └── test/ # Test suite
├── .env.example # Environment configuration template
├── package.json # Dependencies and scripts
└── README.md # This file
🔧 Advanced Features# 🔧 ** project creates a generic tool that can wrap any script with Docker containers, automatically build and test them to ensure they work correctly.
- ✅ AI Integration: Uses OpenAI GPT-4o-mini with optimized prompts
- ✅ Generic Script Wrapper: Works with any script type (bash, Node.js, Python, etc.)
- ✅ Dockerfile Generation: Creates production-ready Dockerfiles automatically
- ✅ Build & Test Pipeline: Builds Docker images and tests execution with examples
- ✅ Output Verification: Validates containerized scripts produce expected results
- ✅ LLM Vendor-Agnostic: Extensible architecture for multiple AI providers
- ✅ Comprehensive Testing: Automated test suite for the wrapping process
- ✅ Security & Sanitization: Input validation and prompt injection protection
- Node.js 20+
- Docker (installed and running)
- LLM API Key (OpenAI, Anthropic, or local model)
# Clone or extract the project
cd nitzanScriptWrap
# Install dependencies
npm install
# Setup environment
cp .env.example .env
# Edit .env and configure your LLM provider:# Generic LLM Configuration (Recommended)
LLM_API_KEY=your-api-key-here
LLM_PROVIDER=openai # openai, anthropic, local
LLM_MODEL=gpt-4o-mini # Provider-specific model
LLM_TEMPERATURE=0.1 # Creativity level (0-2)
LLM_MAX_TOKENS=2000 # Response length limit
# Legacy support (backward compatible)
OPENAI_API_KEY=your-openai-key-here# Full workflow (default) - Generate, Build, Test, Verify
npm start <script-path> <readme-path>
# Example with provided test files
npm start ./scripts/vowel_counter/vowel_counter.js ./scripts/vowel_counter/README.md
npm start ./scripts/line_counter/line_counter.sh ./scripts/line_counter/README.mdGenerates Dockerfile, builds image, runs container, and verifies output:
npm start ./scripts/vowel_counter/vowel_counter.js ./scripts/vowel_counter/README.mdWhat happens:
- 🔒 Security scan of inputs
- 🤖 AI generates optimized Dockerfile
- 🔨 Builds Docker image
- 🚀 Runs container with example from README
- ✅ Verifies output matches expected result
- 📄 Outputs final Dockerfile
Specify your own example command and expected output:
npm start ./script.py ./README.md "python script.py test" "Expected output"Just generate the Dockerfile without building/testing:
npm start ./script.sh ./README.md --generate-onlyOverride LLM settings per command:
# Use higher creativity for more varied Dockerfiles
LLM_TEMPERATURE=0.8 npm start ./script.py ./README.md
# Use different model (if available)
LLM_MODEL=gpt-4 npm start ./script.py ./README.md
# Use different provider (when implemented)
LLM_PROVIDER=anthropic LLM_API_KEY=your-anthropic-key npm start ./script.py ./README.mdOverride security warnings:
npm start ./script.sh ./README.md --forcenpm test# Test Node.js script
npm start ./scripts/vowel_counter/vowel_counter.js ./scripts/vowel_counter/README.md
# Test Bash script
npm start ./scripts/line_counter/line_counter.sh ./scripts/line_counter/README.md- ✅ Security scan passes
- ✅ Dockerfile generated with appropriate base image
- ✅ Docker image builds successfully
- ✅ Container runs and produces expected output
- ✅ Output verification passes
# Node.js script with full workflow
npm start ./scripts/vowel_counter/vowel_counter.js ./scripts/vowel_counter/README.md
# Output: Dockerfile + build + test + verify
# Bash script with full workflow
npm start ./scripts/line_counter/line_counter.sh ./scripts/line_counter/README.md
# Output: Dockerfile + build + test + verify
# Python script (if you have one)
npm start ./my_script.py ./README.md
# Auto-detects Python and uses appropriate base image# Default configuration (from .env file)
npm start ./script.sh ./README.md
# Override temperature for more creative Dockerfiles
LLM_TEMPERATURE=0.8 npm start ./script.sh ./README.md
# Use maximum creativity
LLM_TEMPERATURE=2.0 npm start ./script.sh ./README.md
# Override model (if you have access)
LLM_MODEL=gpt-4 npm start ./script.sh ./README.md
# Combine multiple overrides
LLM_MODEL=gpt-4 LLM_TEMPERATURE=0.5 npm start ./script.sh ./README.mdCommand:
npm start ./scripts/line_counter/line_counter.sh ./scripts/line_counter/README.mdOutput:
🤖 Using openai (gpt-4o-mini) with temperature 0.1
🔒 Performing security scan...
✅ Security scan passed
Building & Testing: line_counter.sh
Using example: ./scripts/line_counter/line_counter.sh 'Hello\nWorld'
Container command: /line_counter.sh Hello\nWorld
---
✅ Dockerfile generated successfully
🔨 Building Docker image...
✅ Docker image built successfully
🚀 Running container with example...
📤 Container output:
stdout: Line Count: 2
stderr:
exit code: 0
✅ Container executed successfully
🎉 All tests passed! Dockerfile is working correctly.
FROM bash:latest
COPY line_counter.sh /line_counter.sh
RUN chmod +x /line_counter.sh
ENTRYPOINT ["bash", "/line_counter.sh"]
CMD ["Hello\nWorld\nTest"]
The tool uses a vendor-agnostic configuration system that works with any LLM provider:
# OpenAI Configuration
LLM_PROVIDER=openai
LLM_MODEL=gpt-4o-mini # or gpt-4, gpt-3.5-turbo
LLM_API_KEY=sk-proj-your-openai-key
# Anthropic Configuration (template - implementation pending)
LLM_PROVIDER=anthropic
LLM_MODEL=claude-3-haiku-20240307 # or claude-3-sonnet-20240229
LLM_API_KEY=your-anthropic-key
# Local Model Configuration (template - implementation pending)
LLM_PROVIDER=local
LLM_MODEL=llama3.1
LLM_BASE_URL=http://localhost:11434The tool shows current configuration at startup:
🤖 Using openai (gpt-4o-mini) with temperature 0.1- Script Analysis: Detects dangerous commands
- Prompt Injection Protection: Prevents AI manipulation
- Path Validation: Ensures safe file access
- Input Sanitization: Cleans all user inputs
- Bash/Shell:
.shfiles with#!/bin/bash - Node.js:
.jsfiles (automatically usesnode:alpine) - Python:
.pyfiles (uses appropriate Python base) - Any Script: Generic support for any executable script
FROM bash:latest
COPY line_counter.sh /line_counter.sh
RUN chmod +x /line_counter.sh
ENTRYPOINT ["bash", "/line_counter.sh"]
CMD ["Hello\nWorld"]FROM node:alpine
COPY vowel_counter.js /vowel_counter.js
RUN chmod +x /vowel_counter.js
ENTRYPOINT ["node", "/vowel_counter.js"]
CMD ["Hello world"]"LLM configuration is invalid" or "API key not found"
# Set up generic configuration (recommended)
echo "LLM_API_KEY=your-api-key-here" >> .env
echo "LLM_PROVIDER=openai" >> .env
echo "LLM_MODEL=gpt-4o-mini" >> .env
# Or use legacy configuration
echo "OPENAI_API_KEY=your-key-here" >> .env"Unknown provider: anthropic"
# Anthropic is not fully implemented yet
# Use OpenAI provider instead
LLM_PROVIDER=openai npm start ./script.sh ./README.md"Docker command not found"
# Install Docker and ensure it's running
docker --version"Security scan failed"
# Use --force to bypass (not recommended)
npm start ./script.sh ./README.md --force"Module not found"
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install- Generic AI-Powered Tool: ✅ Works with any script type
- Dockerfile Generation: ✅ Smart, optimized containers
- Build & Test Pipeline: ✅ Fully automated workflow
- Output Verification: ✅ Ensures correctness
- Budget Optimization: ✅ Uses cost-effective GPT-4o-mini
- LLM Vendor-Agnostic: ✅ Extensible provider system
- Comprehensive Testing: ✅ Automated test suite
- Security Features: ✅ Input validation & prompt injection protection
- Production Ready: Clean, documented, maintainable code
- Developer Friendly: Clear usage examples and error messages
- Extensible: Easy to add new script types and providers
- Secure: Built-in protection against malicious inputs
This project demonstrates advanced AI-powered DevOps automation. The architecture is designed to be:
- Extensible: Easy to add new LLM providers
- Maintainable: Clean separation of concerns
- Testable: Comprehensive test coverage
- Secure: Built-in safety measures
The project is production-ready and successfully demonstrates how AI can automate script containerization while maintaining security, reliability, and cost-effectiveness.
Try it now:
npm start ./scripts/vowel_counter/vowel_counter.js ./scripts/vowel_counter/README.md