在具有npm,yarn和webpack的弹性beantalk上部署Rails 6应用程序时出现Webpack错误

问题描述 投票:0回答:1

我试图将在生产环境(!)上稳定运行的Rails 6应用程序部署到弹性beantalk(eb)上的第二个新环境中,尽管仅从第一个设置复制了配置,但我无法使其运行。

研究了我可以找到两天的所有资源之后,我目前陷入以下错误compilation failed: webpack not installed

-------------------------------------
/var/log/eb-activity.log
-------------------------------------
  +++ export RUBY_VERSION=2.6.5
  +++ RUBY_VERSION=2.6.5
  +++ export GEM_ROOT=/opt/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0
  +++ GEM_ROOT=/opt/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0
  ++ ((  0 != 0  ))
  + /opt/elasticbeanstalk/support/scripts/check-for-gem.rb puma
  + echo true
[2020-01-09T20:22:02.966Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/AppDeployPreHook] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/pre.
[2020-01-09T20:22:02.966Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild] : Starting activity...
[2020-01-09T20:22:10.381Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Starting activity...
[2020-01-09T20:22:10.462Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_XXX] : Starting activity...
[2020-01-09T20:22:23.059Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_XXX/Command 01_restart_nginx] : Starting activity...
[2020-01-09T20:22:24.293Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_XXX/Command 01_restart_nginx] : Completed activity. Result:
  nginx: [warn] conflicting server name "_" on 0.0.0.0:80, ignored
  nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
  nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
  Stopping nginx: [  OK  ]
  Starting nginx: nginx: [warn] conflicting server name "_" on 0.0.0.0:80, ignored
  nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
  nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
  [  OK  ]

[2020-01-09T20:22:24.293Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_XXX] : Completed activity.
[2020-01-09T20:22:24.375Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX] : Starting activity...
[2020-01-09T20:22:37.045Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX/Command 10_install_webpack] : Starting activity...
[2020-01-09T20:25:12.155Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX/Command 10_install_webpack] : Completed activity. Result:
  npm notice created a lockfile as package-lock.json. You should commit this file.
  npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
  npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

  + [email protected]
  added 322 packages from 197 contributors and audited 4227 packages in 144.209s

  3 packages are looking for funding
  run `npm fund` for details

  found 0 vulnerabilities


[2020-01-09T20:25:13.256Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX/Command 11_precompile] : Starting activity...
[2020-01-09T20:30:24.349Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX/Command 11_precompile] : Activity execution failed, because: yarn install v1.21.1
  warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
  [1/4] Resolving packages...
  [2/4] Fetching packages...
  info [email protected]: The platform "linux" is incompatible with this module.
  info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
  [3/4] Linking dependencies...
  [4/4] Building fresh packages...
  success Saved lockfile.
  Done in 162.47s.
  yarn install v1.21.1
  warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
  [1/4] Resolving packages...
  [2/4] Fetching packages...
  info [email protected]: The platform "linux" is incompatible with this module.
  info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
  [3/4] Linking dependencies...
  [4/4] Building fresh packages...
  Done in 83.51s.
  I, [2020-01-09T20:29:36.608192 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/manifest-cadda289ef9c70eaa0879a36e6263cb33f7523a16b3ef862e0b8609cdc2bdab1.js
  I, [2020-01-09T20:29:36.609243 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/manifest-cadda289ef9c70eaa0879a36e6263cb33f7523a16b3ef862e0b8609cdc2bdab1.js.gz
  I, [2020-01-09T20:29:36.609422 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-c0be3de839559053bb0a9486d5645ccba7a7452f6ef0370ee498e1fa59e364b2.png
  I, [2020-01-09T20:29:36.609592 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-469a46bb9645a42d499c7f74ee69ffad4176e08c4373b6fe67a418e8289f3d83.png
  I, [2020-01-09T20:29:36.609775 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-e57001fd85a8e1f4da2bb4bbd309a7d880a9d18e3447d743190ff9befb86413f.jpg
  I, [2020-01-09T20:29:36.610062 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/application-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css
  I, [2020-01-09T20:29:36.610155 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/application-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css.gz
  I, [2020-01-09T20:29:36.610249 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/wall_street-e57001fd85a8e1f4da2bb4bbd309a7d880a9d18e3447d743190ff9befb86413f.jpg
  I, [2020-01-09T20:29:36.610500 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/asset-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
  I, [2020-01-09T20:29:36.610582 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/asset-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
  I, [2020-01-09T20:29:36.690087 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
  I, [2020-01-09T20:29:36.690356 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
  I, [2020-01-09T20:29:36.690743 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/main-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css
  I, [2020-01-09T20:29:36.690957 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/main-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css.gz
  I, [2020-01-09T20:29:36.691548 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/round-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
  I, [2020-01-09T20:29:36.772944 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/round-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
  Compiling...
  Compilation failed:

  webpack not installed

  Install webpack to start bundling: [32m
  $ npm install --save-dev webpack


   (ElasticBeanstalk::ExternalInvocationError)


[2020-01-09T20:30:24.349Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX/Command 11_precompile] : Activity failed.
[2020-01-09T20:30:24.349Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX] : Activity failed.
[2020-01-09T20:30:24.349Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Activity failed.
[2020-01-09T20:30:25.008Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild] : Activity failed.
[2020-01-09T20:30:25.008Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0] : Activity failed.
[2020-01-09T20:30:25.009Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11] : Completed activity. Result:
  Application update - Command CMD-AppDeploy failed
[2020-01-09T20:36:59.175Z] INFO  [5013]  - [CMD-TailLogs] : Starting activity...
[2020-01-09T20:36:59.175Z] INFO  [5013]  - [CMD-TailLogs/AddonsBefore] : Starting activity...
[2020-01-09T20:36:59.175Z] INFO  [5013]  - [CMD-TailLogs/AddonsBefore] : Completed activity.
[2020-01-09T20:36:59.175Z] INFO  [5013]  - [CMD-TailLogs/TailLogs] : Starting activity...
[2020-01-09T20:36:59.175Z] INFO  [5013]  - [CMD-TailLogs/TailLogs/TailLogs] : Starting activity...

-------------------------------------
/var/log/eb-commandprocessor.log
-------------------------------------
[2020-01-09T20:15:53.363Z] DEBUG [1508]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_API||_Commands..
[2020-01-09T20:15:53.364Z] INFO  [1508]  : Found enabled addons: ["logpublish", "logstreaming"].
[2020-01-09T20:15:53.444Z] INFO  [1508]  : Updating Command definition of addon logpublish.
[2020-01-09T20:15:53.444Z] INFO  [1508]  : Updating Command definition of addon logstreaming.
[2020-01-09T20:15:53.444Z] DEBUG [1508]  : Retrieving metadata for key: AWS::CloudFormation::Init||Infra-WriteApplication2||files..
[2020-01-09T20:15:53.445Z] DEBUG [1508]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||ManifestFileS3Key..
[2020-01-09T20:15:56.071Z] INFO  [1508]  : Loading manifest from bucket 'elasticbeanstalk-eu-west-1-511205900284' using computed S3 key 'resources/environments/e-zcsy2pgich/_runtime/versions/manifest_1578600905237'.
[2020-01-09T20:15:56.520Z] INFO  [1508]  : Updated manifest cache: deployment ID 11 and serial 18.
[2020-01-09T20:15:56.520Z] DEBUG [1508]  : Loaded definition of Command CMD-AppDeploy.
[2020-01-09T20:15:56.520Z] INFO  [1508]  : Executing Application update
[2020-01-09T20:15:56.520Z] INFO  [1508]  : Executing command: CMD-AppDeploy...
[2020-01-09T20:15:56.520Z] INFO  [1508]  : Executing command CMD-AppDeploy activities...
[2020-01-09T20:15:56.520Z] DEBUG [1508]  : Setting environment variables..
[2020-01-09T20:15:56.520Z] INFO  [1508]  : Running AddonsBefore for command CMD-AppDeploy...
[2020-01-09T20:15:59.632Z] DEBUG [1508]  : Running stages of Command CMD-AppDeploy from stage 0 to stage 1...
[2020-01-09T20:15:59.632Z] INFO  [1508]  : Running stage 0 of command CMD-AppDeploy...
[2020-01-09T20:15:59.632Z] INFO  [1508]  : Running leader election...
[2020-01-09T20:16:07.059Z] INFO  [1508]  : Instance is Leader.
[2020-01-09T20:16:07.059Z] DEBUG [1508]  : Loaded 5 actions for stage 0.
[2020-01-09T20:16:07.059Z] INFO  [1508]  : Running 1 of 5 actions: DownloadSourceBundle...
[2020-01-09T20:16:14.038Z] INFO  [1508]  : Running 2 of 5 actions: EbExtensionPreBuild...
[2020-01-09T20:18:12.566Z] INFO  [1508]  : Running 3 of 5 actions: AppDeployPreHook...
[2020-01-09T20:22:02.966Z] INFO  [1508]  : Running 4 of 5 actions: EbExtensionPostBuild...
[2020-01-09T20:30:25.008Z] ERROR [1508]  : Command execution failed: Activity failed. (ElasticBeanstalk::ActivityFatalError)
caused by: yarn install v1.21.1
  warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
  [1/4] Resolving packages...
  [2/4] Fetching packages...
  info [email protected]: The platform "linux" is incompatible with this module.
  info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
  [3/4] Linking dependencies...
  [4/4] Building fresh packages...
  success Saved lockfile.
  Done in 162.47s.
  yarn install v1.21.1
  warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
  [1/4] Resolving packages...
  [2/4] Fetching packages...
  info [email protected]: The platform "linux" is incompatible with this module.
  info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
  [3/4] Linking dependencies...
  [4/4] Building fresh packages...
  Done in 83.51s.
  I, [2020-01-09T20:29:36.608192 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/manifest-cadda289ef9c70eaa0879a36e6263cb33f7523a16b3ef862e0b8609cdc2bdab1.js
  I, [2020-01-09T20:29:36.609243 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/manifest-cadda289ef9c70eaa0879a36e6263cb33f7523a16b3ef862e0b8609cdc2bdab1.js.gz
  I, [2020-01-09T20:29:36.609422 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-c0be3de839559053bb0a9486d5645ccba7a7452f6ef0370ee498e1fa59e364b2.png
  I, [2020-01-09T20:29:36.609592 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-469a46bb9645a42d499c7f74ee69ffad4176e08c4373b6fe67a418e8289f3d83.png
  I, [2020-01-09T20:29:36.609775 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-e57001fd85a8e1f4da2bb4bbd309a7d880a9d18e3447d743190ff9befb86413f.jpg
  I, [2020-01-09T20:29:36.610062 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/application-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css
  I, [2020-01-09T20:29:36.610155 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/application-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css.gz
  I, [2020-01-09T20:29:36.610249 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-e57001fd85a8e1f4da2bb4bbd309a7d880a9d18e3447d743190ff9befb86413f.jpg
  I, [2020-01-09T20:29:36.610500 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/asset-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
  I, [2020-01-09T20:29:36.610582 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/asset-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
  I, [2020-01-09T20:29:36.690087 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
  I, [2020-01-09T20:29:36.690356 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
  I, [2020-01-09T20:29:36.690743 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/main-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css
  I, [2020-01-09T20:29:36.690957 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/main-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css.gz
  I, [2020-01-09T20:29:36.691548 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/round-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
  I, [2020-01-09T20:29:36.772944 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/round-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
  Compiling...
  Compilation failed:

  webpack not installed

  Install webpack to start bundling: [32m
  $ npm install --save-dev webpack


   (ElasticBeanstalk::ExternalInvocationError)


[2020-01-09T20:30:25.009Z] ERROR [1508]  : Command CMD-AppDeploy failed!
[2020-01-09T20:30:25.086Z] INFO  [1508]  : Command processor returning results: 
{"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"(TRUNCATED)...NFO -- : Writing /var/app/ondeck/public/assets/round-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz\nCompiling...\nCompilation failed:\n\nwebpack not installed\n\nInstall webpack to start bundling: \u001b[32m\n$ npm install --save-dev webpack. \ncontainer_command 11_precompile in .ebextensions/yarn.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI","returncode":1,"events":[]}],"truncated":"true"}

逻辑上,我尝试一次又一次安装webpack,通常应该已经通过ebextensions文件yarn.config完成了此安装:

commands:
  # 01_remove_clean_and_install_latest_nodejs:
    # run this command from /tmp directory
    # cwd: /tmp
    # test: '[ -f /usr/bin/node ] && echo "remove previous node"'
    # command: 'sudo yum remove -y nodejs | sudo rm /etc/yum.repos.d/nodesource*'

  02_node_get:
    # run this command from /tmp directory
    cwd: /tmp
    # flag -y for no-interaction installation
    command: 'sudo curl --silent --location https://rpm.nodesource.com/setup_13.x | sudo bash -'

  03_node_install:
    # run this command from /tmp directory
    cwd: /tmp
    command: 'sudo yum -y install nodejs'

  04_yarn_get:
    # run this command from /tmp directory
    cwd: /tmp
    # don't run the command if yarn is already installed (file /usr/bin/yarn exists)
    test: '[ ! -f /usr/bin/yarn ] && echo "yarn not installed"'
    command: 'sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo'

  05_yarn_install:
    # run this command from /tmp directory
    cwd: /tmp
    test: '[ ! -f /usr/bin/yarn ] && echo "yarn not installed"'
    command: 'sudo yum -y install yarn'

  06_mkdir_webapp_dir:
    command: mkdir /home/webapp
    ignoreErrors: true

  07_chown_webapp_dir:
    command: chown webapp:webapp /home/webapp
    ignoreErrors: true

  08_chmod_webapp_dir:
    command: chmod 700 /home/webapp
    ignoreErrors: true

  09_update_bundler:
    command: gem update bundler
    ignoreErrors: true

container_commands:

  10_install_webpack:
    command: "sudo npm install --save-dev webpack"

  11_precompile:
    command: "bundle exec rake assets:precompile"

我的其他设置是eb中的RAILS_SKIP_ASSET_COMPILATION=true

我尝试通过npm和yarn将ssh-sing到机器中后,手动安装webpack,有无sudo,但无济于事...

每个eb deploy大约需要20分钟,然后由于上述错误而进入“严重”状态。

编辑

出于某些奇怪的原因,除了在Gemfile中包含bundle exec rails webpacker:install之外,我现在还可以运行它。仍然不满意该设置,但至少现在可以使用

npm webpack amazon-elastic-beanstalk yarn ruby-on-rails-6
1个回答
1
投票
更新:我们有两个bundle install期间未安装的elasticsearch gem,但是从我们的gemfile中删除它们可以使部署顺利进行。我们在本地也注意到了这个问题,其中一个bundle install挂在“解决依赖项”上大约4个小时,这大约是我们的部署成功完成所花费的时间。我将开始检查宝石。

我不确定这是否相关,但是目前有一个类似的问题,AWS支持尚待解决,该问题类似,在挂起AWS自己的某些PreDeploy挂钩脚本(即检查Puma的脚本)后,部署似乎失败了。我们无法成功地将已知的有效应用程序代码捆绑克隆或部署到任何新实例或现有实例。该问题于2019年1月7日开始。

© www.soinside.com 2019 - 2024. All rights reserved.