我正在将现有应用程序部署到新的Elastic-Beanstalk实例。我们的代码库使用Webpacker来管理我们的前端资产。本地安装webpacker进行开发不是问题,但是尝试在暂存服务器上安装webpacker时仍然遇到问题。
如果我理解正确,则实例需要脚本来安装所需的所有文件(宝石等),这些文件位于我应用程序的.ebextensions目录中。它们在部署期间运行。
我有一个预部署脚本,该脚本似乎可以正常运行,但并不完全。
我想知道如何在实例上安装Webpacker,因为它是“交互式”安装的,如下所示:
conflict config/webpacker.yml
Overwrite /var/app/current/config/webpacker.yml? (enter "h" for help) [Ynaqdh]
现在,有关的文件不应被覆盖,因为它们已经正确设置。
我的问题是,如果我不能回答Y或N,在部署过程中如何在脚本内工作?
我已经尝试ssh
进入实例并按照安装指南进行手动安装,但是据我了解,这不是在实例上安装任何东西的正确方法。我在这里所做的任何更改似乎都丢失了,并且我的实例没有被自动缩放代替。
我的安装脚本:
# Setup linux packages
option_settings:
- option_name: BUNDLE_DISABLE_SHARED_GEMS
value: "1"
- option_name: BUNDLE_PATH
value: "vendor/bundle"
files:
# Replaces the instance script. Need to specify where bundler should be installed
"/opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh":
mode: "000775"
owner: webapp
group: users
content: |
#!/usr/bin/env bash
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
# Source the application's ruby, i.e. 2.6. Otherwise it will be 2.3, which will give this error: `bundler requires Ruby version >= 2.3.0`
. $EB_SUPPORT_DIR/envvars
. $EB_SCRIPT_DIR/use-app-ruby.sh
cd $EB_APP_STAGING_DIR
gem install bundler
echo "bundler installed, installing gems" && pwd
bundle install
echo "gems installed, continuing setup"
# Runs before `./10_bundle_install.sh`:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/setup_instance.sh":
mode: "000775"
owner: webapp
group: users
content: |
#!/usr/bin/env bash
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
# Source the application's ruby, i.e. 2.6. Otherwise it will be 2.3, which will give this error: `bundler requires Ruby version >= 2.3.0`
. $EB_SUPPORT_DIR/envvars
. $EB_SCRIPT_DIR/use-app-ruby.sh
cd $EB_APP_STAGING_DIR
bundle exec bin/rails webpacker:install
echo "done, Installing configs for React"
bundle exec bin/rails webpacker:install:react
我希望捆绑程序安装我们Gemfile中的所有gem,先安装webpacker,然后再安装react,但是我收到此错误;
[Instance: i-0d29490010213b969] Command failed on instance. Return code: 1 Output: (TRUNCATED)...:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
from /opt/rubies/ruby-2.4.6/lib/ruby/site_ruby/2.4.0/rubygems.rb:308:in `activate_bin_path'
from /opt/rubies/ruby-2.4.6/bin/bundle:23:in `<main>'.
该错误表明目录设置不正确,但是我现在完全迷失了方向,需要一些指针。谢谢