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"
0 commit comments