asia-northeast1
로 배포할 예정이므로 Firebase의 기본 리소스 위치도 asia-northeast1
로 설정$ curl -sL https://firebase.tools | bash
$ firebase login
$ firebase projects:list
확인 사항
- 요금제를 변경하면서 결제 계정을 설정이 필요
- 결제 계정 설정 후 요금제 변경 가능
시작하기 전에
1.Google Cloud Console의 프로젝트 선택기 페이지에서 Google Cloud 프로젝트를 선택하거나 만듭니다.
⇒ Google Cloud Console - Project 선택 완료
2.Cloud 프로젝트에 결제가 사용 설정되어 있는지 확인합니다. 프로젝트에 결제가 사용 설정되어 있는지 확인하는 방법을 알아보세요.
⇒ 유료 계정 활성화 완료
3. Google Cloud CLI를 설치하고 초기화합니다.
$ brew install --cask google-cloud-sdk
$ gcloud init
Welcome! This command will take you through the configuration of gcloud.
Settings from your current configuration [default] are:
core:
account: [본인 계정]
disable_usage_reporting: 'True'
project: [프로젝트]
Pick configuration to use:
[1] Re-initialize this configuration [default] with new settings
[2] Create a new configuration
# 다른 프로젝트가 지정되어 있어서 변경을 위해 Re-initialize
Please enter your numeric choice: 1
Choose the account you would like to use to perform operations for this configuration:
[1] [본인 계정]
[2] Log in with a new account
Please enter your numeric choice: 1
You are logged in as: [위에서 선택한 계정].
Pick cloud project to use:
[1] [내 프로젝트1]
[2] [내 프로젝트2]
[3] Enter a project ID
[4] Create a new project
Please enter numeric choice or text value (must exactly match list item): 1
Your current project has been set to: [위에서 선택한 프로젝트].
...
Your Google Cloud SDK is configured and ready to use!
...
$ gcloud components update
프로젝트명
디렉토리 생성 및 해당 디렉토리로 이동package.json
파일을 생성{
"name": "helloworld",
"description": "Simple hello world sample in Node",
"version": "1.0.0",
"private": true,
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"engines": {
"node": ">=16.0.0" // 16버전(최신버전)으로 변경
},
"author": "Google LLC",
"license": "Apache-2.0",
"dependencies": {
"express": "^4.17.1"
}
}
const express = require('express');
const app = express();
app.get('/', (req, res) => {
const name = process.env.NAME || 'World';
res.send(`Hello ${name}!`);
});
const port = parseInt(process.env.PORT) || 8080;
app.listen(port, () => {
console.log(`helloworld: listening on port ${port}`);
});
$ gcloud run deploy
Dockerfile
, .dockerignore
, .gcloudignore
생성# Dockerfile
FROM node:18-slim
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --omit=dev
COPY . ./
CMD ["node", "index.js"]
# .dockerignore
Dockerfile
.dockerignore
node_modules
npm-debug.log
# .gcloudignore
node_modules
npm-debug.log
- 변경사항 : 샘플 코드의 Dockerfile
RUN npm install --only=production
을 그대로 빌드하면 아래와 같은 에러가 발생한다.
⇒
--only=production
을--omit=dev
로 변경
$ gcloud builds submit --tag IMAGE_URL
⇒ IMAGE_URL
은 gcr.io/PROJECT-ID/PROJECT-ID
로 작성해서 배포
이미지 URL 확인 방법
Google Cloud Console > Cloud Run > 서비스 선택 > 버전
에서 확인
scripts
에 "gcloud:build": "gcloud builds submit --tag gcr.io/PROJECT-ID/PROJECT-ID"
추가 Google Cloud Console > Cloud Run > 서비스 선택 > 새 버전 및 수정 배포
일반설정 > 컨테이너 이미지 URL 선택 > 컨테이너 선택 > 최신 버전 선택
$ gcloud run deploy SERVICE --image IMAGE_URL
SERVICE를 배포할 서비스의 이름으로 바꿉니다. 이 매개변수를 완전히 생략할 수 있지만 생략하면 서비스 이름을 입력하라는 메시지가 표시됩니다.
scripts
에 "gcloud:deploy": "gcloud run deploy --image gcr.io/PROJECT-ID/PROJECT-ID"
추가 Google Cloud Console > Cloud Run > 서비스 선택 > 지속적 배포 설정