Skip to content

Commit 6edffd2

Browse files
authored
Merge pull request #2 from CtrlAltElite-Devs/ci/cd
Feat CI/CD
2 parents 8086799 + 7a26f5b commit 6edffd2

8 files changed

Lines changed: 4166 additions & 67 deletions

File tree

.github/workflows/ci.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
lint-and-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: astral-sh/setup-uv@v4
16+
with:
17+
version: "latest"
18+
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.11"
22+
23+
- name: Install dependencies
24+
run: uv sync
25+
26+
- name: Lint
27+
run: |
28+
uv run ruff check src/ tests/
29+
uv run ruff format --check src/ tests/
30+
31+
- name: Test
32+
run: uv run pytest tests/ -v
33+
34+
- name: Notify Discord on failure
35+
if: failure()
36+
uses: Ilshidur/action-discord@0.4.0
37+
env:
38+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }}
39+
DISCORD_USERNAME: "IShowSpeed"
40+
DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s"
41+
with:
42+
args: "SUUUUIII--- wait... 💀 ang lint/test sa Topic Worker ni ${{github.actor}} NAGUBA!!! Bro unsa ni?? Fix your code dawg 😭🔴"
43+
44+
- name: Notify Discord on success
45+
if: success()
46+
uses: Ilshidur/action-discord@0.4.0
47+
env:
48+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }}
49+
DISCORD_USERNAME: "IShowSpeed"
50+
DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s"
51+
with:
52+
args: "SUUUUUIIIIII ⚡ Topic Worker CI PASSED!!! si ${{github.actor}} kay goated fr fr 🐐✅ WWWWW chat WWWWW"

.github/workflows/deploy.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Deploy to RunPod
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/topic-worker
9+
10+
jobs:
11+
lint-and-test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: astral-sh/setup-uv@v4
17+
with:
18+
version: "latest"
19+
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.11"
23+
24+
- name: Install dependencies
25+
run: uv sync
26+
27+
- name: Lint
28+
run: |
29+
uv run ruff check src/ tests/
30+
uv run ruff format --check src/ tests/
31+
32+
- name: Test
33+
run: uv run pytest tests/ -v
34+
35+
build-and-push:
36+
needs: lint-and-test
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Notify Discord deployment started
40+
uses: Ilshidur/action-discord@0.4.0
41+
env:
42+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }}
43+
DISCORD_USERNAME: "IShowSpeed"
44+
DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s"
45+
with:
46+
args: "CHAT CHAT CHAT!!! 🏃💨 si ${{github.actor}} kay nag deploy sa Topic Worker to PRODUCTION!!! Hold on let me cook 🔥🔥🔥"
47+
48+
- uses: actions/checkout@v4
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v3
52+
53+
- name: Log in to Docker Hub
54+
uses: docker/login-action@v3
55+
with:
56+
username: ${{ secrets.DOCKERHUB_USERNAME }}
57+
password: ${{ secrets.DOCKERHUB_TOKEN }}
58+
59+
- name: Extract version from release tag
60+
id: version
61+
run: echo "tag=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
62+
63+
- name: Build and push
64+
uses: docker/build-push-action@v6
65+
with:
66+
context: .
67+
push: true
68+
platforms: linux/amd64
69+
tags: |
70+
${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }}
71+
${{ env.IMAGE_NAME }}:latest
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max
74+
75+
update-runpod:
76+
needs: build-and-push
77+
runs-on: ubuntu-latest
78+
steps:
79+
- name: Extract version from release tag
80+
id: version
81+
run: echo "tag=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
82+
83+
- name: Update RunPod template image
84+
run: |
85+
response=$(curl -s -w "\n%{http_code}" -X PATCH \
86+
"https://rest.runpod.io/v1/templates/${{ secrets.RUNPOD_TEMPLATE_ID }}" \
87+
-H "Authorization: Bearer ${{ secrets.RUNPOD_API_KEY }}" \
88+
-H "Content-Type: application/json" \
89+
-d "{\"imageName\": \"docker.io/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }}\"}")
90+
http_code=$(echo "$response" | tail -1)
91+
body=$(echo "$response" | head -n -1)
92+
echo "Response: $body"
93+
if [ "$http_code" -ge 400 ]; then
94+
echo "::error::Failed to update RunPod template (HTTP $http_code)"
95+
exit 1
96+
fi
97+
echo "Template updated to ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }}"
98+
99+
- name: Notify Discord deployment failed
100+
if: failure()
101+
uses: Ilshidur/action-discord@0.4.0
102+
env:
103+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }}
104+
DISCORD_USERNAME: "IShowSpeed"
105+
DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s"
106+
with:
107+
args: "Bro... 💀 ang Topic Worker deployment ni ${{github.actor}} FAILED!!! This is NOT speed chat, this is NOT speed 😭🔴"
108+
109+
- name: Notify Discord deployment succeeded
110+
if: success()
111+
uses: Ilshidur/action-discord@0.4.0
112+
env:
113+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }}
114+
DISCORD_USERNAME: "IShowSpeed"
115+
DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s"
116+
with:
117+
args: "WWWWWW Topic Worker deployed to Production!!! ⚡🚀 si ${{github.actor}} ikaw na jud dawg, SUUUUIIII ✅🐐"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM runpod/pytorch:2.2.0-py3.11-cuda12.1.1-devel-ubuntu22.04
1+
FROM runpod/pytorch:2.4.0-py3.11-cuda12.4.1-devel-ubuntu22.04
22

33
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
44

src/handler.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import logging
6-
from datetime import datetime, timezone
6+
from datetime import UTC, datetime
77

88
import numpy as np
99
import runpod
@@ -29,7 +29,7 @@ def _fail(error: str) -> dict:
2929
version=WORKER_VERSION,
3030
status="failed",
3131
error=error,
32-
completedAt=datetime.now(timezone.utc).isoformat(),
32+
completedAt=datetime.now(UTC).isoformat(),
3333
).model_dump()
3434

3535

@@ -97,9 +97,7 @@ def handler(event: dict) -> dict:
9797
outlier_count = sum(1 for t in model.topics_ if t == -1)
9898

9999
# Compute metrics
100-
metrics = compute_metrics(
101-
model, model.topics_, texts, embeddings, embed_model=embed_model
102-
)
100+
metrics = compute_metrics(model, model.topics_, texts, embeddings, embed_model=embed_model)
103101

104102
response = TopicModelResponse(
105103
version=WORKER_VERSION,
@@ -108,12 +106,12 @@ def handler(event: dict) -> dict:
108106
assignments=assignments,
109107
metrics=metrics,
110108
outlierCount=outlier_count,
111-
completedAt=datetime.now(timezone.utc).isoformat(),
109+
completedAt=datetime.now(UTC).isoformat(),
112110
)
113111

114112
return response.model_dump()
115113

116-
except Exception as e:
114+
except Exception:
117115
logger.exception("Unexpected error in handler")
118116
# Infrastructure error — let RunPod return error status → BullMQ will retry
119117
raise

src/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from pydantic import BaseModel, ConfigDict
77

8-
98
# --- Request ---
109

1110

0 commit comments

Comments
 (0)