在 AWS ElasticBeanstalk 中反应构建容器命令非常慢

问题描述

我正在 AWS ElasticBeanstalk 上运行 Django + React 应用程序,并且在 React 构建步骤似乎存在巨大的部署瓶颈。

2021-07-21 07:28:46,720 P9986 [INFO] ************************************************************
2021-07-21 07:28:46,720 P9986 [INFO] ConfigSet Infra-EmbeddedPreBuild
2021-07-21 07:28:46,723 P9986 [INFO] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2021-07-21 07:28:46,723 P9986 [INFO] Config prebuild_0
2021-07-21 07:28:51,737 P9986 [INFO] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2021-07-21 07:28:51,737 P9986 [INFO] Config prebuild_1
2021-07-21 07:28:51,737 P9986 [INFO] ============================================================
2021-07-21 07:28:51,737 P9986 [INFO] Test for Command 01_download_nodejs
2021-07-21 07:28:51,740 P9986 [ERROR] Exited with error code 1
2021-07-21 07:28:51,740 P9986 [INFO] ============================================================
2021-07-21 07:28:51,740 P9986 [INFO] Test for Command 02_install_nodejs
2021-07-21 07:28:51,742 P9986 [ERROR] Exited with error code 1
2021-07-21 07:28:51,743 P9986 [INFO] ============================================================
2021-07-21 07:28:51,743 P9986 [INFO] Test for Command 03_install_yarn_repo
2021-07-21 07:28:51,745 P9986 [ERROR] Exited with error code 1
2021-07-21 07:28:51,745 P9986 [INFO] ============================================================
2021-07-21 07:28:51,745 P9986 [INFO] Test for Command 04_install_yarn
2021-07-21 07:28:51,747 P9986 [ERROR] Exited with error code 1
2021-07-21 07:28:58,335 P10175 [INFO] ************************************************************
2021-07-21 07:28:58,335 P10175 [INFO] ConfigSet Infra-EmbeddedPostBuild
2021-07-21 07:28:58,338 P10175 [INFO] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2021-07-21 07:28:58,338 P10175 [INFO] Config postbuild_0_twistt
2021-07-21 07:28:58,356 P10175 [INFO] ============================================================
2021-07-21 07:28:58,356 P10175 [INFO] Command 06_yarn_install
2021-07-21 07:29:45,106 P10175 [INFO] -----------------------Command Output-----------------------
2021-07-21 07:29:45,107 P10175 [INFO]   yarn install v1.22.5
### Some warnings
2021-07-21 07:29:45,108 P10175 [INFO]   Done in 46.21s.
2021-07-21 07:29:45,108 P10175 [INFO] ------------------------------------------------------------
2021-07-21 07:29:45,108 P10175 [INFO] Completed successfully.
2021-07-21 07:29:45,142 P10175 [INFO] ============================================================
2021-07-21 07:29:45,142 P10175 [INFO] Command 070_update_browserslist
2021-07-21 07:30:23,325 P10175 [INFO] -----------------------Command Output-----------------------
2021-07-21 07:30:23,336 P10175 [INFO] Completed successfully.
2021-07-21 07:30:23,365 P10175 [INFO] ============================================================
2021-07-21 07:30:23,365 P10175 [INFO] Command 07_yarn_run_build
2021-07-21 07:56:06,817 P10175 [INFO] -----------------------Command Output-----------------------
2021-07-21 07:56:06,826 P10175 [INFO]   yarn run v1.22.5
2021-07-21 07:56:06,826 P10175 [INFO]   $ react-scripts build
2021-07-21 07:56:06,826 P10175 [INFO]   Creating an optimized production build...
2021-07-21 07:56:06,826 P10175 [INFO]   Compiled with warnings.
### ... List of compiler errors and other standard react build boilerplate
2021-07-21 07:56:06,838 P10175 [INFO]   
2021-07-21 07:56:06,838 P10175 [INFO]   Done in 1543.22s.
2021-07-21 07:56:06,838 P10175 [INFO] ------------------------------------------------------------
2021-07-21 07:56:06,838 P10175 [INFO] Completed successfully.
2021-07-21 07:56:06,892 P10175 [INFO] ============================================================
2021-07-21 07:56:06,892 P10175 [INFO] Command 08_migrate
2021-07-21 07:56:09,817 P10175 [INFO] -----------------------Command Output-----------------------
### ... Django migrations info
2021-07-21 07:56:09,817 P10175 [INFO] ------------------------------------------------------------
2021-07-21 07:56:09,817 P10175 [INFO] Completed successfully.
2021-07-21 07:56:09,825 P10175 [INFO] ============================================================
2021-07-21 07:56:09,826 P10175 [INFO] Command 09_collectstatic
2021-07-21 07:56:13,046 P10175 [INFO] -----------------------Command Output-----------------------
2021-07-21 07:56:13,047 P10175 [INFO]   
2021-07-21 07:56:13,047 P10175 [INFO]   194 static files copied to '/var/app/staging/staticfiles',604 post-processed.
2021-07-21 07:56:13,047 P10175 [INFO] ------------------------------------------------------------
2021-07-21 07:56:13,047 P10175 [INFO] Completed successfully.
2021-07-21 07:56:13,055 P10175 [INFO] ============================================================
2021-07-21 07:56:13,055 P10175 [INFO] Command 10_set_is_cloud_server_var
2021-07-21 07:56:13,121 P10175 [INFO] Completed successfully.

如您所见,react 构建脚本花费了 20 多分钟。

我省略了编译器警告,因为那里没有任何实质性内容(只是 React 组件的标准 linter 问题)。

预构建命令(安装 nodejs 和 yarn)失败,但我不明白为什么这会对事情产生影响(构建成功,大概是因为这些依赖项已经在环境中)

在 2016 年的 13 英寸 MacBook Pro 本地,这需要大约 38 秒。

使用的实例是 t2.micro,但有时在这个实例上构建需要不到 100 秒。

可能是什么问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)