Как выяснить, как исправить с активами: ошибки перед компиляцией - PullRequest
1 голос
/ 27 февраля 2020

У меня есть пробрем с развертыванием с использованием rails + capistrano + EC2. Я предполагаю, что, вероятно, есть некоторая проблема с ресурсами: прекомпиляция, но не удалось найти никаких полезных ошибок.

Как я могу решить эту проблему? Или я хочу выяснить, что произошло.

ошибки похожи на это


** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:

 DEBUG [5e4911b6] Running if test ! -d /var/www/rails/voc-app/releases/20200227075754; then echo "Directory does not exist '/var/www/rails/voc-app/releases/20200227075754'" 1>&2; false; fi as masaho@18.180.8.25

 DEBUG [5e4911b6] Command: if test ! -d /var/www/rails/voc-app/releases/20200227075754; then echo "Directory does not exist '/var/www/rails/voc-app/releases/20200227075754'" 1>&2; false; fi

 DEBUG [5e4911b6] Finished in 0.084 seconds with exit status 0 (successful).

  INFO [8054a7d6] Running $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as masaho@18.180.8.25

 DEBUG [8054a7d6] Command: cd /var/www/rails/voc-app/releases/20200227075754 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" RAILS_GROUPS="" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )

Я не смог найти, как мне поступить из вышеперечисленных ошибок.

Capfile

require "capistrano/setup"
require "capistrano/deploy"
require "capistrano/rbenv"
require "capistrano/bundler"
require "capistrano/rails/assets"
require "capistrano/rails/migrations"
Dir.glob("lib/capistrano/tasks/*.rb").each { |r| import r }

Deploy.rb

# config valid for current version and patch releases of Capistrano
lock "3.12.0"

set :application, "example"
set :repo_url, "git@github.com:example"
set :branch, 'master'
set :deploy_to, '/var/www/rails/example'
set :linked_files, fetch(:linked_files, []).push('config/master.key')
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
set :keep_releases, 5
set :rbenv_ruby, '2.5.1'
set :log_level, :debug

namespace :deploy do
    desc 'Restart application'
    task :restart do
        invoke 'unicorn:restart'
    end

    desc 'Create database'
    task :db_create do
        on roles(:db) do |host|
            with rails_env: fetch(:rails_env) do
                within current_path do
                    execute :bundle, :exec, :rake, 'db:create'
                end
            end
        end
    end

    desc 'Run seed'
    task :seed do
        on roles(:app) do
            with rails_env: fetch(:rails_env) do
                within current_path do
                    execute :bundle, :exec, :rake, 'db:seed'
                end
            end
        end
    end

    after :publishing, :restert

    after :restart, :clear_cache do
        on roles(:web), in: :groups, limit: 3, wait: 10 do
        end
    end
end

Unicorn.rb

# プロジェクトのルート
rails_root = ENV['RAILS_ROOT'] || File.expand_path('../../', __FILE__)

if ENV['RAILS_ENV'] == 'development' # for pry
  worker_processes 1
else
  worker_processes ENV['UNICORN_WORKER_PROCESSES'].to_i > 0 ? ENV['UNICORN_WORKER_PROCESSES'].to_i : 2
  preload_app true # Unicornの再起動時にダウンタイムなしで再起動

  stderr_path "#{rails_root}/log/unicorn_stderr.log"
  stdout_path "#{rails_root}/log/unicorn_stdout.log"
  pid "#{rails_root}/tmp/pids/unicorn.pid"
end

working_directory rails_root

timeout 300

listen 3000
listen "#{rails_root}/tmp/sockets/unicorn.sock"

before_fork do |server, worker|
  ApplicationRecord.connection.disconnect! if defined?(ApplicationRecord) && ApplicationRecord.connected?

  old_pid = "#{server.config[:pid]}.oldbin"
  if old_pid != server.pid
    begin
      # USR2シグナルを受けると古いプロセスを止める
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end
end

after_fork do |_server, _worker|
  ApplicationRecord.establish_connection if defined?(ApplicationRecord)
end

config / environment / production.rb

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
  # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
  config.require_master_key = true

  # Disable serving static files from the `/public` folder by default since
  # Apache or NGINX already handles this.
  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  # config.assets.compile = false

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Store uploaded files on the local file system (see config/storage.yml for options)
  config.active_storage.service = :local

  # Mount Action Cable outside main process or domain
  # config.action_cable.mount_path = nil
  # config.action_cable.url = 'wss://example.com/cable'
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Use the lowest log level to ensure availability of diagnostic information
  # when problems arise.
  config.log_level = :debug

  # Prepend all log lines with the following tags.
  config.log_tags = [ :request_id ]

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Use a real queuing backend for Active Job (and separate queues per environment)
  # config.active_job.queue_adapter     = :resque
  # config.active_job.queue_name_prefix = "voc-app_#{Rails.env}"

  config.action_mailer.perform_caching = false

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Use a different logger for distributed setups.
  # require 'syslog/logger'
  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger    = ActiveSupport::TaggedLogging.new(logger)
  end

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
end

Имею пытался решить эту проблему часами. Было бы неплохо, если бы у вас было решение.

...