我正在尝试将 Ruby-on-Rails 项目部署到我自己的专用服务器(ubuntu 2004.2022.1.0)。
我正在使用 Ruby 3.0.2、Rbenv、Capistrano 3.17.1、Puma、Nginx。
但是我在部署步骤上失败了。
如果有人能帮我解决这个问题,我会很高兴。
这里是使用命令时的错误信息:
cap 生产部署 --trace
00:20 bundler:install
The Gemfile's dependencies are satisfied, skipping installation
** Execute deploy:updated
** Invoke deploy:compile_assets (first_time)
** Invoke deploy:set_rails_env
** Execute deploy:compile_assets
** Invoke deploy:assets:precompile (first_time)
** Execute deploy:assets:precompile
00:20 deploy:assets:precompile
01 bundle exec rake assets:precompile
01 rake aborted!
01 ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
/home/deploy/deploy.fr/shared/bundle/ruby/3.0.0/gems/activesupport-7.0.3.1/lib/active_support/message_encryptor.rb:209:in `rescue in _decrypt'/home/deploy/deploy.fr/shared/bundle/ruby/3.0.0/gems/activesupport-7.0.3.1/lib/active_support/message_encryptor.rb:186:in `_decrypt'
/home/deploy/deploy.fr/shared/bundle/ruby/3.0.0/gems/activesupport-7.0.3.1/lib/active_support/message_encryptor.rb:160:in `decrypt_and_verify'
Caused by:
OpenSSL::Cipher::CipherError:
/home/deploy/deploy.fr/shared/bundle/ruby/3.0.0/gems/activesupport-7.0.3.1/lib/active_support/message_encryptor.rb:204:in `final'
/home/deploy/deploy.fr/shared/bundle/ruby/3.0.0/gems/activesupport-7.0.3.1/lib/active_support/message_encryptor.rb:204:in `_decrypt'
/home/deploy/deploy.fr/shared/bundle/ruby/3.0.0/gems/activesupport-7.0.3.1/lib/active_support/message_encryptor.rb:160:in `decrypt_and_verify'(See full trace by running task with --trace)
#<Thread:0x00005638e7884638 /home/deploy/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/sshkit-1.21.3/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
/home/deploy/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/sshkit-1.21.3/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as [email protected]: rake exit status: 1 (SSHKit::Runner::ExecuteError)
rake stdout: Nothing written
rake stderr: rake aborted!
ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
/home/deploy/deploy.fr/shared/bundle/ruby/3.0.0/gems/activesupport-7.0.3.1/lib/active_support/message_encryptor.rb:209:in `rescue in
...
capistrano.log(只有失败的行)
DEBUG [c2a2b569] Command: [ -f /home/deploy/deploy.fr/current/REVISION ]
DEBUG [c2a2b569] Finished in 0.105 seconds with exit status 1 (failed).
DEBUG [0c97213c] Running [ -L /home/deploy/deploy.fr/releases/20220908112310/config/database.yml ] as [email protected]
DEBUG [0c97213c] Command: [ -L /home/deploy/deploy.fr/releases/20220908112310/config/database.yml ]
DEBUG [0c97213c] Finished in 0.111 seconds with exit status 1 (failed).
DEBUG [9a1b2e0b] Running [ -f /home/deploy/deploy.fr/releases/20220908112310/config/database.yml ] as [email protected]
DEBUG [9a1b2e0b] Command: [ -f /home/deploy/deploy.fr/releases/20220908112310/config/database.yml ]
DEBUG [9a1b2e0b] Finished in 0.079 seconds with exit status 1 (failed).
DEBUG [2c6d0708] Running [ -L /home/deploy/deploy.fr/releases/20220908112310/config/secrets.yml ] as [email protected]
DEBUG [2c6d0708] Command: [ -L /home/deploy/deploy.fr/releases/20220908112310/config/secrets.yml ]
DEBUG [2c6d0708] Finished in 0.068 seconds with exit status 1 (failed).
DEBUG [d332b2bb] Running [ -f /home/deploy/deploy.fr/releases/20220908112310/config/secrets.yml ] as [email protected]
DEBUG [d332b2bb] Command: [ -f /home/deploy/deploy.fr/releases/20220908112310/config/secrets.yml ]
DEBUG [d332b2bb] Finished in 0.115 seconds with exit status 1 (failed).
DEBUG [c1307965] Running [ -L /home/deploy/deploy.fr/releases/20220908112310/config/master.key ] as [email protected]
DEBUG [c1307965] Command: [ -L /home/deploy/deploy.fr/releases/20220908112310/config/master.key ]
DEBUG [c1307965] Finished in 0.114 seconds with exit status 1 (failed).
DEBUG [3098a995] Running [ -f /home/deploy/deploy.fr/releases/20220908112310/config/master.key ] as [email protected]
DEBUG [3098a995] Command: [ -f /home/deploy/deploy.fr/releases/20220908112310/config/master.key ]
DEBUG [3098a995] Finished in 0.074 seconds with exit status 1 (failed).
DEBUG [ca0c9dee] Running [ -L /home/deploy/deploy.fr/releases/20220908112310/log ] as [email protected]
DEBUG [ca0c9dee] Command: [ -L /home/deploy/deploy.fr/releases/20220908112310/log ]
DEBUG [ca0c9dee] Finished in 0.118 seconds with exit status 1 (failed).
DEBUG [8bba8809] Running [ -L /home/deploy/deploy.fr/releases/20220908112310/tmp/pids ] as [email protected]
DEBUG [8bba8809] Command: [ -L /home/deploy/deploy.fr/releases/20220908112310/tmp/pids ]
DEBUG [8bba8809] Finished in 0.114 seconds with exit status 1 (failed).
DEBUG [2a5f23c1] Finished in 0.114 seconds with exit status 1 (failed).
DEBUG [a2b2d01b] Running [ -d /home/deploy/deploy.fr/releases/20220908112310/tmp/cache ] as [email protected]
DEBUG [a2b2d01b] Command: [ -d /home/deploy/deploy.fr/releases/20220908112310/tmp/cache ]
DEBUG [a2b2d01b] Finished in 0.072 seconds with exit status 1 (failed).
DEBUG [b2059567] Running [ -L /home/deploy/deploy.fr/releases/20220908112310/tmp/sockets ] as [email protected]
DEBUG [b2059567] Command: [ -L /home/deploy/deploy.fr/releases/20220908112310/tmp/sockets ]
DEBUG [b2059567] Finished in 0.073 seconds with exit status 1 (failed).
DEBUG [eef74f83] Running [ -d /home/deploy/deploy.fr/releases/20220908112310/tmp/sockets ] as [email protected]
DEBUG [eef74f83] Command: [ -d /home/deploy/deploy.fr/releases/20220908112310/tmp/sockets ]
DEBUG [eef74f83] Finished in 0.115 seconds with exit status 1 (failed).
DEBUG [e4ed291f] Running [ -L /home/deploy/deploy.fr/releases/20220908112310/tmp/webpacker ] as [email protected]
DEBUG [e4ed291f] Command: [ -L /home/deploy/deploy.fr/releases/20220908112310/tmp/webpacker ]
DEBUG [e4ed291f] Finished in 0.118 seconds with exit status 1 (failed).
DEBUG [9a3182f0] Running [ -d /home/deploy/deploy.fr/releases/20220908112310/tmp/webpacker ] as [email protected]
DEBUG [9a3182f0] Command: [ -d /home/deploy/deploy.fr/releases/20220908112310/tmp/webpacker ]
DEBUG [9a3182f0] Finished in 0.074 seconds with exit status 1 (failed).
DEBUG [50e4ca0b] Running [ -L /home/deploy/deploy.fr/releases/20220908112310/vendor ] as [email protected]
DEBUG [50e4ca0b] Command: [ -L /home/deploy/deploy.fr/releases/20220908112310/vendor ]
DEBUG [50e4ca0b] Finished in 0.073 seconds with exit status 1 (failed).
DEBUG [2224ab16] Running [ -L /home/deploy/deploy.fr/releases/20220908112310/storage ] as [email protected]
DEBUG [2224ab16] Command: [ -L /home/deploy/deploy.fr/releases/20220908112310/storage ]
DEBUG [2224ab16] Finished in 0.073 seconds with exit status 1 (failed).
DEBUG [9dbdf796] Running [ -L /home/deploy/deploy.fr/releases/20220908112310/public/assets ] as [email protected]
DEBUG [9dbdf796] Command: [ -L /home/deploy/deploy.fr/releases/20220908112310/public/assets ]
DEBUG [9dbdf796] Finished in 0.074 seconds with exit status 1 (failed).
DEBUG [f5079584] Running [ -d /home/deploy/deploy.fr/releases/20220908112310/public/assets ] as [email protected]
DEBUG [f5079584] Command: [ -d /home/deploy/deploy.fr/releases/20220908112310/public/assets ]
DEBUG [f5079584] Finished in 0.118 seconds with exit status 1 (failed).
部署.rb:
# deploy.rb
# config valid for current version and patch releases of Capistrano
lock "~> 3.17.1"
set :application, "deploy.fr"
# set :repo_url, "[email protected]:me/my_repo.git"
set :repo_url, "/home/deploy/git_deploy_fr_nf"
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/home/deploy/deploy.fr"
# Default value for :format is :airbrussh.
# set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
append :linked_files, "config/database.yml", "config/secrets.yml", "config/master.key"
# Default value for linked_dirs is []
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "tmp/webpacker", "vendor", "storage"
set :nginx_config_name, 'deploy_fr_nf'
set :nginx_server_name, 'deploy.fr'
set :puma_workers, 2 # nombre de coeurs du serveur dédié
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }
# Default value for keep_releases is 5
# set :keep_releases, 5
# Uncomment the following to require manually verifying the host key before first deploy.
# set :ssh_options, verify_host_key: :secure
宝石文件:
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.0.2"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.3", ">= 7.0.3.1"
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"
# Use postgresql as the database for Active Record
gem "pg", "~> 1.4.3"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"
# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false
# Use Sass to process CSS
# gem "sassc-rails"
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end
group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
# déploiement
gem 'capistrano', '~> 3.17', '>= 3.17'
gem 'capistrano-rails', '~> 1.6'
gem 'capistrano-rbenv', '~> 2.2'
gem 'capistrano3-puma' , group: :development
gem 'ed25519', '>= 1.2', '< 2.0'
gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0'
end
group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"
end
Capfile
# Capfile
# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
# Load the SCM plugin appropriate to your project:
#
# require 'capistrano/scm/hg'
# install_plugin Capistrano::SCM::Hg
# or
# require 'capistrano/scm/svn'
# install_plugin Capistrano::SCM::Svn
# or
# install_plugin Capistrano::SCM::Git
# install_plugin Capistrano::Puma
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
# require 'capistrano/rbenv'
# require 'capistrano/rvm'
require 'capistrano/rails'
require 'capistrano/bundler'
# Important: Puma configuration should come after rvm or rbenv
require 'capistrano/puma'
install_plugin Capistrano::Puma # Default puma tasks
install_plugin Capistrano::Puma::Workers # if you want to control the workers (in cluster mode)
install_plugin Capistrano::Puma::Jungle # if you need the jungle tasks
install_plugin Capistrano::Puma::Monit # if you need the monit tasks
require 'capistrano/puma/nginx'
install_plugin Capistrano::Puma::Nginx # if you want to upload a nginx site template
# require 'capistrano/chruby'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'
# require 'capistrano/passenger'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.3.1)
actionpack (= 7.0.3.1)
activesupport (= 7.0.3.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.3.1)
actionpack (= 7.0.3.1)
activejob (= 7.0.3.1)
activerecord (= 7.0.3.1)
activestorage (= 7.0.3.1)
activesupport (= 7.0.3.1)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.3.1)
actionpack (= 7.0.3.1)
actionview (= 7.0.3.1)
activejob (= 7.0.3.1)
activesupport (= 7.0.3.1)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.3.1)
actionview (= 7.0.3.1)
activesupport (= 7.0.3.1)
rack (~> 2.0, >= 2.2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.3.1)
actionpack (= 7.0.3.1)
activerecord (= 7.0.3.1)
activestorage (= 7.0.3.1)
activesupport (= 7.0.3.1)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.3.1)
activesupport (= 7.0.3.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.3.1)
activesupport (= 7.0.3.1)
globalid (>= 0.3.6)
activemodel (7.0.3.1)
activesupport (= 7.0.3.1)
activerecord (7.0.3.1)
activemodel (= 7.0.3.1)
activesupport (= 7.0.3.1)
activestorage (7.0.3.1)
actionpack (= 7.0.3.1)
activejob (= 7.0.3.1)
activerecord (= 7.0.3.1)
activesupport (= 7.0.3.1)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.3.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
airbrussh (1.4.1)
sshkit (>= 1.6.1, != 1.7.0)
bcrypt_pbkdf (1.1.0)
bindex (0.8.1)
bootsnap (1.13.0)
msgpack (~> 1.2)
builder (3.2.4)
capistrano (3.17.1)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (>= 1.9.0)
capistrano-bundler (2.1.0)
capistrano (~> 3.1)
capistrano-rails (1.6.2)
capistrano (~> 3.1)
capistrano-bundler (>= 1.1, < 3)
capistrano-rbenv (2.2.0)
capistrano (~> 3.1)
sshkit (~> 1.3)
capistrano3-puma (5.2.0)
capistrano (~> 3.7)
capistrano-bundler
puma (>= 4.0, < 6.0)
capybara (3.37.1)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (4.1.0)
concurrent-ruby (1.1.10)
crass (1.0.6)
debug (1.6.2)
irb (>= 1.3.6)
reline (>= 0.3.1)
digest (3.1.0)
ed25519 (1.3.0)
erubi (1.11.0)
globalid (1.0.0)
activesupport (>= 5.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
importmap-rails (1.1.5)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.5.11)
irb (1.4.1)
reline (>= 0.3.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
loofah (2.18.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.2)
minitest (5.16.3)
msgpack (1.5.6)
net-imap (0.2.3)
digest
net-protocol
strscan
net-pop (0.1.1)
digest
net-protocol
timeout
net-protocol (0.1.3)
timeout
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-smtp (0.3.1)
digest
net-protocol
timeout
net-ssh (7.0.1)
nio4r (2.5.8)
nokogiri (1.13.8-x86_64-linux)
racc (~> 1.4)
pg (1.4.3)
public_suffix (5.0.0)
puma (5.6.5)
nio4r (~> 2.0)
racc (1.6.0)
rack (2.2.4)
rack-test (2.0.2)
rack (>= 1.3)
rails (7.0.3.1)
actioncable (= 7.0.3.1)
actionmailbox (= 7.0.3.1)
actionmailer (= 7.0.3.1)
actionpack (= 7.0.3.1)
actiontext (= 7.0.3.1)
actionview (= 7.0.3.1)
activejob (= 7.0.3.1)
activemodel (= 7.0.3.1)
activerecord (= 7.0.3.1)
activestorage (= 7.0.3.1)
activesupport (= 7.0.3.1)
bundler (>= 1.15.0)
railties (= 7.0.3.1)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.3)
loofah (~> 2.3)
railties (7.0.3.1)
actionpack (= 7.0.3.1)
activesupport (= 7.0.3.1)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
regexp_parser (2.5.0)
reline (0.3.1)
io-console (~> 0.5)
rexml (3.2.5)
rubyzip (2.3.2)
selenium-webdriver (4.4.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sprockets (4.1.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sshkit (1.21.3)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
stimulus-rails (1.1.0)
railties (>= 6.0.0)
strscan (3.0.4)
thor (1.2.1)
timeout (0.3.0)
turbo-rails (1.1.1)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
web-console (4.2.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webdrivers (5.0.0)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0)
websocket (1.2.9)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.0)
PLATFORMS
x86_64-linux
DEPENDENCIES
bcrypt_pbkdf (>= 1.0, < 2.0)
bootsnap
capistrano (~> 3.17, >= 3.17)
capistrano-rails (~> 1.6)
capistrano-rbenv (~> 2.2)
capistrano3-puma
capybara
debug
ed25519 (>= 1.2, < 2.0)
importmap-rails
jbuilder
pg (~> 1.4.3)
puma (~> 5.0)
rails (~> 7.0.3, >= 7.0.3.1)
selenium-webdriver
sprockets-rails
stimulus-rails
turbo-rails
tzinfo-data
web-console
webdrivers
RUBY VERSION
ruby 3.0.2p107
BUNDLED WITH
2.2.22
我通过从 deploy.rb 中删除链接(这两行)解决了错误:
append :linked_files, "config/database.yml", "config/secrets.yml", "config/master.key"
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "tmp/webpacker", "vendor", "storage"
看看https://guides.rubyonrails.org/security.html#environmental-security
您必须将 config/master.key 复制到已部署的文件夹。
如果你想重新生成安全文件,你可以删除这个文件:
config/master.key
config/credentials.yml.enc
然后运行这个命令重新生成
rails credentials:edit
将您的 credentials.yml.enc 复制到您的 shared/config/ 文件夹。 然后将“config/credentials.hml.enc”添加到 deploy.rb 文件中的 :linked_files 行。