amazon-web-services - AWS Pipeline - 损坏的构建
问题描述
我的代码管道停止工作,错误消息是:
yarn run v1.21.1
$ react-app-rewired build
Creating an optimized production build...
<--- Last few GCs --->
[23:0x55e3d7ad8700] 188895 ms: Mark-sweep 1824.5 (1875.9) -> 1823.0 (1883.6) MB, 1725.5 / 0.0 ms (average mu = 0.109, current mu = 0.013) allocation failure scavenge might not succeed
[23:0x55e3d7ad8700] 191161 ms: Mark-sweep 1831.3 (1884.2) -> 1829.9 (1889.8) MB, 2253.0 / 0.0 ms (average mu = 0.052, current mu = 0.006) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x55e3d5b70342]
Security context: 0x0be28ab9a299 <JSObject>
1: addMappingWithCode [0x396c722b2119] [/app/node_modules/source-map/lib/source-node.js:~150] [pc=0xd1b26fc691d](this=0x304f7c5044c1 <JSGlobal Object>,0x32d3c4a6d401 <Object map = 0x12d61490c7a9>,0x069a17fc0ae1 <String[18]: var >)
2: /* anonymous */ [0x2863e0300269] [/app/node_modules/source-map/lib/source-node.js:~86] [pc=0xd1b26fc4673...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Writing Node.js report to file: report.20210409.212950.23.0.001.json
Node.js report completed
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command '/bin/sh -c yarn run build' returned a non-zero code: 1
[Container] 2021/04/09 21:29:51 Command did not exit successfully docker build -f Dockerfile-prod -t $REPOSITORY_URI:$BRANCH --build-arg API_URL=$API_URL --build-arg PORTAL_TOKEN=$PORTAL_TOKEN --build-arg REACT_ENV=$REACT_ENV . exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: BUILD State: FAILED
[Container] 2021/04/09 21:29:51 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -f Dockerfile-prod -t $REPOSITORY_URI:$BRANCH --build-arg API_URL=$API_URL --build-arg PORTAL_TOKEN=$PORTAL_TOKEN --build-arg REACT_ENV=$REACT_ENV .. Reason: exit status 1
[Container] 2021/04/09 21:29:51 Entering phase POST_BUILD
[Container] 2021/04/09 21:29:51 Running command bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi"
[Container] 2021/04/09 21:29:51 Command did not exit successfully bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi" exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: POST_BUILD State: FAILED
[Container] 2021/04/09 21:29:51 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi". Reason: exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
[Container] 2021/04/09 21:29:51 Phase context status code: Message: yarn run v1.21.1
$ react-app-rewired build
Creating an optimized production build...
<--- Last few GCs --->
[23:0x55e3d7ad8700] 188895 ms: Mark-sweep 1824.5 (1875.9) -> 1823.0 (1883.6) MB, 1725.5 / 0.0 ms (average mu = 0.109, current mu = 0.013) allocation failure scavenge might not succeed
[23:0x55e3d7ad8700] 191161 ms: Mark-sweep 1831.3 (1884.2) -> 1829.9 (1889.8) MB, 2253.0 / 0.0 ms (average mu = 0.052, current mu = 0.006) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x55e3d5b70342]
Security context: 0x0be28ab9a299 <JSObject>
1: addMappingWithCode [0x396c722b2119] [/app/node_modules/source-map/lib/source-node.js:~150] [pc=0xd1b26fc691d](this=0x304f7c5044c1 <JSGlobal Object>,0x32d3c4a6d401 <Object map = 0x12d61490c7a9>,0x069a17fc0ae1 <String[18]: var >)
2: /* anonymous */ [0x2863e0300269] [/app/node_modules/source-map/lib/source-node.js:~86] [pc=0xd1b26fc4673...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Writing Node.js report to file: report.20210409.212950.23.0.001.json
Node.js report completed
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command '/bin/sh -c yarn run build' returned a non-zero code: 1
[Container] 2021/04/09 21:29:51 Command did not exit successfully docker build -f Dockerfile-prod -t $REPOSITORY_URI:$BRANCH --build-arg API_URL=$API_URL --build-arg PORTAL_TOKEN=$PORTAL_TOKEN --build-arg REACT_ENV=$REACT_ENV . exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: BUILD State: FAILED
[Container] 2021/04/09 21:29:51 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -f Dockerfile-prod -t $REPOSITORY_URI:$BRANCH --build-arg API_URL=$API_URL --build-arg PORTAL_TOKEN=$PORTAL_TOKEN --build-arg REACT_ENV=$REACT_ENV .. Reason: exit status 1
[Container] 2021/04/09 21:29:51 Entering phase POST_BUILD
[Container] 2021/04/09 21:29:51 Running command bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi"
[Container] 2021/04/09 21:29:51 Command did not exit successfully bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi" exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: POST_BUILD State: FAILED
[Container] 2021/04/09 21:29:51 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi". Reason: exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
[Container] 2021/04/09 21:29:51 Phase context status code: Message:
线
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
提示内存问题。
因此,在 AWS 上,我尝试了:开发人员工具 -> CodeBuild -> 构建项目 -> 编辑 -> 环境 -> 附加配置,首先将计算部分从 3 GB 内存、2 个 vCPU 增加到 7 GB 内存、4 个 vCPU,然后从 7 个GB 内存,4 个 vCPU 到 15 GB 内存,8 个 vCPU。
另外,我尝试在 package.json 文件中添加如下内容及其一些变体:
"start": "react-scripts --max_old_space_size=4096 start",
"build": "set NODE_OPTIONS=--max_old_space_size=512 && react-app-rewired build",
我最后一次尝试是添加
- export NODE_OPTIONS="--max-old-space-size=8192”
到 buildspec.yml 文件的命令部分。
这是我的 package.json 文件的脚本部分:
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
},
这是我的 buildspec.xml 文件。
version: 0.2
phases:
install:
runtime-versions:
docker: 18
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- docker login --username ****** --password ‘******’
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- export NODE_OPTIONS="--max-old-space-size=8192”
build:
commands:
- docker build -f Dockerfile-prod -t $REPOSITORY_URI:$BRANCH --build-arg API_URL=$API_URL --build-arg PORTAL_TOKEN=$PORTAL_TOKEN --build-arg REACT_ENV=$REACT_ENV .
- docker tag $REPOSITORY_URI:$BRANCH $REPOSITORY_URI:$CODEBUILD_RESOLVED_SOURCE_VERSION
post_build:
commands:
- bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi"
- docker push $REPOSITORY_URI:$BRANCH
- docker push $REPOSITORY_URI:$CODEBUILD_RESOLVED_SOURCE_VERSION
- echo Writing image definitions file...
- printf "[{\"name\":\"$TASK_DEFINITION-Instance\",\"imageUri\":\"%s\"}]" $REPOSITORY_URI:$CODEBUILD_RESOLVED_SOURCE_VERSION > imagedefinitions.json
artifacts:
files: imagedefinitions.json
任何帮助将不胜感激。
解决方案
这是我的 buildspecs 文件,我根据您的问题和您在那里提供的详细信息解决了我提出的问题
version: 0.2
env:
variables:
NODE_ENV: 'development'
phases:
install:
runtime-versions:
nodejs: 12
pre_build:
commands:
- echo Deploy website
build:
commands:
- rm -rf .git
- yarn install
- NODE_OPTIONS="--max-old-space-size=8192"
- yarn build
post_build:
commands:
- echo 'Invalidating distribuition cache'
- aws cloudfront create-invalidation --distribution-id my_id --paths "/*"
推荐阅读
- python - 如何使用pybind11将堆分配指针的`std::vector`传递给python?
- javascript - 数据未在 html 中呈现
- react-native - 标题/标题未在两个导航器之间更新(反应导航 5)
- vue.js - Aws Amplify: Partial updates(mutations)
- kubernetes - 如何在 Kubernetes 中找出哪个 IP 属于哪个 POD?
- azure - 部署到 Linux 应用服务的 Visual Studio Web 部署错误 - 无法完成对远程代理的请求
- reactjs - 如何克服 http 429 错误以发送更多 API 请求?
- python - 如何将 numpy 数组转换为 gif?
- java - JSONPATH - java.lang.NoSuchFieldError: defaultReader
- c# - 初始化泛型对象时设置只读变量?