$npx -y skills add MLOps-Courses/mlops-coding-skills --skill mlops-automationGuide to refine MLOps projects with task automation, containerization, CI/CD pipelines, and robust experiment tracking.
| 1 | # MLOps Automation |
| 2 | |
| 3 | ## Goal |
| 4 | |
| 5 | 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`). |
| 6 | |
| 7 | ## Prerequisites |
| 8 | |
| 9 | - **Language**: Python 3.14 |
| 10 | - **Manager**: `uv` |
| 11 | - **Context**: Preparing for scale and deployment. |
| 12 | |
| 13 | ## Instructions |
| 14 | |
| 15 | ### 1. Task Automation |
| 16 | |
| 17 | Expose a single, shared task vocabulary with `mise` (replaces `just`/`make`). |
| 18 | |
| 19 | 1. **Tool**: `mise` — pins the toolchain and defines tasks in `mise.toml`. |
| 20 | 1. **Vocabulary**: `install`, `format`, `check`, `test`, `build`, `watch`. Run everything via `mise run <task>` so hooks and CI reuse the same entrypoints. |
| 21 | 1. **Core Tasks**: |
| 22 | - `format`: Format code and config (`ruff format`, `dprint fmt`). |
| 23 | - `check`: Static checks (`ruff check`, `ty`, security rules). |
| 24 | - `test`: Run `pytest`. |
| 25 | - `build`: Build the wheel (`uv build`). |
| 26 | |
| 27 | ### 2. Git Hooks |
| 28 | |
| 29 | Catch issues locally with `lefthook` (replaces `pre-commit`). |
| 30 | |
| 31 | 1. **Framework**: `lefthook` with thin hooks — every command delegates to a `mise run` task so hooks and CI stay identical. |
| 32 | 1. **pre-commit**: Run `mise run format` then `mise run check`. |
| 33 | 1. **pre-push**: Run `mise run test`. |
| 34 | 1. **Security**: Prefer Ruff `S` rules (replaces `bandit`) plus `pip-audit`/`gitleaks` (see the Validation skill), not a separate scanner. |
| 35 | 1. **Commits**: Enforce **Conventional Commits** (e.g., `feat: add new model`) so `git-cliff` can generate the changelog. |
| 36 | |
| 37 | ### 3. Containerization |
| 38 | |
| 39 | Reproducibility anywhere. |
| 40 | |
| 41 | 1. **Tool**: `docker`. |
| 42 | 1. **Base Image**: Use `python:3.14-slim` for a minimal footprint; install `uv` in the build stage. |
| 43 | 1. **Optimization**: |
| 44 | - **Layer Caching**: Copy `uv.lock` + `pyproject.toml` and run `uv sync` *before* copying `src/`. |
| 45 | - **Multi-stage**: Build inputs in one stage, copy only artifacts (`dist/*.whl`) to the runtime stage. |
| 46 | 1. **Registry**: ask for the company artifact registry, or use `ghcr.io` for GitHub. |
| 47 | |
| 48 | ### 4. CI/CD Workflows |
| 49 | |
| 50 | Automate verification and release with GitHub Actions. |
| 51 | |
| 52 | 1. **Platform**: ask for the company CI/CD platform, or use `github-actions` for GitHub. |
| 53 | 1. **Toolchain**: Bootstrap every job with `actions/checkout@v7` + `jdx/mise-action@v4` so CI runs the exact same `mise run` tasks as local hooks. |
| 54 | 1. **Workflows**: |
| 55 | - `ci.yml`: On push/PR, run `mise run format`, `mise run check`, `mise run test`. |
| 56 | - `cd.yml`: On Release, build the image and publish docs via the official GitHub Pages Actions (`configure-pages`, `upload-pages-artifact`, `deploy-pages`). |
| 57 | 1. **Optimization**: Use `concurrency` to cancel redundant runs. |
| 58 | |
| 59 | ### 5. AI/ML Experiments & Registry |
| 60 | |
| 61 | Manage the ML lifecycle with **MLflow 3**. |
| 62 | |
| 63 | 1. **Platform**: `MLflow` (v3). |
| 64 | 1. **Tracking**: |
| 65 | - Use `mlflow.autolog()`; log metrics, params, and artifacts. |
| 66 | - The file store is deprecated — opt in for local runs with `MLFLOW_ALLOW_FILE_STORE=true`; use a real backend (SQL/HTTP) in production. |
| 67 | 1. **Models**: Log models with the keyword `name=` (e.g., `mlflow.pyfunc.log_model(name=...)`). |
| 68 | 1. **Validation**: Gate promotion with `mlflow.validate_evaluation_results` against explicit metric thresholds. |
| 69 | 1. **Registry**: |
| 70 | - Register top models manually or via CI. |
| 71 | - **Aliases**: Use `@champion` or `@production` for stable deployment pointers. Never rely on moving versions (e.g., `v1` -> `v2`). |
| 72 | |
| 73 | ### 6. Design Patterns |
| 74 | |
| 75 | Write flexible code. |
| 76 | |
| 77 | 1. **Strategy**: For swappable algorithms (e.g., different model types). |
| 78 | 1. **Factory**: For creating objects from config (e.g., `ModelFactory`). |
| 79 | 1. **Adapter**: For standardizing mismatched interfaces. |
| 80 | |
| 81 | ## Self-Correction Checklist |
| 82 | |
| 83 | - [ ] **Task Vocabulary**: Does `mise run check` (and `format`/`test`/`build`) work? |
| 84 | - [ ] **Hooks**: Do `lefthook` hooks delegate to `mise run` tasks? |
| 85 | - [ ] **Image**: Is the Dockerfile multi-stage on `python:3.14-slim`? |
| 86 | - [ ] **CI/CD**: Do `ci.yml`/`cd.yml` bootstrap with `jdx/mise-action@v4`? |
| 87 | - [ ] **Tracking**: Are runs logged to MLflow with validated thresholds? |