在AWS Elastic Beanstalk上安装composer时出错



当我部署应用程序时,我正试图通过pipelineLaravel应用程序部署到AWS EB。我在最近的事件中出错。当我检查日志文件的最后100行时,我发现了这个错误:

2020/10/18 00:43:08.443797 [INFO] Executing instruction: Install composer dependencies
2020/10/18 00:43:08.443819 [INFO] installing composer dependencies...
2020/10/18 00:43:08.443859 [INFO] Running command /bin/sh -c composer.phar install --no-ansi --no-interaction 
2020/10/18 00:43:08.482582 [ERROR] An error occurred during execution of command [app-deploy] - [Install composer dependencies]. 
Stop running the command. Error: installing composer dependencies failed with error: Command /bin/sh -c composer.phar install --no-ansi --no-interaction  failed with error exit status 254. Stderr:Sun Oct 18 00:43:08 2020 (12045):
Fatal Error Insufficient shared memory!

我在.ebextensions中有一个名为01_deploy.config的文件,内容如下:

option_settings:
# Point the app root to the public/ folder.
- namespace: aws:elasticbeanstalk:container:php:phpini
option_name: document_root
value: /public
# Set here your php.ini `memory_limit` value.
- namespace: aws:elasticbeanstalk:container:php:phpini
option_name: memory_limit
value: 256M
container_commands:
01_install_composer_dependencies:
command: "sudo php /usr/bin/composer.phar install --no-dev --no-interaction --prefer-dist --optimize-autoloader"
cwd: "/var/app/current"
02_install_node_dependencies:
command: "sudo npm install"
cwd: "/var/app/current"
05_run_migrations:
command: "php artisan migrate --force"
cwd: "/var/app/current"
leader_only: true

编辑:

2020/10/18 10:28:58.643232 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-init -s arn:aws:cloudformation:us-east-2:129692188551:stack/awseb-e-ptmhtrxjzh-stack/af3b2a70-0ce0-11eb-8981-0618bcd9a382 -r AWSEBAutoScalingGroup --region us-east-2 --configsets Infra-EmbeddedPostBuild
2020/10/18 10:29:45.306985 [ERROR] An error occurred during execution of command [app-deploy] - [PostBuildEbExtension]. 
Stop running the command. Error: Container commands build failed. Please refer to /var/log/cfn-init.log for more details.

第2版:针对最后一个错误

2020-10-18 10:39:44,791 [ERROR] Unhandled exception during build: Command 05_run_migrations failed
Traceback (most recent call last):
File "/opt/aws/bin/cfn-init", line 171, in <module>
worklog.build(metadata, configSets)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 129, in build
Contractor(metadata).build(configSets, self)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 530, in build
self.run_config(config, worklog)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 542, in run_config
CloudFormationCarpenter(config, self._auth_config).build(worklog)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 260, in build
changes['commands'] = CommandTool().apply(self._config.commands)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/command_tool.py", line 117, in apply
raise ToolError(u"Command %s failed" % name)
ToolError: Command 05_run_migrations failed

选项1:您可以在本地安装composer,并在将其发送到Elastic Beanstalk 时将供应商文件夹包含在zip归档中

选项2:使用此container_command

command: "sudo php -d memory_limit=-1 /usr/bin/composer.phar install --no-dev --no-interaction --prefer-dist --optimize-autoloader"

最新更新