美文网首页
配置Capistrano

配置Capistrano

作者: hjiangwen | 来源:发表于2017-12-12 13:30 被阅读42次

    引入以下Gem

    # /Gemfile
    group :development do
       ...
      gem 'capistrano'
      gem 'capistrano-rails'
      gem 'capistrano3-puma'
      gem 'capistrano-rvm',     require: false
      gem 'capistrano-bundler'
      # gem 'capistrano-sidekiq'
    end
    

    运行以下命令

    $ bundle exec cap install
    

    编辑/Capfile文件

    # Load DSL and set up stages
    require "capistrano/setup"
    
    # Include default deployment tasks
    require "capistrano/deploy"
    
    require "capistrano/scm/git"
    install_plugin Capistrano::SCM::Git
    
    # 引入Gemfile所引入的gems的任务
    require "capistrano/rvm"
    require "capistrano/bundler"
    require "capistrano/rails/assets"
    require "capistrano/rails/migrations"
    require 'capistrano/puma'
    install_plugin Capistrano::Puma
    
    # Load custom tasks from `lib/capistrano/tasks` if you have any defined
    Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
    
    

    编辑/config/deploy.rb

    # config valid for current version and patch releases of Capistrano
    lock "~> 3.10.1"
    set :rails_env, fetch(:stage)
    
    # 修改应用名称,git仓库地址
    set :application, "your_app_name"
    set :repo_url, "your_repo_url"
    
    # Default branch is :master
    # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
    
    set :deploy_to, "/var/projects/#{fetch(:application)}_#{fetch(:rails_env)}"
    set :rvm_ruby_version, 'ruby-2.3.0'
    set :rvm_binary, '/usr/local/rvm/bin/rvm'
    
    append :linked_dirs, 'tmp/pids', 'tmp/cache', 'log', 'public/uploads'
    
    set :keep_releases, 5
    set :keep_assets, 2
    
    set :puma_bind,       "unix://#{shared_path}/tmp/pids/puma.sock"
    set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
    set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
    set :puma_access_log, "#{release_path}/log/puma.error.log"
    set :puma_error_log,  "#{release_path}/log/puma.access.log"
    set :puma_preload_app, true
    set :puma_worker_timeout, nil
    set :puma_tag, "#{fetch(:application)}_#{fetch(:rails_env)}"
    set :puma_init_active_record, true  # Change to false when not using ActiveRecord
    set :puma_threads, [0, 5]
    set :puma_workers, 1
    set :puma_env, fetch(:rack_env, fetch(:rails_env))
    
    namespace :deploy do
    
      desc 'Initial Deploy'
      task :initial do
        on roles(:app) do
          before 'deploy:restart', 'puma:start'
          invoke 'deploy'
        end
      end
    
      desc 'Restart application'
      task :restart do
        on roles(:app), in: :sequence, wait: 3 do
          invoke 'puma:restart'
        end
      end
    
      after  :finishing, :cleanup
    
    end
    
    

    编辑/config/deploy/staging.rb,编辑你要部署的环境,设置IP地址,用户名

    server 'xx.xx.xx.xx', user: 'deploy', roles: %w{app db web}
    

    相关文章

      网友评论

          本文标题:配置Capistrano

          本文链接:https://www.haomeiwen.com/subject/ttwgixtx.html