Ruby on rails Capistrano rails |未定义的方法`已被调用';在gitlab部署期间迁移时设置rails_env时的for Rake::Task
我花了很多时间调试这个问题,但似乎还没有找到答案。我还考虑过在capistrano存储库中创建一个问题,但我并不认为这是capistrano本身的问题 背景: 我在Gitlab EE中托管的私有存储库中有一个rails 5项目。My repo完全配置为使用Gitlab CI,用于使用capistrano、capistrano/rails和capistrano/rvm自动化部署。我有一个用于部署的作业,其中我执行Ruby on rails Capistrano rails |未定义的方法`已被调用';在gitlab部署期间迁移时设置rails_env时的for Rake::Task,ruby-on-rails,environment-variables,capistrano3,gitlab-ci,rvm-capistrano,Ruby On Rails,Environment Variables,Capistrano3,Gitlab Ci,Rvm Capistrano,我花了很多时间调试这个问题,但似乎还没有找到答案。我还考虑过在capistrano存储库中创建一个问题,但我并不认为这是capistrano本身的问题 背景: 我在Gitlab EE中托管的私有存储库中有一个rails 5项目。My repo完全配置为使用Gitlab CI,用于使用capistrano、capistrano/rails和capistrano/rvm自动化部署。我有一个用于部署的作业,其中我执行capreviewdeploy(正在查看我想要部署的环境) 一切都运行良好,直到我到达
capreviewdeploy
(正在查看我想要部署的环境)
一切都运行良好,直到我到达capistrano钩子deploy:migrate
,在该钩子中,由于以下错误而中断
错误:
config/deploy.rb
config/deploy/review.rb
卡普里
Gemfile
我的猜测是,由于您正在CI环境中手动安装Capistrano Gems,因此存在版本不匹配的问题。如果您在CI服务器上运行
bundle install
和bundle exec
,或者锁定已安装的版本,它可能会开始工作
我为此使用的一个解决方案是将所有必需的部署gem添加到我的gem文件中的:部署
组中。然后,您需要将以下内容添加到deploy.rb
:
set :bundle_without, %w{development test deployment}.join(' ')
然后将脚本更改为:
bundle install --except development test default production ...
bundle exec cap $CI_BUILD_REF_NAME deploy
您是否正在使用
.gitlab ci.yml
运行此操作?你能发布相关部分吗?编辑后添加我的堆栈详细信息。希望有帮助。谢谢!在我的CI环境中使用bundler在我刚刚测试它时非常有效。我非常喜欢尝试:部署组解决方案。我只是不明白为什么我需要在我的deploy.rb
中设置set:bundle\u而不使用%w{development test}.join(“”)
,因为这将覆盖:bundle\u而不使用
“capistrano变量”的值。我在我的每个环境中都单独设置了这个。另外,在下一个代码块中生产后,…
中会发生什么?啊,我犯了一个错误。在没有
的情况下更改bundle_的原因是,您不需要在生产环境中安装部署gems。如果您要在每个环境的基础上覆盖它,那么相应地进行调整。省略号之后,您的文件中除部署组之外的任何其他组都将被覆盖。我正试图在Bundler core中添加一个——只有参数,这将简化这一点:重要信息:对于所有像我这样的人来说,这会让我陷入困境!这个补丁帮助我完成了一个使用rails 5的项目。但它与rails 4.2中的另一个不起作用。。。所以我不得不升级另一个项目。。。希望这也有帮助:)
lock '~> 3.7'
env_file = "./config/environment_variables.yml"
if File.exists?(env_file)
YAML.load_file(env_file)['capistrano'].each do |key, value|
ENV[key.to_s] = value
end
end
set :application, ENV['PROJECT_NAME']
set :repo_url, ENV['REPO_URL']
set :rvm_type, :user
set :rvm_ruby_version, '2.3.1'
set :conditionally_migrate, true
set :linked_files, %w{config/environment_variables.yml}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :slackistrano, {
klass: Slackistrano::CustomMessaging,
channel: ENV['SLACK_CHANNEL'],
webhook: ENV['SLACK_HOOK']
}
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
desc 'Reset environment (rake db:reset)'
task :db_reset do
on roles(:app) do
within "#{current_path}" do
with rails_env: "#{fetch(:rails_env)}" do
execute :rake, "db:migrate:reset"
execute :rake, "db:seed"
end
end
end
end
after :published, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
# Server definiton: (define ip in local env, and pass in gitlab)
server ENV['DEV_DROPLET_IP'], user: 'deploy', roles: %w{web app db}, password: ENV["SSH_DEPLOY_PASS"]
# ONLY WORKS IF IT WAS RUN BY THE GITLAB CI RUNNER
set :branch, ENV['CI_BUILD_REF_NAME'] ? ENV['CI_BUILD_REF_NAME'] : 'development'
# Capistrano Variables
set :stage, 'review'
set :rails_env, 'review'
# Variables for rev
set :commit, ENV['CI_BUILD_REF'] ? ENV['CI_BUILD_REF'][0..7] : 'local'
set :user, ENV['GITLAB_USER_EMAIL'] ? ENV['GITLAB_USER_EMAIL']: 'local user'
# Capistrano Deployment Route
set :deploy_to, "/home/deploy/rev.#{ENV['PROJECT_NAME']}"
namespace :deploy do
desc 'Set review branch in the review server'
task :set_review_branch do
on roles(:app) do
within "#{current_path}" do
execute "echo '#{fetch(:branch)}@#{fetch(:commit)}' >> #{release_path.join('tmp/rev_branch')}"
execute "echo '#{fetch(:user)}' >> #{release_path.join('tmp/rev_user')}"
end
end
end
after :publishing, 'deploy:set_review_branch'
before :finishing, 'deploy:db_reset'
end
require "capistrano/setup"
require "capistrano/deploy"
require 'capistrano/rvm'
require 'capistrano/rails'
require 'slackistrano/capistrano'
require_relative 'lib/custom_messaging'
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
source 'https://rubygems.org'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'bootstrap-sass'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'mysql2'
gem 'haml-rails'
gem 'devise'
gem 'paperclip', git: 'git://github.com/thoughtbot/paperclip.git'
gem 'administrate', '~> 0.3.0'
gem 'bourbon'
gem 'rails_real_favicon', '~> 0.0.6'
gem 'listen', '~> 3.0.5'
group :development, :test do
gem 'byebug', platform: :mri
gem 'minitest-rails'
gem 'minitest-reporters'
gem 'simplecov'
gem 'simplecov-json', require: false
gem 'factory_girl_rails'
gem 'faker'
end
group :development do
gem 'annotate'
gem 'better_errors'
gem 'binding_of_caller'
# Capistrano for Deployments
gem 'capistrano', '~> 3.7'
gem 'capistrano-rvm'
gem 'capistrano-rails'
gem 'slackistrano'
gem 'web-console'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
set :bundle_without, %w{development test deployment}.join(' ')
bundle install --except development test default production ...
bundle exec cap $CI_BUILD_REF_NAME deploy