laravel-aws-eb icon indicating copy to clipboard operation
laravel-aws-eb copied to clipboard

"sudo npm run prod" fails with "Exited with error code 243"

Open HilalLko opened this issue 3 years ago • 6 comments

My deployment script (04-deploy-script.config) inside .ebextensions contains following

container_commands:
  00install_packages:
    command: "composer.phar install"
  01migration:
    command: "php artisan migrate --force"
  02npm_install:
    command: "sudo npm install"
  03build_node_assets:
    command: "sudo npm run prod"  
  04optimize_clear:
    command: "php artisan optimize:clear"

Everything goes normal until 02npm_install the very next command to it which is 03build_node_assets building node assets by running sudo npm run prod always fails, and if I remove the step/command fro building assets deployment goes normal and succeeds. PS Instance type running t3.small

Error from cfn-init.log

2022-08-01 08:51:13,354 [ERROR] Command 03build_node_assets (sudo npm run prod) failed
2022-08-01 08:51:13,354 [ERROR] Error encountered during build of postbuild_0_bettrcloudbar_webportal: Command 03build_node_assets failed
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 576, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 276, 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 03build_node_assets failed
2022-08-01 08:51:13,357 [ERROR] -----------------------BUILD FAILED!------------------------
2022-08-01 08:51:13,357 [ERROR] Unhandled exception during build: Command 03build_node_assets 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 137, in build
    Contractor(metadata).build(configSets, self)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 564, in build
    self.run_config(config, worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 576, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 276, 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 03build_node_assets failed

Error from cfn-init-cmd.log

2022-08-01 08:51:12,565 P12210 [INFO] Command 03build_node_assets
2022-08-01 08:51:13,353 P12210 [INFO] -----------------------Command Output-----------------------
2022-08-01 08:51:13,353 P12210 [INFO] 	
2022-08-01 08:51:13,353 P12210 [INFO] 	> prod
2022-08-01 08:51:13,353 P12210 [INFO] 	> npm run production
2022-08-01 08:51:13,353 P12210 [INFO] 	
2022-08-01 08:51:13,353 P12210 [INFO] 	
2022-08-01 08:51:13,353 P12210 [INFO] ------------------------------------------------------------
2022-08-01 08:51:13,353 P12210 [ERROR] Exited with error code 243

Error from eb-engine.log

2022/08/01 08:51:13.393640 [INFO] Error occurred during build: Command 03build_node_assets failed

2022/08/01 08:51:13.393885 [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. 

2022/08/01 08:51:13.393889 [INFO] Executing cleanup logic
2022/08/01 08:51:13.405229 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1659343873393,"severity":"ERROR"}]}]}

HilalLko avatar Aug 01 '22 09:08 HilalLko

@rennokki @maxvisser @Ali-Shaikh

HilalLko avatar Aug 01 '22 09:08 HilalLko

Hi, cool that you tag me but I am not a maintainer of this repo.

I believe this repo does not include a 03build_node_assets script. I would suggest running any build scripts on CI (Github actions, bitbucket pipelines, jenkins/travis) and uploading a fully configured build to Elastic Beanstalk.

If you want help to debug your npm run script you need to include your package.json which contains all npm run commands.

It could be that your instance does not have node/npm installed. A general feedback point: try to do everything manually first before writing scripts.

maxvisser avatar Aug 02 '22 10:08 maxvisser

@maxvisser Haha, I thought you were a contributor on this repo but I'm glad that you're here anyhow.

On your general feedback. 1- npm is installed as expected

npm --version as 8.14.0
node --version as v16.16.0

2- When running npm run prod (with sudo) it sometimes works and sometimes fails as I have tried more than 4 times and 3 times it runs and rest other times it fails.

HilalLko avatar Aug 02 '22 10:08 HilalLko

Hi, cool that you tag me but I am not a maintainer of this repo.

I believe this repo does not include a 03build_node_assets script. I would suggest running any build scripts on CI (Github actions, bitbucket pipelines, jenkins/travis) and uploading a fully configured build to Elastic Beanstalk.

If you want help to debug your npm run script you need to include your package.json which contains all npm run commands.

It could be that your instance does not have node/npm installed. A general feedback point: try to do everything manually first before writing scripts.

#6 PR that brings build node assets into work

HilalLko avatar Aug 02 '22 10:08 HilalLko

I was not aware of these container commands in this repo.

If it works 3 out of 4 times. Try a bigger instance and if you do need a medium or large; please go use github actions or other CI as it would be a bit sad if you only need more memory to build some packages ;)

maxvisser avatar Aug 02 '22 13:08 maxvisser

P.s it is technically correct that I am a contributor; apparently I knew enough to open a pull request and contribute 🚀

maxvisser avatar Aug 02 '22 13:08 maxvisser

Downgraded node version to "12.x" and the issue is resolved

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

Inside rebuild hook "install_latest_node_js.sh". Only the hook name is "latest" although installing old version ;-) image

HilalLko avatar Aug 17 '22 12:08 HilalLko