[Google Cloud] 서버 배포 오류

2022. 12. 25. 18:21·BE Study
반응형

 

Google Cloud에 서버를 배포하던 중 오류가 발생하였다.

Updating service [default] (this may take several minutes)...failed.              
ERROR: (gcloud.app.deploy) Error Response: [9] An internal error occurred while processing task /app-engine-flex/flex_await_healthy/flex_await_healthy>2022-12-25T08:48:43.233Z5850.fb.2: 
> todo_app@1.0.0 start /app
> nodemon server.js

sh: 1: nodemon: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! todo_app@1.0.0 start: `nodemon server.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the todo_app@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-12-25T08_49_04_319Z-debug.log

오류코드에서 볼 수 있듯이 dependencies nodemon이 문제가 되었던 상황이 이었다.

 

 

현재 package.json 파일을 보게 되면

{
  "name": "todo_app",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon server.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.20.1",
    "dotenv": "^16.0.3",
    "ejs": "^3.1.8",
    "express": "^4.18.2",
    "express-session": "^1.17.3",
    "method-override": "^3.0.0",
    "mongodb": "^3.6.4",
    "passport": "^0.6.0",
    "passport-local": "^1.0.0"
  }
}

다음과 같이 script의 'start'에 nodemon이 사용되고 있는 것을 볼 수 있지만, dependencies에는 저장이 되어있지 않은 상태이다. nodemon이 현재 내 컴퓨터에는 global로 설치가 되어있기 때문에 'npm run start'로 사용이 가능했지만, google cloud App Engine에는 따로 설정을 해주어야 한다. (AWS EC2와 다르게 Google Cloud는 dependencies library를 자동으로 설치를 해준다) 평소 하던 대로 nodemon을 dependencies에 추가하지 않고 devDependencies에 추가하기 위해 $ npm install --save-dev nodemon을 이용하여 설치를 해주었다.

이후 다시 $ gcloud app deploy를 이용하여 배포서버를 upload 하였지만 동일한 오류를 만나게 되었다.

 

 

Google Cloud Specifying dependencies 문서를 통해 문제를 파악한 결과 다음과 같은 문구를 확인할 수 있었다.

All dependencies that you define under the devDependencies field are ignored and do not get installed for your app in App Engine.

결국, devDependencies에 지정된 libraray는 Google Cloud App Engine에 설치가 안 되는 것이었다.

nodemon을 다시 $ npm install nodemon을 통해 dependencies library로 설치하고 자동 배포($ gcloud app deploy)를 진행하니 문제가 없이 배포가 완료되었다.

 

 

추가적으로

During deployment, the Node.js runtime automatically installs all dependencies declared in your package.json file. By default, the npm install command is used, unless a yarn.lock file exists and is not listed in the app.yaml file's skip_files section, in which case yarn install --production is used instead.

다음 문서 내용처럼 app.yaml 파일의 skip-files 섹션에서 배포 후 필요한 dependencies가 쓰여있지 않으면 기본적으로 npm install 명령어가 실행되는 것을 알 수 있다.

 

 

결론

1. package.json에서 devDependencies에 지정된 libraray는 Google Cloud App Engine에 설치가 안된다.
2. nodemon server.js는 local에서 테스트하는 용도로만 사용하고, cloud에 deploy할때는 삭제해도 자동으로 서버가 시작된다.
    - 이때, package.json sciprt에 nodemon등의 CLI 작업 설정이 없어야 한다.

 

 

참조

Google Cloud Specifying dependencies

https://cloud.google.com/appengine/docs/standard/nodejs/specifying-dependencies

반응형
저작자표시 변경금지 (새창열림)

'BE Study' 카테고리의 다른 글

Node.js + MongoDB App 만들기 (1)  (0) 2022.12.16
백엔드 면접 스크립트 - Node.js  (0) 2022.12.06
백엔드 면접 스크립트 - Database  (0) 2022.11.15
백엔드 면접 스크립트 - 운영체제  (0) 2022.10.21
백엔드 면접 스크립트 - Network  (0) 2022.10.21
'BE Study' 카테고리의 다른 글
  • Node.js + MongoDB App 만들기 (1)
  • 백엔드 면접 스크립트 - Node.js
  • 백엔드 면접 스크립트 - Database
  • 백엔드 면접 스크립트 - 운영체제
OverFlowBIN
OverFlowBIN
    반응형
  • OverFlowBIN
    OverFlowBIN BE Tech Blog
    OverFlowBIN
  • 전체
    오늘
    어제
  • 글쓰기 관리
    • 전체보기
      • Computer Science
      • BE Study
      • MySQL
      • Algorithm
      • Language
        • TypeScript
        • JavaScript
        • Python
        • JAVA
      • Spring Boot
      • Programing Tool
      • Group Study
      • HTTP
      • Node
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    단축평가
    일급 함수
    backend
    algorithm
    thymeleaf
    spring boot
    python #내장함수 #자료구조
    node.js
    논리연산자
    백엔드
    programers
    의존성 주입
    Nullish
    기술면접
    axios
    MongoDB
    게시판 만들기
    httpie
    이진검색
    Spring
    Google Cloud
    일급함수
    Java
    javascript
    back-end
    app engine
    코딩테스트
    bootstrap
    이분탐색
    동작원리
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
OverFlowBIN
[Google Cloud] 서버 배포 오류
상단으로

티스토리툴바