Spaces:
Running
Running
Docker image Build and deploy to HF Spaces Via CI/CD Steps
Browse files- .github/workflows/README.md +58 -0
- .github/workflows/ci.yaml +35 -0
- .github/workflows/deploy-hf-space.yaml +33 -0
- .github/workflows/docker-build.yaml +47 -0
- HF_SPACE_README.md +43 -0
.github/workflows/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CI/CD Workflows
|
| 2 |
+
|
| 3 |
+
Automated pipelines using GitHub Actions.
|
| 4 |
+
|
| 5 |
+
## Workflows
|
| 6 |
+
|
| 7 |
+
### 1. CI Pipeline (`ci.yaml`)
|
| 8 |
+
**Triggers**: Push to main, Pull Requests
|
| 9 |
+
**Actions**:
|
| 10 |
+
- Lint code with flake8
|
| 11 |
+
- Format check with black
|
| 12 |
+
- Validate dependencies
|
| 13 |
+
|
| 14 |
+
### 2. Docker Build (`docker-build.yaml`)
|
| 15 |
+
**Triggers**: Push to main, Version tags
|
| 16 |
+
**Actions**:
|
| 17 |
+
- Build Docker image
|
| 18 |
+
- Push to GitHub Container Registry (ghcr.io)
|
| 19 |
+
- Tag with SHA and latest
|
| 20 |
+
|
| 21 |
+
**Access image**:
|
| 22 |
+
```bash
|
| 23 |
+
docker pull ghcr.io/your-username/automl-mlops-pipeline:latest
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
### 3. HuggingFace Deploy (`deploy-hf-space.yaml`)
|
| 27 |
+
**Triggers**: Version tags, Manual dispatch
|
| 28 |
+
**Actions**:
|
| 29 |
+
- Push code to HuggingFace Space
|
| 30 |
+
- Auto-deploy live demo
|
| 31 |
+
|
| 32 |
+
## Setup
|
| 33 |
+
|
| 34 |
+
### Required Secrets
|
| 35 |
+
|
| 36 |
+
Add these in GitHub Settings β Secrets:
|
| 37 |
+
|
| 38 |
+
1. **For Docker Build**: None (uses `GITHUB_TOKEN` automatically)
|
| 39 |
+
|
| 40 |
+
2. **For HuggingFace Deploy**:
|
| 41 |
+
- `HF_TOKEN`: Your HuggingFace access token
|
| 42 |
+
- `HF_SPACE_NAME`: Your space name (e.g., `username/automl-demo`)
|
| 43 |
+
|
| 44 |
+
### Get HuggingFace Token
|
| 45 |
+
1. Go to https://huggingface.co/settings/tokens
|
| 46 |
+
2. Create "Write" access token
|
| 47 |
+
3. Add as `HF_TOKEN` secret in GitHub
|
| 48 |
+
|
| 49 |
+
## Manual Triggers
|
| 50 |
+
|
| 51 |
+
Trigger HuggingFace deployment manually:
|
| 52 |
+
```
|
| 53 |
+
Actions tab β Deploy to HuggingFace Space β Run workflow
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
## View Container Images
|
| 57 |
+
|
| 58 |
+
Visit: https://github.com/your-username/automl-mlops-pipeline/pkgs/container/automl-mlops-pipeline
|
.github/workflows/ci.yaml
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: CI Pipeline
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches: [ main ]
|
| 6 |
+
pull_request:
|
| 7 |
+
branches: [ main ]
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
lint:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v3
|
| 14 |
+
|
| 15 |
+
- name: Set up Python
|
| 16 |
+
uses: actions/setup-python@v4
|
| 17 |
+
with:
|
| 18 |
+
python-version: '3.11'
|
| 19 |
+
|
| 20 |
+
- name: Install dependencies
|
| 21 |
+
run: |
|
| 22 |
+
pip install flake8 black
|
| 23 |
+
|
| 24 |
+
- name: Lint with flake8
|
| 25 |
+
run: |
|
| 26 |
+
flake8 src/ app/ --count --select=E9,F63,F7,F82 --show-source --statistics
|
| 27 |
+
flake8 src/ app/ --count --max-line-length=120 --statistics --exit-zero
|
| 28 |
+
|
| 29 |
+
- name: Check formatting with black
|
| 30 |
+
run: |
|
| 31 |
+
black --check src/ app/ --line-length=120 || true
|
| 32 |
+
|
| 33 |
+
- name: Validate requirements
|
| 34 |
+
run: |
|
| 35 |
+
pip install -r requirements.txt --dry-run
|
.github/workflows/deploy-hf-space.yaml
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Deploy to HuggingFace Space
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
tags:
|
| 6 |
+
- 'v*'
|
| 7 |
+
workflow_dispatch:
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
deploy:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v3
|
| 14 |
+
with:
|
| 15 |
+
fetch-depth: 0
|
| 16 |
+
lfs: true
|
| 17 |
+
|
| 18 |
+
- name: Push to HuggingFace Space
|
| 19 |
+
env:
|
| 20 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 21 |
+
run: |
|
| 22 |
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
| 23 |
+
git config --global user.name "github-actions[bot]"
|
| 24 |
+
|
| 25 |
+
# Add HuggingFace remote if not exists
|
| 26 |
+
git remote add hf https://huggingface.co/spaces/${{ secrets.HF_SPACE_NAME }} || true
|
| 27 |
+
|
| 28 |
+
# Push to HuggingFace
|
| 29 |
+
git push https://user:$HF_TOKEN@huggingface.co/spaces/${{ secrets.HF_SPACE_NAME }} main:main
|
| 30 |
+
|
| 31 |
+
- name: Deployment Status
|
| 32 |
+
run: |
|
| 33 |
+
echo "β
Deployed to: https://huggingface.co/spaces/${{ secrets.HF_SPACE_NAME }}"
|
.github/workflows/docker-build.yaml
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Docker Build
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches: [ main ]
|
| 6 |
+
tags:
|
| 7 |
+
- 'v*'
|
| 8 |
+
|
| 9 |
+
env:
|
| 10 |
+
REGISTRY: ghcr.io
|
| 11 |
+
IMAGE_NAME: ${{ github.repository }}
|
| 12 |
+
|
| 13 |
+
jobs:
|
| 14 |
+
build:
|
| 15 |
+
runs-on: ubuntu-latest
|
| 16 |
+
permissions:
|
| 17 |
+
contents: read
|
| 18 |
+
packages: write
|
| 19 |
+
|
| 20 |
+
steps:
|
| 21 |
+
- uses: actions/checkout@v3
|
| 22 |
+
|
| 23 |
+
- name: Log in to Container Registry
|
| 24 |
+
uses: docker/login-action@v2
|
| 25 |
+
with:
|
| 26 |
+
registry: ${{ env.REGISTRY }}
|
| 27 |
+
username: ${{ github.actor }}
|
| 28 |
+
password: ${{ secrets.GITHUB_TOKEN }}
|
| 29 |
+
|
| 30 |
+
- name: Extract metadata
|
| 31 |
+
id: meta
|
| 32 |
+
uses: docker/metadata-action@v4
|
| 33 |
+
with:
|
| 34 |
+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
| 35 |
+
tags: |
|
| 36 |
+
type=sha,prefix={{branch}}-
|
| 37 |
+
type=ref,event=branch
|
| 38 |
+
type=ref,event=tag
|
| 39 |
+
type=raw,value=latest,enable={{is_default_branch}}
|
| 40 |
+
|
| 41 |
+
- name: Build and push
|
| 42 |
+
uses: docker/build-push-action@v4
|
| 43 |
+
with:
|
| 44 |
+
context: .
|
| 45 |
+
push: true
|
| 46 |
+
tags: ${{ steps.meta.outputs.tags }}
|
| 47 |
+
labels: ${{ steps.meta.outputs.labels }}
|
HF_SPACE_README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: AutoML MLOps Pipeline
|
| 3 |
+
emoji: π€
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 8000
|
| 8 |
+
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# AutoML MLOps Pipeline
|
| 13 |
+
|
| 14 |
+
Production-ready AutoML pipeline with MLflow tracking, monitoring, and orchestration.
|
| 15 |
+
|
| 16 |
+
## Features
|
| 17 |
+
|
| 18 |
+
- π€ **AutoML**: AutoGluon, FLAML, PyCaret
|
| 19 |
+
- π **MLflow Tracking**: DagsHub integration
|
| 20 |
+
- π **Monitoring**: Drift detection, performance tracking
|
| 21 |
+
- π **Observability**: Prometheus & Grafana
|
| 22 |
+
- π **Orchestration**: Airflow scheduling
|
| 23 |
+
- π³ **Docker**: Containerized deployment
|
| 24 |
+
|
| 25 |
+
## API Endpoints
|
| 26 |
+
|
| 27 |
+
Once deployed, access:
|
| 28 |
+
- **API Documentation**: `/docs`
|
| 29 |
+
- **Health Check**: `/health`
|
| 30 |
+
- **Predictions**: `/predict`
|
| 31 |
+
- **Monitoring**: `/monitoring/metrics`
|
| 32 |
+
|
| 33 |
+
## Quick Test
|
| 34 |
+
|
| 35 |
+
```bash
|
| 36 |
+
curl -X POST https://abeshith-automl-mlops-pipeline.hf.space/predict \
|
| 37 |
+
-H "Content-Type: application/json" \
|
| 38 |
+
-d '{"age": 45, "sex": 1, "cp": 2, "trestbps": 130, "chol": 250, "fbs": 0, "restecg": 1, "thalach": 150, "exang": 0, "oldpeak": 2.5, "slope": 2, "ca": 0, "thal": 2}'
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
## Repository
|
| 42 |
+
|
| 43 |
+
Full source code: [GitHub](https://github.com/Abeshith/AutoML-MLOps-PipeLine)
|