Skip to content

Commit 7d25236

Browse files
committed
Merge branch 'backend_kume' into develop
2 parents 6669791 + 43c93c8 commit 7d25236

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+10689
-1891
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build and Deploy to Cloud Run
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
permissions:
8+
contents: read
9+
id-token: write
10+
11+
jobs:
12+
build-and-deploy:
13+
runs-on: ubuntu-latest
14+
env:
15+
# Replace these with your values or set as repository Secrets
16+
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
17+
REGION: asia-northeast1
18+
REPOSITORY: my-fastapi-repo
19+
IMAGE_NAME: kz-backend-api
20+
SERVICE_NAME: kz-backend-api-service
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Authenticate to Google Cloud (OIDC)
27+
uses: google-github-actions/auth@v1
28+
with:
29+
# Use Workload Identity: configure a Workload Identity Provider in GCP and set the full resource name
30+
# Example: projects/123456789/locations/global/workloadIdentityPools/github-pool/providers/github-provider
31+
workload_identity_provider: ${{ secrets.GCP_WI_PROVIDER }}
32+
# Service account to impersonate (must be bound to the provider)
33+
service_account: ${{ secrets.GCP_SA }}
34+
35+
- name: Configure gcloud
36+
uses: google-github-actions/setup-gcloud@v1
37+
with:
38+
project_id: ${{ env.PROJECT_ID }}
39+
40+
- name: Configure Docker auth for Artifact Registry
41+
run: |
42+
gcloud auth configure-docker "${{ env.REGION }}-docker.pkg.dev"
43+
44+
- name: Build and push Docker image
45+
run: |
46+
IMAGE_TAG=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
47+
docker build -f backend/Dockerfile.cloudrun -t $IMAGE_TAG backend
48+
docker push $IMAGE_TAG
49+
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT
50+
51+
- name: Deploy to Cloud Run
52+
env:
53+
IMAGE_TAG: ${{ steps.build-and-push.outputs.IMAGE_TAG || '' }}
54+
run: |
55+
# If IMAGE_TAG not available via outputs, reconstruct
56+
if [ -z "$IMAGE_TAG" ]; then
57+
IMAGE_TAG=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
58+
fi
59+
gcloud run deploy ${{ env.SERVICE_NAME }} --image="$IMAGE_TAG" --platform=managed --region=${{ env.REGION }} --allow-unauthenticated --memory=512Mi --concurrency=80

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ api_keys.txt
6363
*.p12
6464
*.pfx
6565

66+
# デプロイ情報・機密URL情報(backend-report全体を除外)
67+
docs/backend-report/
68+
docs/project_report/
69+
70+
# Debug and test files (debug folder)
71+
backend/debug/
72+
debug/
73+
test_received_jsons/
74+
75+
# 機密情報を含むドキュメント・スクリプト(実際のCloud Run URLを含むため除外)
76+
/TESTING_GUIDE.md
77+
/QUICK_START.md
78+
/quick_start_test.ps1
79+
/backend/DEPLOYMENT_GUIDE.md
80+
/.github/copilot-instructions.md
81+
/communication_test_dashboard.html
82+
83+
# Debug frontend (API test tool - local use only)
84+
debug_frontend/
85+
86+
debug_hardware/
87+
88+
4DXHOME/
89+
6690
# Database and data files
6791
*.db
6892
*.sqlite

