Beanstalk : Node.js 배포-권한 거부로 인해 node-gyp 실패
Node.js 애플리케이션 (노드 6, npm 5)을 Beanstalk에 배포하면 다음과 같이 실패합니다.
gyp ERR! 스택 오류 : EACCES : 권한 거부 됨, mkdir '/ tmp / deployment / application / node_modules / heapdump / build'
오류가 패키지와 관련된 것은 아니지만 모든 node-gyp 호출이 실패합니다.
AWS 콘솔의 ERROR 이벤트는 다음과 같습니다.
[인스턴스 : i-12345] 인스턴스에서 명령이 실패했습니다. 반환 코드 : 1 출력 : (TRUNCATED) ... / opt / elasticbeanstalk / containerfiles / ebnode.py ", 180 행, npm_install raise e subprocess.CalledProcessError : 명령 '['/ opt / elasticbeanstalk / node-install / node- v6.10.0-linux-x64 / bin / npm ','--production ','install ']'이 0이 아닌 종료 상태 1을 반환했습니다. /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh 후크가 실패했습니다. 자세한 내용은 콘솔 또는 EB CLI를 사용하여 /var/log/eb-activity.log를 확인하십시오.
및 eb-activity.log
상기 NPM 오류를 함유 하였다.
.zip 파일을 포함하지 않은 .zip 파일을 업로드하여 애플리케이션을 수동으로 배포했습니다 node_modules
. 즉, eb
명령 줄 도구 를 통해 배포되지 않았습니다 .
해결책
해결책은 .npmrc
콘텐츠가 있는 파일 을 애플리케이션 에 추가하는 것입니다 .
# Force npm to run node-gyp also as root, preventing permission denied errors in AWS with npm@5
unsafe-perm=true
(또는 다른 방법으로 npm을 구성합니다. (설정 npm_config_unsafe_perm=true
이 /opt/elasticbeanstalk/env.vars
작동하지 않았지만)
설명
npm install
루트 사용자가 실행하지만 node-gyp
일부 패키지에 대해 트리거 하는 프로세스는 기본 사용자가 실행합니다 ec2-user
. 이 사용자는 /tmp/deployment/application/node_modules/
npm 설치 실행으로 생성되고 루트가 소유 한 디렉토리에 대한 액세스 권한이 없습니다 . (그리고 가능성도에 대한 접근 부족 /tmp/.npm
과 /tmp/.config
같은 만든입니다.) 가능하면 unsafe-perm
, 우리는 루트로도 노드 활력을 실행하는 NPM을 강제로 문제를 방지.
(개인적으로 나는 모든 실행하는 것을 선호 ec2-user
하기보다는를 root
:-)하지만 난 그게 더 복잡 것 같아요)
크레딧
관련 질문
여기서 두 가지를해야합니다.
첫 번째 : 프로젝트 루트에 .ebextensions 폴더가 아직없는 경우 생성합니다. 그런 다음 .ebextensions에 01_fix_permissions.config라는 파일을 생성합니다.
그런 다음 두 번째로 PROXY를 활성화 set -xe
하고/opt/elasticbeanstalk/bin/healthd-track-pidfile --proxy nginx
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/49_change_permissions.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
sudo chown -R ec2-user:ec2-user tmp/
set -xe
/opt/elasticbeanstalk/bin/healthd-track-pidfile --proxy nginx
우리 팀과 저는 서비스를 초기화하는 스크립트의 일부 구성을 재정 의하여 Amazon NodeJS 시스템에서이 작업을 수행 할 수있었습니다. 이는 기본적으로 포함 된 aws 노드 실행 구성을 정확히 동일한 스크립트와 몇 가지 추가 명령으로 덮어 씁니다. 이것은 아래에 놓을 파일입니다..ebextensions
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
#==============================================================================
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Amazon Software License (the "License"). You may not use
# this file except in compliance with the License. A copy of the License is
# located at
#
# http://aws.amazon.com/asl/
#
# or in the "license" file accompanying this file. This file is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or
# implied. See the License for the specific language governing permissions
# and limitations under the License.
#==============================================================================
chmod 777 -R /tmp
set -xe
sudo /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
인스턴스에서 aws 구성으로 수정했습니다. t2.micro => t2.small 또는 더 큰 것. 여기에 링크 설명 입력
'Program Tip' 카테고리의 다른 글
진행 대화 상자에서 취소 버튼을 설정하는 방법은 무엇입니까? (0) | 2020.12.06 |
---|---|
Java 8 람다 목록에서 요소 가져 오기 및 제거 (0) | 2020.12.06 |
WideCharToMultiByte를 올바르게 사용하는 방법 (0) | 2020.12.06 |
마우스 오른쪽 버튼 클릭에 이벤트 바인딩 (0) | 2020.12.06 |
$ (document) .ready ()가 모두 실행 된 후 이벤트가 있습니까? (0) | 2020.12.06 |