I am trying to deploy a Ruby On Rails app to an aws instance. The original problem was that the deployment process was stuck at compiling assets. And seems that this was a common scenario that other developers tend to workaround by removing the compile step, compile the assets locally and then rsync them to the remote server. So I decided to give it a try following what is suggested here: Rails 5.1 capistrano is stuck at webpacker compiling assets After checking this question: pipeline assets precompile disable does not seem to work I found how to skip assets precompile by removing require 'capistrano/rails' from my Capfile:
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
# require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rails/migrations'
require 'capistrano/rbenv'
set :rbenv_type, :user
set :rbenv_ruby, '2.6.5'
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
before 'deploy:updated', 'deploy:rsync_assets'
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
Here deploy:rsync_assets is invoked before deploy:updated. deploy:rsync_assets is supossed to:
- exec locally asstes:precompile
- rsync remote
For the rsync there was a problem with "skipping non-regular file" because a lot of them are symlinks: rsync prints "skipping non-regular file" for what appears to be a regular directory fixed adding -l to the command to copy the symlinks. Now the problem is that: ActionView::Template::Error (The asset "application.css" is not present in the asset pipeline.) There is an application.scss but there never was an application.css file. The app works fine locally, and also in other servers(render and heroku). Even I accomplished to deploy it in aws once, always without an application.css so I can figure out why is asking for it now? Here is my deploy.rb:
# config valid for current version and patch releases of Capistrano
lock "~> 3.17.2"
require 'capistrano-db-tasks'
set :application, 'my_app'
set :repo_url, 'git@github.com:develaper/my_app.git'
set :deploy_to, '/home/deploy/my_app'
set :branch, 'develop'
set :bundle_flags, "--deployment"
# set :branch, ENV['BRANCH'] if ENV['BRANCH']
set :linked_files, %w{config/database.yml config/master.key}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/packs public/system}
set :keep_releases, 3
set :keep_assets, 3
set :db_local_clean, true
set :db_remote_clean, true
namespace :deploy do
desc 'locally precompile and rsync'
task :rsync_assets do
host = "myhost.compute-1.amazonaws.com"
app_folder = "/home/deploy/my_app"
puts Airbrussh::Colors.yellow('** Skipping asset compile.')
rsync_host = host.to_s
run_locally do
execute "RAILS_ENV=production rake assets:precompile"
execute "rsync -l --recursive --times --rsh=ssh --compress --human-readable --progress --delete ./public/ deploy@#{rsync_host}:#{app_folder}/shared/public/"
# execute "rm -rf public/assets"
# execute "rm -rf tmp/cache/assets"
end
end
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
The result of running rails webpacker:info
Ruby: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
Rails: 6.1.0
Webpacker: 4.3.0
Node: v12.22.12
Yarn: 1.22.19
@rails/webpacker:
ww_app@0.1.0 /home/my_user/Development/my_app
└── @rails/webpacker@4.2.2
Is bin/webpack present?: true
Is bin/webpack-dev-server present?: true
Is bin/yarn present?: true
As suggested here: Rails: Webpacker 4.2 can't find application in /app/public/packs/manifest.json heroku
I changed my config/environments/production.rb
config.assets.compile = false
and config/webpacker.yml
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: true
# Extract and emit a css file
extract_css: false