| | --- |
| | language: "code" |
| | license: "mit" |
| | tags: |
| | - dockerfile |
| | - hadolint |
| | - binary-classification |
| | - codebert |
| | model-index: |
| | - name: Binary Dockerfile Classifier |
| | results: [] |
| | --- |
| | |
| |
|
| | # π§± Dockerfile Quality Classifier β Binary Model |
| |
|
| | This model predicts whether a given Dockerfile is: |
| |
|
| | - β
**GOOD** β clean and adheres to best practices (no top rule violations) |
| | - β **BAD** β violates at least one important rule (from Hadolint) |
| |
|
| | It is the first step in a full ML-based Dockerfile linter. |
| |
|
| | --- |
| |
|
| | ## π§ Model Overview |
| |
|
| | - **Architecture:** Fine-tuned `microsoft/codebert-base` |
| | - **Task:** Binary classification (`good` vs `bad`) |
| | - **Input:** Full Dockerfile content as plain text |
| | - **Output:** `[prob_good, prob_bad]` β softmax scores |
| | - **Max input length:** 512 tokens |
| |
|
| | --- |
| |
|
| | ## π Training Details |
| |
|
| | - **Data source:** Real-world and synthetic Dockerfiles |
| | - **Labels:** Based on [Hadolint](https://github.com/hadolint/hadolint) top 30 rules |
| | - **Bad examples:** At least one rule violated |
| | - **Good examples:** Fully clean files |
| | - **Dataset balance:** 15000 BAD / 1500 GOOD (clean) |
| |
|
| | --- |
| |
|
| | ## π§ͺ Evaluation Results |
| |
|
| | Evaluation on a held-out test set of 1,650 Dockerfiles: |
| |
|
| | | Class | Precision | Recall | F1-score | Support | |
| | |-------|-----------|--------|----------|---------| |
| | | good | 0.96 | 0.91 | 0.93 | 150 | |
| | | bad | 0.99 | 1.00 | 0.99 | 1500 | |
| | | **Accuracy** | | | **0.99** | 1650 | |
| |
|
| | --- |
| |
|
| | ## π Quick Start |
| |
|
| | ### π§ͺ Step 1 β Create test script |
| |
|
| | Save this as `test_binary_predict.py`: |
| |
|
| | ```python |
| | import sys |
| | from transformers import AutoTokenizer, AutoModelForSequenceClassification |
| | import torch |
| | from pathlib import Path |
| | |
| | path = Path(sys.argv[1]) |
| | text = path.read_text(encoding="utf-8") |
| | |
| | tokenizer = AutoTokenizer.from_pretrained("LeeSek/binary-dockerfile-model") |
| | model = AutoModelForSequenceClassification.from_pretrained("LeeSek/binary-dockerfile-model") |
| | model.eval() |
| | |
| | inputs = tokenizer(text, return_tensors="pt", padding="max_length", truncation=True, max_length=512) |
| | |
| | with torch.no_grad(): |
| | logits = model(**inputs).logits |
| | probs = torch.nn.functional.softmax(logits, dim=1).squeeze() |
| | |
| | label = "GOOD" if torch.argmax(probs).item() == 0 else "BAD" |
| | print(f"Prediction: {label} β Probabilities: good={probs[0]:.3f}, bad={probs[1]:.3f}") |
| | ``` |
| |
|
| | --- |
| |
|
| | ### π Step 2 β Create good and bad Dockerfile |
| |
|
| | Good: |
| |
|
| | ```docker |
| | FROM node:18 |
| | WORKDIR /app |
| | COPY . . |
| | RUN npm install |
| | CMD ["node", "index.js"] |
| | ``` |
| |
|
| | Bad: |
| |
|
| | ```docker |
| | FROM ubuntu:latest |
| | RUN apt-get install python3 |
| | ADD . /app |
| | WORKDIR /app |
| | RUN pip install flask |
| | CMD python3 app.py |
| | ``` |
| |
|
| | --- |
| |
|
| | ### βΆοΈ Step 3 β Run the prediction |
| |
|
| | ```bash |
| | python test_binary_predict.py Dockerfile |
| | ``` |
| |
|
| | Expected output: |
| |
|
| | ``` |
| | Prediction: GOOD β Probabilities: good=0.998, bad=0.002 |
| | ``` |
| |
|
| | --- |
| |
|
| | ## π Extras |
| |
|
| | The full training and evaluation pipeline β including data preparation, training, validation, prediction β is available in the **`scripts/`** folder. |
| |
|
| | > π¬ **Note:** Scripts are written with **Polish comments and variable names** for clarity during local development. Logic is fully portable. |
| |
|
| | --- |
| |
|
| | ## π License |
| |
|
| | MIT |
| |
|
| | --- |
| |
|
| | ## π Credits |
| |
|
| | - Model powered by [Hugging Face Transformers](https://huggingface.co/transformers) |
| | - Tokenizer: CodeBERT |
| | - Rule definitions: [Hadolint](https://github.com/hadolint/hadolint) |
| |
|