Skip to content

Codebase-2-DockerFile is a tool that automatically generates Dockerfiles from a given codebase using LLMs. It leverages code2prompt to analyze the codebase and provides a chat interface for iterative Dockerfile refinement.

License

Notifications You must be signed in to change notification settings

LikithMeruvu/Codebase-2-DockerFile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dockerfile Generator

License
Python
Streamlit
Gemini LLM
code2prompt

Generate a fully-functional Dockerfile from any codebase in just a few clicks! This project streamlines the entire containerization process by reading your project’s source files, analyzing them with code2prompt, and calling a Gemini LLM to produce a well-structured, minimal Dockerfile for your app.


Table of Contents


Features

  1. Zero Docker Knowledge Required
    Provide a codebase (as a ZIP), and instantly get a Dockerfile tailored to your project’s framework and dependencies.

  2. Automatic Language Detection
    Leverages code2prompt to detect your code’s language, frameworks, and libraries.

  3. Powered by Gemini LLM
    Integrates Google’s Gemini LLM for advanced natural-language instructions about how to structure your Dockerfile.

  4. Flexible Patterns
    Specify include and exclude patterns to control which files are part of the container build.

  5. Optional Template Support
    Pass a custom Handlebars/Jinja2 template for specialized Dockerfile layouts.

  6. Seamless UI
    Built with Streamlit, ensuring an intuitive, web-based interface for Dockerfile generation.


Tech Stack

  • Python 3.8+
  • Streamlit for the interactive web UI
  • code2prompt for scanning codebases
  • Gemini LLM API for intelligent Dockerfile generation
  • [OpenAI python-dotenv, requests, etc.] for environment management and additional AI capabilities

Architecture Overview

┌──────────────┐      ┌─────────────────────┐
│  User Upload  │ →→→ │    code2prompt      │ →→→  Summarized code
│  ZIP File     │      │(Analyze Codebase)   │
└──────────────┘      └─────────────────────┘
                            ↓
                     ┌─────────────────────┐
                     │    Gemini LLM       │
                     │(Generate Dockerfile)│
                     └─────────────────────┘
                            ↓
                     ┌─────────────────────┐
                     │  Streamlit UI       │
                     │(Display Dockerfile) │
                     └─────────────────────┘
  1. User uploads a ZIP of the codebase.
  2. code2prompt enumerates & summarizes all source files.
  3. Gemini LLM gets the summarization + user instructions to generate a Dockerfile.
  4. Streamlit displays the final Dockerfile in a user-friendly interface.

Installation

  1. Clone the Repository

    git clone https://github.com/your-username/dockerfile-generator.git
    cd dockerfile-generator
  2. Create & Activate a Virtual Environment

    python3 -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  3. Install Dependencies

    pip install -r requirements.txt
  4. Set Environment Variables
    Create a .env file (or otherwise set these in your environment):

    GEMINI_API_KEY=<YOUR_GEMINI_API_KEY>
    

Usage

  1. Start the Streamlit App
    streamlit run app.py
  2. Open in Your Browser
    By default, Streamlit runs at http://localhost:8501.
  3. Upload a ZIP
    Click “Browse files” to upload your project’s source code as a ZIP.
  4. (Optional) Enter Additional Instructions
    E.g., “Use Python 3.9 as the base image and install pip packages from requirements.txt.”
  5. Generate Dockerfile
    The tool runs code2prompt → calls Gemini LLM → returns your Dockerfile.
  6. Download Dockerfile
    Click the “Download Dockerfile” button to get it locally.

Configuration

Key Description Default
GEMINI_API_KEY Your Gemini LLM API key. (none)
include_patterns Comma-separated patterns to include (e.g. *.py) (none)
exclude_patterns Comma-separated patterns to exclude (e.g. *.md) (none)
template_path Path to a custom Dockerfile template (Handlebars/Jinja2). (none)

Put these in .env or set them as environment variables.


Example Workflow

  1. ZIP Your Project
    Suppose your Python Flask app is at ~/MyFlaskApp/.
    zip -r myapp.zip MyFlaskApp
  2. Launch
    streamlit run app.py
  3. Upload the myapp.zip file.
  4. Optionally specify includes like *.py or excludes like *.txt.
  5. Generate the Dockerfile, which might contain FROM python:3.9, COPY . ., RUN pip install ..., etc.


CLI Module: Dockerfile Generator

The CLI module allows you to generate Dockerfiles from a codebase using code2prompt and the Gemini model. It supports both local directories and GitHub repository URLs as input.


Installation

  1. Clone the repository:

    git clone https://github.com/your-repo/Codebase-2-DockerFile.git
    cd Codebase-2-DockerFile
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up environment variables: Create a .env file in the root directory and add your Gemini API key:

    GEMINI_API_KEY=your_gemini_api_key_here

Usage

Command-Line Interface (CLI)

The CLI tool can be used to generate Dockerfiles from a codebase. It supports the following arguments:

python cli.py <codebase_path> [options]

Arguments:

  • codebase_path: Path to the codebase (local directory or GitHub URL).
  • -i or --include: Include patterns (e.g., *.py,*.js).
  • -e or --exclude: Exclude patterns (e.g., *.txt,*.md).
  • -t or --template: Path to a custom code2prompt template.
  • -a or --instructions: Additional instructions for Dockerfile generation.
  • -o or --output: Output file name (default: Dockerfile).

Examples

Example 1: Generate Dockerfile from a GitHub Repository

python cli.py https://github.com/LikithMeruvu/Python-coding-Agent.git -a "Use Python 3.9" -o MyDockerfile

Example 2: Generate Dockerfile from a Local Directory

python cli.py ./my-codebase -i "*.py" -e "*.txt" -a "Use Python 3.8" -o MyDockerfile

Example 3: Generate Dockerfile with Custom Template

python cli.py https://github.com/LikithMeruvu/Python-coding-Agent.git -t ./custom_template.txt -o MyDockerfile

How It Works

  1. Clone or Use Local Codebase:

    • If a GitHub URL is provided, the repository is cloned to a temporary directory.
    • If a local directory is provided, it is used directly.
  2. Run code2prompt:

    • The code2prompt tool generates a prompt from the codebase based on the provided include/exclude patterns and template.
  3. Generate Dockerfile:

    • The prompt is sent to the Gemini model, which generates the Dockerfile content.
  4. Save Dockerfile:

    • The generated Dockerfile is saved to the specified output file.

Error Handling

  • If the codebase cannot be cloned or accessed, an error message is displayed.
  • If code2prompt fails to generate a prompt, the process stops, and an error is shown.
  • If the Gemini model fails to generate a Dockerfile, an error is displayed.

License

This project is licensed under the MIT License.
Feel free to use, modify, and distribute it as you see fit.

Give us a Star!
If you find this project helpful, please consider giving it a star on GitHub. It helps others discover this project too!

Happy containerizing!

About

Codebase-2-DockerFile is a tool that automatically generates Dockerfiles from a given codebase using LLMs. It leverages code2prompt to analyze the codebase and provides a chat interface for iterative Dockerfile refinement.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages