Elastic Beanstalk 预部署 Laravel 节点错误

Elastic Beanstalk pre-deploy Laravel Node error

在 Laravel 上部署 Elasticbean stalk 时出现问题,因为我正在使用 GitHub 软件包之一

https://github.com/rennokki/laravel-aws-eb

我将 .ebextensions 和 .platform 文件夹删除到我的根项目中。

当我部署并遇到错误时,我决定检查日志报告,它说这是由于 node.js

2021-10-20 10:48:34,072 [INFO] -----------------------Starting build-----------------------
2021-10-20 10:48:34,079 [INFO] Running configSets: Infra-EmbeddedPostBuild
2021-10-20 10:48:34,082 [INFO] Running configSet Infra-EmbeddedPostBuild
2021-10-20 10:48:34,086 [INFO] Running config postbuild_0_Ergnation_rowing
2021-10-20 10:48:34,103 [INFO] Command 00_copy_env_file succeeded
2021-10-20 10:48:36,241 [INFO] Command 01_install_composer_dependencies succeeded
2021-10-20 10:48:36,263 [ERROR] Command 02_install_node_dependencies (sudo npm install) failed
2021-10-20 10:48:36,263 [ERROR] Error encountered during build of postbuild_0_Ergnation_rowing: Command 02_install_node_dependencies failed
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 573, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 273, in build
    self._config.commands)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
    raise ToolError(u"Command %s failed" % name)
cfnbootstrap.construction_errors.ToolError: Command 02_install_node_dependencies failed
2021-10-20 10:48:36,266 [ERROR] -----------------------BUILD FAILED!------------------------
2021-10-20 10:48:36,266 [ERROR] Unhandled exception during build: Command 02_install_node_dependencies failed
Traceback (most recent call last):
  File "/opt/aws/bin/cfn-init", line 176, in <module>
    worklog.build(metadata, configSets)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 135, in build
    Contractor(metadata).build(configSets, self)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 561, in build
    self.run_config(config, worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 573, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 273, in build
    self._config.commands)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
    raise ToolError(u"Command %s failed" % name)
cfnbootstrap.construction_errors.ToolError: Command 02_install_node_dependencies failed

我决定检查文件,这个文件显示

02_install_node_dependencies:
    command: "sudo npm install"
    cwd: "/var/app/staging"

似乎安装方法正确 node.js

我已尝试“Sudo yum install -y nodejs”并再次部署,但控制台日志一直显示错误 sudo npm install 即使我将其删除并仍然显示错误 npm issue

02_install_node_dependencies (sudo npm install) failed
2021-10-20 11:48:45,727 [ERROR] Error encountered during build of postbuild_0_Ergnation_rowing: Command 02_install_node_dependencies failed
Traceback (most recent call last):

如果您使用亚马逊 Linux 2 我建议您使用 Hooks,因为您将拥有更多控制权。

根据 docs:

On Amazon Linux 2 platforms, we recommend using Buildfile, Procfile, and platform hooks to configure and run custom code on your environment instances during instance provisioning.

You can still use commands and container commands in .ebextensions configuration files, but they aren't as easy to work with. For example, writing command scripts inside a YAML file can be challenging from a syntax standpoint

在这种情况下,在您的项目中创建以下文件

.platform/hooks/prebuild/install_node_js.sh

文件内容如下:

#!/bin/sh

# Install  Node  alongside with the paired NPM release

if [[ ! "$(node --version)" =~ "v12" ]]; then   
    sudo yum remove -y nodejs npm

    sudo rm -fr /var/cache/yum/*

    sudo yum clean all 

    curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -

    sudo yum install nodejs -y
fi

就是这样,部署您的代码,您应该启动 Node 并且 运行。