78 lines
2.2 KiB
YAML
78 lines
2.2 KiB
YAML
name: Train & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- "src/**"
|
|
- "configs/**"
|
|
- "dvc.yaml"
|
|
|
|
jobs:
|
|
train:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.10"
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
pip install -r requirements.txt
|
|
pip install dvc
|
|
|
|
- name: Pull data from DVC
|
|
run: dvc pull || echo "No DVC data to pull, skipping"
|
|
|
|
- name: Train model
|
|
run: python src/train.py
|
|
|
|
- name: Track model with DVC
|
|
run: |
|
|
dvc add models/ || echo "DVC tracking skipped"
|
|
dvc push || echo "DVC push skipped"
|
|
|
|
- name: Commit DVC metadata
|
|
run: |
|
|
git config user.name "gitea-runner"
|
|
git config user.email "runner@mlops"
|
|
git add models/*.dvc models/.gitignore 2>/dev/null || true
|
|
git diff --cached --quiet || git commit -m "Update model - $(date +%Y%m%d-%H%M%S)"
|
|
git push || echo "Nothing to push"
|
|
|
|
build-and-deploy:
|
|
needs: train
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
REGISTRY_URL: harbor.inje-private.com
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: main
|
|
|
|
- name: Login to Harbor
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login $REGISTRY_URL -u ${{ secrets.REGISTRY_USER }} --password-stdin
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
IMAGE_TAG="${{ github.sha }}"
|
|
docker build -t $REGISTRY_URL/mlops/mlops-serving:${IMAGE_TAG} .
|
|
docker push $REGISTRY_URL/mlops/mlops-serving:${IMAGE_TAG}
|
|
|
|
- name: Update manifest
|
|
run: |
|
|
IMAGE_TAG="${{ github.sha }}"
|
|
sed -i "s|image:.*mlops-serving.*|image: $REGISTRY_URL/mlops/mlops-serving:${IMAGE_TAG}|" manifests/deployment.yaml
|
|
git config user.name "gitea-runner"
|
|
git config user.email "runner@mlops"
|
|
git add manifests/
|
|
git commit -m "Deploy model ${IMAGE_TAG:0:7}"
|
|
git push
|
|
# ↑ manifests/ 변경 → ArgoCD가 자동 감지 → soo ns에 배포
|