Skip to content

Commit c922f8a

Browse files
committed
feat: Implement GitHub Actions workflow for AI service deployment to Cloud Run and add CI/CD setup documentation.
1 parent 4c3651b commit c922f8a

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Deploy AI Service to Cloud Run
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "ai_service/**"
9+
- ".github/workflows/deploy.yml"
10+
11+
env:
12+
PROJECT_ID: lucky-union-472503-c7 # TODO: Update if different
13+
REGION: asia-southeast1
14+
SERVICE_NAME: ai-service
15+
WORK_DIR: ai_service
16+
17+
jobs:
18+
deploy:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: "read"
22+
id-token: "write"
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
# Authenticate via Service Account Key JSON
29+
# (Simpler for this setup than Workload Identity Federation)
30+
- id: "auth"
31+
uses: "google-github-actions/auth@v2"
32+
with:
33+
credentials_json: "${{ secrets.GCP_SA_KEY }}"
34+
35+
- name: "Set up Cloud SDK"
36+
uses: "google-github-actions/setup-gcloud@v2"
37+
38+
- name: "Deploy to Cloud Run"
39+
uses: "google-github-actions/deploy-cloudrun@v2"
40+
with:
41+
service: "${{ env.SERVICE_NAME }}"
42+
region: "${{ env.REGION }}"
43+
source: "${{ env.WORK_DIR }}"
44+
flags: "--allow-unauthenticated --port 8000"
45+
env_vars: |
46+
NEO4J_URI=${{ secrets.NEO4J_URI }}
47+
NEO4J_USER=${{ secrets.NEO4J_USER }}
48+
NEO4J_PASSWORD=${{ secrets.NEO4J_PASSWORD }}
49+
GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}
50+
TAVILY_API_KEY=${{ secrets.TAVILY_API_KEY }}
51+
CYPHER_MODEL=gpt-4o-mini
52+
QA_MODEL=gpt-4o-mini
53+
CYPHER_TEMPERATURE=0.0
54+
QA_TEMPERATURE=0.0

CI_CD_SETUP.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Hướng dẫn Cấu hình CI/CD với GitHub Actions
2+
3+
Để GitHub tự động deploy code lên Google Cloud Run mỗi khi bạn push vào nhánh `main`, bạn cần thiết lập **Secrets** trong GitHub Repository.
4+
5+
## 1. Tạo Service Account trên Google Cloud
6+
7+
GitHub cần một "tài khoản robot" (Service Account) để có quyền deploy thay bạn.
8+
9+
1. Truy cập [Google Cloud Console > IAM & Admin > Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts).
10+
2. Chọn project `lucky-union-472503-c7`.
11+
3. Nhấn **+ CREATE SERVICE ACCOUNT**.
12+
- **Name**: `github-actions-deployer`
13+
- Nhấn **Create and Continue**.
14+
4. **Cấp quyền (Roles)**:
15+
Thêm các role sau cho Service Account này:
16+
- `Cloud Run Admin` (để quản lý Cloud Run)
17+
- `Service Account User` (để chạy service dưới quyền mặc định)
18+
- `Artifact Registry Writer` (để push Docker image)
19+
- `Storage Admin` (để upload source code nếu cần)
20+
- Nhấn **Done**.
21+
5. **Tạo Key JSON**:
22+
- Bấm vào Service Account vừa tạo (email).
23+
- Vào tab **KEYS** > **ADD KEY** > **Create new key**.
24+
- Chọn **JSON** > **Create**.
25+
- Một file `.json` sẽ được tải về máy. **Giữ bí mật file này!**
26+
27+
## 2. Thêm Secrets vào GitHub
28+
29+
1. Vào GitHub Repository của bạn.
30+
2. Chọn **Settings** > **Secrets and variables** > **Actions**.
31+
3. Nhấn **New repository secret**.
32+
4. Thêm lần lượt các secret sau:
33+
34+
| Tên Secret | Giá trị (Lấy từ đâu?) |
35+
| :--------------- | :---------------------------------------------------------- |
36+
| `GCP_SA_KEY` | **Toàn bộ nội dung** của file JSON bạn vừa tải về ở bước 1. |
37+
| `NEO4J_URI` | Giá trị `NEO4J_URI` trong file `.env` của bạn. |
38+
| `NEO4J_USER` | Giá trị `NEO4J_USER` trong file `.env` của bạn. |
39+
| `NEO4J_PASSWORD` | Giá trị `NEO4J_PASSWORD` trong file `.env` của bạn. |
40+
| `GEMINI_API_KEY` | Giá trị `GEMINI_API_KEY` trong file `.env` của bạn. |
41+
| `TAVILY_API_KEY` | Giá trị `TAVILY_API_KEY` trong file `.env` của bạn. |
42+
43+
## 3. Kích hoạt Workflow
44+
45+
Sau khi đã thêm đủ Secrets:
46+
47+
1. Commit và Push file `.github/workflows/deploy.yml` lên nhánh `main`.
48+
2. Vào tab **Actions** trên GitHub để xem quá trình deploy đang chạy.
49+
50+
---
51+
52+
**Lưu ý:**
53+
54+
- Workflow này chỉ chạy khi có thay đổi trong thư mục `ai_service`.
55+
- Nếu bạn thay đổi biến môi trường, hãy nhớ cập nhật lại trong GitHub Secrets.

0 commit comments

Comments
 (0)