【发布时间】:2020-08-05 02:48:36
【问题描述】:
我已将webpacker gem 添加到我的Rails 5.2 应用程序中,现在我正尝试将它部署到带有Capistrano 的服务器上。该过程在deploy:assets:precompile 步骤中失败,并显示以下错误消息:
DEBUG [f2c62805] Command: cd /var/www/myapp/releases/20200805023716 && ( export RAILS_ENV="production" RAILS_GROUPS="" ; /usr/local/rvm/bin/rvm 2.5.7 do bundle exec rake assets:precompile )
DEBUG [f2c62805] Compiling...
DEBUG [f2c62805] Compilation failed:
webpack config /var/www/myapp/shared/config/webpack/production.js not found, please run 'bundle exec rails webpacker:install' to install Webpacker with default configs or add the missing config file for your custom environment.
我不知道为什么它在 shared/config 文件夹中而不是新版本的文件夹中查找。大概我不希望我的配置被共享,以防我更改它并且未来的部署失败。在这种情况下,我的应用程序的当前版本可能会有不适合它的配置。
以下是一些相关的 Capistrano 配置:
set :config_files, ['config/boot.rb', 'config/database.yml', 'config/secrets.yml']
set :bin_files, ['bin/bundle', 'bin/delayed_job', 'bin/rails', 'bin/rake', 'bin/webpack']
# Tells Capistrano to store config/database.yml file inside a directory called /shared, which is meant for any files
# we want to persist between deploys
set :linked_files, fetch(:linked_files, []) + fetch(:config_files)
# Directories that are meant to persist between deploys, and they will also be stored inside /shared
set :linked_dirs, fetch(:linked_dirs, []).push('bin', 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads')
Sprockets 资产编译得很好。我试过在服务器上运行bundle exec rake assets:precompile,它确实在shared/config 文件夹中查找。我运行了--trace,发现它运行了webpacker:compile 步骤,这就是它失败的地方。
如何让它在当前版本的目录 (/var/www/myapp/releases/20200805023716/config/webpack/production.js) 中查找配置文件?
【问题讨论】:
标签: ruby-on-rails capistrano webpacker