Skip to content

Commit 512659c

Browse files
authored
Merge pull request #33 from Team-GORANI/taehan-kim-patch-1
Frontend CI/CD & CORS ENV Variables setting
2 parents 4795404 + ea2639e commit 512659c

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Front-End Build & Push New Model
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- "frontend/**" # frontend 폴더와 하위 파일 및 디렉토리에 변경이 있을 때만 트리거
8+
pull_request:
9+
branches:
10+
- main
11+
paths:
12+
- "frontend/**" # frontend 폴더와 하위 파일 및 디렉토리에 변경이 있을 때만 트리거
13+
env:
14+
PROJECT_ID: ascendant-pad-445604-e1 # GCP 프로젝트 ID
15+
REGION: asia-northeast3 # GCP 리전(서울)
16+
ZONE: asia-northeast3-a # GCP 존
17+
REPOSITORY: gorani-frontend # Docker Artifact Registry 레포지토리 이름
18+
IMAGE: main # Docker 이미지 이름
19+
GCE_INSTANCE: gorani-front # GCE VM 인스턴스 이름
20+
21+
jobs:
22+
ci:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
# GCP 인증
28+
- id: 'auth'
29+
name: 'Authenticate to Google Cloud'
30+
uses: 'google-github-actions/auth@v0.6.0'
31+
with:
32+
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
33+
token_format: 'access_token'
34+
35+
# Setup gcloud CLI
36+
- name: 'Set up Cloud SDK'
37+
uses: 'google-github-actions/setup-gcloud@v2'
38+
with:
39+
version: '>= 363.0.0'
40+
41+
# Docker 이미지 빌드
42+
- name: 'Docker build'
43+
run: |-
44+
docker build \
45+
--tag "$REGION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA" \
46+
./frontend
47+
48+
- uses: 'docker/login-action@v1'
49+
name: 'Docker login'
50+
with:
51+
registry: '${{ env.REGION }}-docker.pkg.dev'
52+
username: 'oauth2accesstoken'
53+
password: '${{ steps.auth.outputs.access_token }}'
54+
55+
- name: 'Docker push'
56+
run: |-
57+
docker push "$REGION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA"
58+
cd:
59+
runs-on: ubuntu-latest
60+
needs: [ci]
61+
steps:
62+
- id: 'auth'
63+
name: 'Authenticate to Google Cloud'
64+
uses: 'google-github-actions/auth@v0.6.0'
65+
with:
66+
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
67+
token_format: 'access_token'
68+
69+
- name: Deploy
70+
run: |-
71+
gcloud compute instances update-container "$GCE_INSTANCE" \
72+
--zone "$ZONE" \
73+
--container-image "$REGION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA"

app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# 프론트엔드(localhost:5174)에서의 API 요청 허용
1414
app.add_middleware(
1515
CORSMiddleware,
16-
allow_origins=["http://localhost:5173"], # 프론트엔드 서버 주소
16+
allow_origins=[os.getenv('FRONTEND_URL', 'http://localhost:5173')], # 프론트엔드 서버 주소
1717
allow_credentials=True, # 자격 증명(쿠키 등) 허용
1818
allow_methods=["*"], # 모든 HTTP 메서드 허용
1919
allow_headers=["*"], # 모든 HTTP 헤더 허용

frontend/src/services/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import axios from 'axios';
22

33
// axios 인스턴스 생성
44
const api = axios.create({
5-
baseURL: 'http://localhost:8000', // FastAPI 서버 주소
5+
baseURL: import.meta.env.VITE_API_URL || 'http://localhost:8000', // FastAPI 서버 주소
66
headers: {
77
'Content-Type': 'application/json',
88
},

0 commit comments

Comments
 (0)