| name | mlops-automation |
| description | Guide to refine MLOps projects with task automation, containerization, CI/CD pipelines, and robust experiment tracking. |
MLOps Automation
Goal
To elevate the codebase to production standards by adding Task Automation (mise), Git Hooks (lefthook), Containerization (docker), CI/CD (github-actions), and Experiment Tracking (mlflow).
Prerequisites
- Language: Python 3.14
- Manager:
uv
- Context: Preparing for scale and deployment.
Instructions
1. Task Automation
Expose a single, shared task vocabulary with mise (replaces just/make).
- Tool:
mise — pins the toolchain and defines tasks in mise.toml.
- Vocabulary:
install, format, check, test, build, watch. Run everything via mise run <task> so hooks and CI reuse the same entrypoints.
- Core Tasks:
format: Format code and config (ruff format, dprint fmt).
check: Static checks (ruff check, ty, security rules).
test: Run pytest.
build: Build the wheel (uv build).
2. Git Hooks
Catch issues locally with lefthook (replaces pre-commit).
- Framework:
lefthook with thin hooks — every command delegates to a mise run task so hooks and CI stay identical.
- pre-commit: Run
mise run format then mise run check.
- pre-push: Run
mise run test.
- Security: Prefer Ruff
S rules (replaces bandit) plus pip-audit/gitleaks (see the Validation skill), not a separate scanner.
- Commits: Enforce Conventional Commits (e.g.,
feat: add new model) so git-cliff can generate the changelog.
3. Containerization
Reproducibility anywhere.
- Tool:
docker.
- Base Image: Use
python:3.14-slim for a minimal footprint; install uv in the build stage.
- Optimization:
- Layer Caching: Copy
uv.lock + pyproject.toml and run uv sync before copying src/.
- Multi-stage: Build inputs in one stage, copy only artifacts (
dist/*.whl) to the runtime stage.
- Registry: ask for the company artifact registry, or use
ghcr.io for GitHub.
4. CI/CD Workflows
Automate verification and release with GitHub Actions.
- Platform: ask for the company CI/CD platform, or use
github-actions for GitHub.
- Toolchain: Bootstrap every job with
actions/checkout@v7 + jdx/mise-action@v4 so CI runs the exact same mise run tasks as local hooks.
- Workflows:
ci.yml: On push/PR, run mise run format, mise run check, mise run test.
cd.yml: On Release, build the image and publish docs via the official GitHub Pages Actions (configure-pages, upload-pages-artifact, deploy-pages).
- Optimization: Use
concurrency to cancel redundant runs.
5. AI/ML Experiments & Registry
Manage the ML lifecycle with MLflow 3.
- Platform:
MLflow (v3).
- Tracking:
- Use
mlflow.autolog(); log metrics, params, and artifacts.
- The file store is deprecated — opt in for local runs with
MLFLOW_ALLOW_FILE_STORE=true; use a real backend (SQL/HTTP) in production.
- Models: Log models with the keyword
name= (e.g., mlflow.pyfunc.log_model(name=...)).
- Validation: Gate promotion with
mlflow.validate_evaluation_results against explicit metric thresholds.
- Registry:
- Register top models manually or via CI.
- Aliases: Use
@champion or @production for stable deployment pointers. Never rely on moving versions (e.g., v1 -> v2).
6. Design Patterns
Write flexible code.
- Strategy: For swappable algorithms (e.g., different model types).
- Factory: For creating objects from config (e.g.,
ModelFactory).
- Adapter: For standardizing mismatched interfaces.
Self-Correction Checklist