QUICK_START.example.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# 4DX@HOME デバッグ環境 クイックスタートガイド
2+
3+
> **⚠️ 注意**: このファイルはテンプレートです。実際のCloud Run URLは `QUICK_START.md` に記載されていますが、そのファイルは `.gitignore` により除外されています。
4+
5+
## 📋 目的
6+
7+
このガイドでは、**フロントエンドとハードウェア間の通信が必ずCloud Run APIサーバーを経由する**ことを実際に確認します。
8+
9+
## 🎯 検証項目
10+
11+
- ✅ フロントエンド → Cloud Run API → ハードウェア の3層通信
12+
- ✅ WebSocketによる双方向通信
13+
- ✅ デバイステストのリクエスト・レスポンス
14+
- ✅ 直接通信の防止(廃止エンドポイントが410エラーを返す)
15+
16+
## 🚀 クイックスタート(5分)
17+
18+
### 方法1: 自動テストスクリプト(推奨)
19+
20+
```powershell
21+
# リポジトリルートで実行
22+
.\quick_start_test.ps1
23+
```
24+
25+
> ****: `quick_start_test.ps1` は実際のCloud Run URLを含むため、`.gitignore` により除外されています。
26+
27+
### 方法2: 手動セットアップ
28+
29+
#### ステップ1: Cloud Run URL取得
30+
31+
```powershell
32+
# サービスURLを取得
33+
gcloud run services describe fdx-home-backend-api --region=asia-northeast1 --format="value(status.url)"
34+
```
35+
36+
取得したURLを各 `.env` ファイルに設定してください。
37+
38+
#### ステップ2: debug_hardware起動
39+
40+
```powershell
41+
# ターミナル1
42+
cd debug_hardware
43+
python app.py
44+
```
45+
46+
**期待される出力**:
47+
```
48+
============================================================
49+
🚀 デバイスハブテストサーバー起動
50+
セッションID: DH001
51+
Cloud Run URL: https://your-backend-api-XXXXXXXXXX.asia-northeast1.run.app
52+
============================================================
53+
✅ [WebSocket] 接続確立成功
54+
* Running on http://127.0.0.1:5000
55+
```
56+
57+
#### ステップ3: debug_frontend起動
58+
59+
```powershell
60+
# ターミナル2
61+
cd debug_frontend
62+
npm run dev
63+
```
64+
65+
ブラウザで開く: http://localhost:5173
66+
67+
#### ステップ4: デバイステスト実行
68+
69+
1. **動画選択画面**`demo1` を選択
70+
2. **「次へ」**ボタンをクリック
71+
3. **準備画面****「デバイスをテスト」** ボタンをクリック
72+
73+
## 📊 期待される結果
74+
75+
### ✅ ブラウザコンソール
76+
77+
```
78+
🧪 デバイステスト開始
79+
📤 POST https://your-backend-api-XXXXXXXXXX.asia-northeast1.run.app/api/device/test
80+
✅ デバイステスト完了: {
81+
status: 'success',
82+
device_response: {
83+
type: 'device_test_result',
84+
results: {
85+
vibration: true,
86+
wind: true,
87+
water: true,
88+
flash: true,
89+
color: true
90+
},
91+
all_passed: true
92+
}
93+
}
94+
```
95+
96+
### ✅ debug_hardware ログ(ターミナル1)
97+
98+
```
99+
============================================================
100+
🧪 [WebSocket] デバイステスト指示受信
101+
テストタイプ: basic
102+
Session ID: DH001
103+
============================================================
104+
✅ VIBRATION: 正常
105+
✅ WIND: 正常
106+
✅ WATER: 正常
107+
✅ FLASH: 正常
108+
✅ COLOR: 正常
109+
============================================================
110+
✅ [WebSocket] デバイス動作確認完了
111+
============================================================
112+
```
113+
114+
## 🔍 通信フロー図
115+
116+
```
117+
[Frontend] [Cloud Run API] [debug_hardware]
118+
localhost:5173 asia-northeast1 localhost:5000
119+
| | |
120+
| POST /api/device/test | |
121+
|------------------------->| |
122+
| | |
123+
| | WebSocket: device_test |
124+
| |--------------------------->|
125+
| | |
126+
| | | テスト実行
127+
| | | (5デバイス)
128+
| | |
129+
| | WebSocket: device_test_result
130+
| |<---------------------------|
131+
| | |
132+
| HTTP Response | |
133+
| {device_response: {...}} | |
134+
|<-------------------------| |
135+
| | |
136+
```
137+
138+
## 🐛 トラブルシューティング
139+
140+
### Cloud Run URLの確認
141+
142+
```powershell
143+
# サービスURL取得
144+
gcloud run services describe fdx-home-backend-api --region=asia-northeast1 --format="value(status.url)"
145+
```
146+
147+
### Cloud Run APIが応答しない
148+
149+
```powershell
150+
# Cloud Run APIのヘルスチェック
151+
curl [YOUR_CLOUD_RUN_URL]/health
152+
153+
# サービス状態確認
154+
gcloud run services describe fdx-home-backend-api --region=asia-northeast1
155+
```
156+
157+
## 📚 詳細ドキュメント
158+
159+
- **完全なテストガイド**: `TESTING_GUIDE.md` (Git除外ファイル)
160+
- **デプロイガイド**: `backend/DEPLOYMENT_GUIDE.md` (Git除外ファイル)
161+
- **デバイステスト手順**: `debug_hardware/DEVICE_TEST_GUIDE.md`
162+
163+
---
164+
165+
**最終更新**: 2025年11月7日
166+
**テンプレートバージョン**: 1.0

0 commit comments

Comments
 (0)