Metadata-Version: 2.4
Name: docktor-py
Version: 0.1.1
Summary: A smart Dockerfile linter, optimizer, and explainer.
Author-email: Nash Correia <nashco9900@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Nash Correia
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/Nash0810/docktor
Project-URL: Bug Tracker, https://github.com/Nash0810/docktor/issues
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.1.0
Requires-Dist: rich>=13.0.0
Requires-Dist: chardet>=5.0.0
Requires-Dist: docker>=6.0.0
Requires-Dist: pypiwin32>=223; sys_platform == "win32"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

<!-- Project Title -->
<h1 align="center">🐳 Docktor</h1>
<p align="center">
  <strong>A Smart Dockerfile Linter & Optimizer</strong><br>
  Build smaller, faster, and more secure Docker images with ease.
</p>

<!-- Badges -->
<p align="center">
  <a href="https://pypi.org/project/docktor/"><img src="https://img.shields.io/pypi/v/docktor.svg" alt="PyPI version"></a>
  <a href="https://github.com/Nash0810/docktor/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
  <a href="https://github.com/Nash0810/docktor/actions"><img src="https://github.com/Nash0810/docktor/workflows/CI/badge.svg" alt="Build Status"></a>
  <a href="https://pypi.org/project/docktor/"><img src="https://img.shields.io/pypi/pyversions/docktor" alt="Python Versions"></a>
</p>

## ✨ Features

- **Comprehensive Linter** – Checks against 20+ rules for performance, security, and best practices.
- **Intelligent Optimizer** – Combines `RUN` commands, cleans up apt-get cache, replaces `ADD` with `COPY`, etc.
- **Educational Explanations** – Understand _why_ a suggestion is made.
- **Empirical Benchmarking** – See image size, build time, and layer count improvements.
- **CI/CD Friendly** – Output in human-readable tables (Rich) or machine-readable JSON.

## 🚀 Quick Start

### Installation

Requires Python **3.8+** and Docker.

```bash
pip install docktor-py
```

### Usage

#### 1. Lint a Dockerfile

```bash
docktor lint Dockerfile
```

#### 2. See Detailed Explanations

```bash
docktor lint Dockerfile --explain
```

#### 3. Automatically Optimize

```bash
# Pretty summary
docktor optimize Dockerfile

# Copy-pasteable output
docktor optimize Dockerfile --raw

# Save optimized file
docktor optimize Dockerfile --raw > Dockerfile.optimized
```

#### 4. Benchmark Your Changes

```bash
docktor benchmark Dockerfile Dockerfile.optimized
```

## ⚙️ Implemented Rules

| Rule ID | Description                                    | Category      | Auto-Optimized?    |
| ------- | ---------------------------------------------- | ------------- | ------------------ |
| BP001   | FROM uses `:latest` or no tag                  | Best Practice | Yes (for untagged) |
| BP002   | EXPOSE is present without HEALTHCHECK          | Best Practice | No                 |
| BP003   | EXPOSE is missing `/tcp` or `/udp` protocol    | Best Practice | Yes                |
| BP004   | LABEL instruction for metadata is missing      | Best Practice | No                 |
| BP005   | RUN command is used in a scratch image         | Best Practice | No (error)         |
| BP006   | COPY --from refers to a non-existent stage     | Best Practice | No (error)         |
| BP007   | CMD/ENTRYPOINT uses shell form                 | Best Practice | No                 |
| BP008   | WORKDIR path is not absolute                   | Best Practice | No                 |
| BP009   | apt-get install is missing apt-get update      | Best Practice | ye(error)          |
| PERF001 | Consecutive RUN commands can be merged         | Performance   | Yes                |
| PERF002 | apt-get install is missing cache cleanup       | Performance   | Yes                |
| PERF003 | Broad COPY is used before dependency install   | Performance   | No                 |
| PERF004 | Build-time packages (git, gcc) are installed   | Performance   | No                 |
| PERF005 | Unsafe apt-get upgrade command is used         | Performance   | No                 |
| PERF006 | Broad `COPY . .` pattern is used               | Performance   | No                 |
| PERF007 | Redundant apt-get update command is used       | Performance   | No                 |
| SEC001  | ADD is used instead of COPY                    | Security      | Yes                |
| SEC002  | Container runs as the root user                | Security      | No                 |
| SEC003  | Potential secrets are in ENV variables         | Security      | No                 |
| SEC004  | COPY is used without --chown for non-root user | Security      | No                 |

## 🤝 Contributing

Contributions, issues, and feature requests are welcome!
Check out the [issues page](https://github.com/Nash0810/docktor/issues) to get started.

## 📄 License

This project is licensed under the [MIT License](LICENSE).
