Initial commit with 2026 World Cup Quant Platform core modules and CI/CD
This commit is contained in:
118
.github/workflows/deploy-production.yml
vendored
Normal file
118
.github/workflows/deploy-production.yml
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
name: deploy-2026fifa-platform
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
test-and-build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 取回原始碼
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 設定 Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
|
||||
- name: 安裝前端套件
|
||||
working-directory: platform/web
|
||||
run: npm install
|
||||
|
||||
- name: 前端 Lint
|
||||
working-directory: platform/web
|
||||
run: npm run lint
|
||||
|
||||
- name: 前端建置檢查
|
||||
working-directory: platform/web
|
||||
run: npm run build
|
||||
|
||||
- name: 設定 Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: 安裝後端與警報套件
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r platform/backend/requirements.txt
|
||||
pip install -r platform/alerts/requirements.txt
|
||||
|
||||
- name: 編譯 Python 程式碼
|
||||
run: |
|
||||
python -m compileall platform/backend/app
|
||||
python -m compileall platform/alerts
|
||||
|
||||
build-and-push:
|
||||
needs: test-and-build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: 取回原始碼
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 登入容器倉庫
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build 並推送前端映像
|
||||
run: |
|
||||
docker build -t ghcr.io/${{ github.repository_owner }}/2026fifa-web:${{ github.sha }} platform/web
|
||||
docker tag ghcr.io/${{ github.repository_owner }}/2026fifa-web:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/2026fifa-web:latest
|
||||
docker push ghcr.io/${{ github.repository_owner }}/2026fifa-web:${{ github.sha }}
|
||||
docker push ghcr.io/${{ github.repository_owner }}/2026fifa-web:latest
|
||||
|
||||
- name: Build 並推送後端映像
|
||||
run: |
|
||||
docker build -t ghcr.io/${{ github.repository_owner }}/2026fifa-backend:${{ github.sha }} platform/backend
|
||||
docker tag ghcr.io/${{ github.repository_owner }}/2026fifa-backend:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/2026fifa-backend:latest
|
||||
docker push ghcr.io/${{ github.repository_owner }}/2026fifa-backend:${{ github.sha }}
|
||||
docker push ghcr.io/${{ github.repository_owner }}/2026fifa-backend:latest
|
||||
|
||||
- name: Build 並推送警報服務映像
|
||||
run: |
|
||||
docker build -t ghcr.io/${{ github.repository_owner }}/2026fifa-alerts:${{ github.sha }} platform/alerts
|
||||
docker tag ghcr.io/${{ github.repository_owner }}/2026fifa-alerts:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/2026fifa-alerts:latest
|
||||
docker push ghcr.io/${{ github.repository_owner }}/2026fifa-alerts:${{ github.sha }}
|
||||
docker push ghcr.io/${{ github.repository_owner }}/2026fifa-alerts:latest
|
||||
|
||||
deploy:
|
||||
needs: build-and-push
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 取回原始碼
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 安裝 kubectl
|
||||
uses: azure/setup-kubectl@v4
|
||||
with:
|
||||
version: 'v1.30.0'
|
||||
|
||||
- name: 建立 KubeConfig
|
||||
run: |
|
||||
mkdir -p ~/.kube
|
||||
echo "${{ secrets.K3S_KUBECONFIG }}" > ~/.kube/config
|
||||
|
||||
- name: 替換映像版本
|
||||
run: |
|
||||
sed -i "s#ghcr.io/your-org/2026fifa-web:latest#ghcr.io/${{ github.repository_owner }}/2026fifa-web:${{ github.sha }}#g" platform/deploy/k3s/web-deployment.yaml
|
||||
sed -i "s#ghcr.io/your-org/2026fifa-backend:latest#ghcr.io/${{ github.repository_owner }}/2026fifa-backend:${{ github.sha }}#g" platform/deploy/k3s/backend-deployment.yaml
|
||||
sed -i "s#ghcr.io/your-org/2026fifa-alerts:latest#ghcr.io/${{ github.repository_owner }}/2026fifa-alerts:${{ github.sha }}#g" platform/deploy/k3s/alerts-deployment.yaml
|
||||
|
||||
- name: 套用 K3s Manifest
|
||||
run: |
|
||||
kubectl apply -f platform/deploy/k3s/namespace.yaml
|
||||
kubectl apply -f platform/deploy/k3s/secret.yaml
|
||||
kubectl apply -f platform/deploy/k3s/configmap.yaml
|
||||
kubectl apply -f platform/deploy/k3s/postgres-deployment.yaml
|
||||
kubectl apply -f platform/deploy/k3s/redis-deployment.yaml
|
||||
kubectl apply -f platform/deploy/k3s/backend-deployment.yaml
|
||||
kubectl apply -f platform/deploy/k3s/web-deployment.yaml
|
||||
kubectl apply -f platform/deploy/k3s/alerts-deployment.yaml
|
||||
kubectl apply -f platform/deploy/k3s/ingress.yaml
|
||||
Reference in New Issue
Block a user