【问题标题】:Rails 4 - capistrano 3 doesn't deploy last commitsRails 4 - capistrano 3 不部署最后一次提交
【发布时间】:2015-01-17 01:54:31
【问题描述】:

我们有一个带有 Apache、Phusion Passenger 和 Capistrano 3 的 Rails 4 应用程序的生产环境,以及一个远程 bitbucket 存储库。 Capistrano 的“上限生产部署”运行良好,并且执行没有错误。但是当我们转到远程服务器上的“当前”文件夹并执行“git log”命令时,我们的远程存储库的最后一次提交不会被加载。

我们已经在我们的应用程序的主文件夹中尝试了“git log”,同样的问题。

我们的问题是,我们可以将 repo 的最后一次提交加载到生产环境中吗? Capistrano 不是默认做的吗?

知道它可能来自哪里吗?

这里是我们的 Capfile、deploy.rb 和 deploy/production.rb 文件的代码:

Capfile

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'


require 'rvm1/capistrano3'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

Dir.glob('lib/capistrano/**/*.rb').each { |r| import r }

deploy.rb

lock '3.1.0'

set :application, 'XXXXXXX'
set :deploy_user, 'XXXXXXX'

set :repo_url, 'GIT_REPO_URL.XXXXXXX.git'

set :keep_releases, 5

set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.1.2'
set :default_env, { rvm_bin_path: '/usr/local/rvm/bin' }


set :bundle_dir, "/usr/local/bin"

set :ssh_options, {:forward_agent => true}

set :linked_files, %w{config/database.yml config/application.yml}

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

set :tests, []

set(:config_files, %w(
  apache2.conf
  database.example.yml
  log_rotation
  unicorn.rb
  unicorn_init.sh
))

set :log_level, :debug

set :pty, true

set :assets_roles, [:app]

# which config files should be made executable after copying
# by deploy:setup_config
set(:executable_config_files, %w(
  unicorn_init.sh
))

# files which need to be symlinked to other parts of the
# filesystem. For example nginx virtualhosts, log rotation
# init scripts etc.
set(:symlinks, [
  {
    source: "apache2.conf",
    link: "/etc/apache2/sites-enabled/#{fetch(:full_app_name)}"
  },
  {
    source: "unicorn_init.sh",
    link: "/etc/init.d/unicorn_#{fetch(:full_app_name)}"
  },
  {
    source: "log_rotation",
   link: "/etc/logrotate.d/#{fetch(:full_app_name)}"
  }
])


namespace :deploy do
   task :start do ; end
   task :stop do ; end
   desc 'Restart application'
   task :restart do
    on roles(:all), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      execute :touch, release_path.join('restart.txt')
    end
  end

  task :stop_node do
    on roles(:all), in: :sequence do
      #Stop the node_server
      execute "nohup node ./realtime/node_server.js &"
    end
  end
  task :restart_node do
    on roles(:all), in: :sequence do
      #Restart the node_server
      execute "nohup node ./realtime/node_server.js &"
    end

  end
end

# Bundle install configuration
set :bundle_without, %w{development test}.join(' ')
set :bundle_roles, :all
namespace :bundler do
  desc "Install gems with bundler."
  task :install do
    on roles fetch(:bundle_roles) do
      with RAILS_ENV: fetch(:environment) do
        within release_path do
          execute :bundle, "install", "--without #{fetch(:bundle_without)}"
        end
      end
    end
  end
end
before 'deploy:updated', 'bundler:install'
before 'deploy:restart', 'bundler:install'
after 'deploy:updated', 'deploy:publishing'
after 'deploy:restart','deploy:restart_node'

deploy/production.rb

set :stage, :production
set :branch, "REPO_BRANCH"

set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
set :server_name, "XXXXXXX.com www.XXXXXXXX.com"

set :password, ask('Server password', nil)


server 'XXXXXX.com', user: 'XXXXXX', password: fetch(:password), port: 22,  roles: %w{web app}, primary: true

set :deploy_to, '/PATH/TO/APP'


set :rails_env, :production
set :environment, "production"

set :unicorn_worker_count, 5

set :enable_ssl, false

【问题讨论】:

  • 您是否已将本地更改推送到 github 或同等位置?
  • 是的,我先把本地的修改推送到bitbucket上的远程repo,然后调用“cap production deploy”
  • 如果要部署正确的分支,我建议您检查部署日志。
  • @maximus 我已经检查了 revisions.log 并且特定的分支被认为是“部署”为一个版本。但是代码中看不到任何更改。提交仍未加载(拉)

标签: ruby-on-rails git capistrano


【解决方案1】:

看起来 capistrano 在 /var/www/:appname/repo 中保留了一个 repo/ 目录,它缓存了 git repo,所以如果你更改 repo capistrano 不会自动更新。

核对 repo 目录对我有用

【讨论】:

  • 拯救了我的一天!现在正在调试一段时间:-)
  • @Benoir 你是救生员 :)
【解决方案2】:

您已经为部署设置了一个特定的分支 (set :branch, "REPO_BRANCH"),这个分支来自远程 git 存储库。确保您已将提交推送到 bitbucket 存储库的正确分支。

【讨论】:

  • 我已经很好地推送了这个特定分支上的本地更改。但它不起作用......我可以通过拉取更改直接在生产服务器上拉取更改,但我想通过 Capistrano 自动完成
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-18
  • 1970-01-01
相关资源
最近更新 更多