I've added the webpacker
gem to my Rails 5.2 app, and now I'm trying to deploy it to a server with Capistrano. The process fails during the deploy:assets:precompile
step with the following error message:
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.
I don't know why it's looking in the shared/config
folder rather than the new release's folder. Presumably I wouldn't want my config to be shared in case I change it and future deploy fails. In that case, the current version of my app would have config that may not be suitable for it.
Here's some of the relevant Capistrano configuration:
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 assets are compiled just fine. I've tried running bundle exec rake assets:precompile
on the server, and it does look in the shared/config
folder. I ran a --trace
and found out that this runs the webpacker:compile
step, which is where it fails.
What can I do to make it look for the config file in the current release's directory (/var/www/myapp/releases/20200805023716/config/webpack/production.js
)?