'Rails, Capistrano - Compilation failed without serving any debug log
I'm trying to deploy my Rails5 app to AWS EC2 instance using Capistrano3.
However when it comes to assets compile, it fails without logging any reasons.
Where should I start with in such case?
Though I set log_level: :debug
to config/deploy/staging.rb
there was no more info. log/capistrano.log
is also the same.
I tried running bundle exec rake assets:precompile RAILS_ENV=staging
in local and succeeded.
"log/capistrano.log" 50149L, 2790165C
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
DEBUG [39e6a15a]
DEBUG [39e6a15a]
DEBUG [39e6a15a] warning " > [email protected]" has incorrect peer dependency "webpack@^4.0.0".
DEBUG [39e6a15a]
[4/4] Building fresh packages...
success Saved lockfile.
DEBUG [39e6a15a]
DEBUG [39e6a15a] Done in 38.64s.
DEBUG [39e6a15a]
DEBUG [39e6a15a] Webpacker is installed 🎉 🍰
DEBUG [39e6a15a]
DEBUG [39e6a15a] Using /home/deploy/apps/neuroweb/releases/20180507061527/config/webpacker.yml file for setting up webpack paths
DEBUG [39e6a15a]
DEBUG [39e6a15a] Compiling…
DEBUG [39e6a15a]
DEBUG [39e6a15a] Compilation failed:
gems I use to deploy:
gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-bundler'
gem 'capistrano-rbenv'
gem 'capistrano3-unicorn'
config/deploy/staging.rb
lock "3.10.2"
set :log_level, :debug
set :repo_url, 'xxxxxxxx'
set :application, 'neuroweb'
set :branch, 'staging'
set :keep_releases, 1
set :rbenv_ruby, '2.4.3'
# Don't change these unless you know what you're doing
set :use_sudo, false
set :deploy_via, :remote_cache
set :deploy_to, "/home/deploy/apps/#{fetch(:application)}"
#set :linked_dirs, %w{vendor/bundle}
#set :linked_files, %w{ config/secrets.yml}
append :linked_files, ".env"
set :rbenv_type, :user
set :ssh_options, {
port: 22,
forward_agent: true,
keys: ['~/.ssh/staging.pem'],
}
set :pty, true
server 'xxxx', roles: [:web, :app, :db], primary: true, user: 'ubuntu'
set :keep_releases, 1
set :stage, :staging
set :rails_env, 'staging'
set :unicorn_exec, -> { "unicorn_rails" }
set :unicorn_config_path, -> { File.join(current_path, "config", "unicorn", "staging.rb") }
set :unicorn_rack_env, 'staging'
set :user, 'ubuntu' #deploy
set :unicorn_pid, "/home/deploy/apps/neuroweb/shared/tmp/pids/unicorn.pid"
namespace :deploy do
desc "Upload secrets.yml to the shared/config directory."
task :secrets_yml do
unless File.exist?('tmp/secrets.yml')
secrets = { fetch(:stage).to_s =>
{ 'secret_key_base' => SecureRandom.hex(64) } }
File.open('tmp/secrets.yml', 'w') do |f|
f.write secrets.to_yaml
end
end
on roles(:app) do
unless test "[ -f #{shared_path}/config/secrets.yml ]"
unless test "[ -d #{shared_path}/config ]"
execute "/bin/mkdir -p #{shared_path}/config/"
end
upload! "tmp/secrets.yml", "#{shared_path}/config/secrets.yml"
end
end
end # secrets_yml
#
# delayed_job
#
task :restart do
invoke 'unicorn:restart'
invoke 'delayed_job:restart'
end
end #deploy
namespace :delayed_job do
def args
fetch(:delayed_job_args, "")
end
def delayed_job_roles
fetch(:delayed_job_server_role, :app)
end
desc 'Stop the delayed_job process'
task :stop do
on roles(delayed_job_roles) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :bundle, :exec, :'bin/delayed_job', :stop
end
end
end
end
desc 'Start the delayed_job process'
task :start do
on roles(delayed_job_roles) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :bundle, :exec, :'bin/delayed_job', args, :start
end
end
end
end
desc 'Restart the delayed_job process'
task :restart do
on roles(delayed_job_roles) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :bundle, :exec, :'bin/delayed_job', args, :restart
end
end
end
end
end
after 'deploy:publishing', 'deploy:restart'
webpacker.yml
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
extensions:
- .jsx
- .vue
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
compile: false
cache_manifest: true
staging:
<<: *default
compile: false
cache_manifest: true
Solution 1:[1]
This is likely caused by running out of memory.
Look in your system log for something like this to confirm:
Out of memory: Kill process 2736 (node) score 222 or sacrifice child
The solution is to upgrade to a machine (or virtual machine) that has more memory.
Solution 2:[2]
Try to run ./bin/webpack direct on the server.
I had the same issue and this showed an error message to me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Robin Daugherty |
Solution 2 | Markus Andreas |