Cloud Computing
[GCP] Firebase에 Flask 앱 배포하기
커피맛스누피
2021. 7. 1. 16:37
디렉터리 구조
/rootProject
ㄴ/server
ㄴ/src
ㄴ/templates
ㄴindex.html
ㄴ app.py
ㄴDockerfile
ㄴ/static
ㄴstyle.css
ㄴ/venv
ㄴ.firebaserc
ㄴfirebase.json
ㄴfirestore.indexes.json
1단계: 샘플 app 작성하기
2단계: 앱을 컨테이너화하여 Container Registry에 업로드
gcloud builds submit --tag gcr.io/PROJECT_ID/rootProject
3단계: Cloud Run에 컨테이너 이미지 배포
gcloud run deploy --image gcr.io/PROJECT_ID/rootProject
4단계: Firebase로 호스팅 요청 전달
firebase.json 편집
"hosting": {
// ...
// Add the "rewrites" attribute within "hosting"
"rewrites": [ {
"source": "/helloworld",
"run": {
"serviceId": "helloworld", // "service name" (from when you deployed the container image)
"region": "us-central1" // optional (if omitted, default is us-central1)
}
} ]
}
배포 명령어 실행
firebase deploy
+ Docker로 로컬에서 테스트
PORT=8080 && docker run -p 9090:${PORT} -e PORT=${PORT} IMAGE_URL
IMAGE_URL을 이미지 경로로 바꿔야 한다.
(참고)
https://firebase.google.com/docs/hosting/cloud-run?hl=ko
https://medium.com/firebase-developers/hosting-flask-servers-on-firebase-from-scratch-c97cfb204579