#author("2017-04-12T15:19:45+09:00","default:wikiwriter","wikiwriter") #author("2017-04-12T15:20:57+09:00","default:wikiwriter","wikiwriter") [[Capistrano3]] &tag(Capistrano3/deploy_via_copyする); *目次 [#i7bdbafb] #contents *関連ページ [#d98e9a99] -[[../基本]] -[[./古い情報]] *参考情報 [#xcebfe5f] *capistrano-scm-copyを最初から使う方法 [#ha3bcf1a] **インストール [#pbd49b81] -Gemfileを編集。rubyzipが必要なことに注意。 #pre{{ gem 'rubyzip' group :deployment do gem 'capistrano' gem 'capistrano-rails' gem 'capistrano-rbenv' gem 'capistrano-bundler' gem "capistrano-scm-copy" end }} -gemのインストール bundle install --path vendor/bundle -cap install実行 bundle exec cap install **設定ファイルの編集 [#pfa01924] -Capfileの編集。rbenv、bundler、assets、migrationsあたりが必要。 #pre{{ # Load DSL and Setup Up Stages require 'capistrano/setup' # Includes default deployment tasks require 'capistrano/deploy' # Includes 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 # # require 'capistrano/rvm' require 'capistrano/rbenv' # require 'capistrano/chruby' 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/*.rake').each { |r| import r } }} -config/deploy/staging.rb、production.rbの編集 #pre{{ puts "\n\e[0;31m Are you REALLY sure you want to deploy to production? \e[0m\n" proceed = STDIN.gets unless proceed =~ /^y/ puts "canceld" exit end set :ssh_options, :forward_agent=>true, :keys=>'~/.ssh/id_rsa.myapp_np', :auth_methods=>%w(publickey) set :deploy_to, '/Users/sora/www/myapp' server 'bronze', user: 'sora', roles: %w{web}, my_property: :my_value role :app, %w{bronze} role :web, %w{bronze} role :db, %w{bronze} }} -config/deploy.rbの編集 #pre{{ set :application, 'myapp' set :rbenv_ruby, File.read('.ruby-version').strip set :scm, :copy set :include_dir, ["*", '.ruby-version'] set :exclude_dir, ['vendor/bundle', 'log\/*', 'tmp\/*', 'mydb\/*'] set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle') set :keep_releases, 3 task :list do on roles(:web) do |host| execute "ls" end end namespace :deploy do namespace :deploy do after :restart, :restart_passenger do on roles(:web), in: :groups, limit: 3, wait: 10 do within release_path do execute :touch, 'tmp/restart.txt' end end end after :finishing, 'deploy:restart_passenger', 'deploy:cleanup' end end }} **使用する [#oc86e354] -サーバー上で"ls"を実行する"list"タスクを実行 bundle exec cap production list -deployする bundle exec cap staging deploy *capistrano-scm-copyを後から追加する方法[#u725bdde] -[[wercker/capistrano-scm-copy:https://github.com/wercker/capistrano-scm-copy]]を使う方法。 **設定 [#fddf8ec0] -Gemfileに以下を追加する gem "capistrano-scm-copy" -config/deploy.rbの:scmを変更。exclude_dirに指定したディレクトリは無視される。 set :scm, :copy set :exclude_dir, ['vendor/bundle'] -staging.rb、production.rbの変更 -deploy_toでdeploy先ディレクトリを指定する。staging、production環境で異なる場合deploy.rbではなくstaging.rbかproduction.rbで変更しないといけない。 #pre{{ set :deploy_to, '/home/tanaka/www/demoapp' }} -公式ドキュメントによろと、Capfileに以下を追加する必要がある。 require 'capistrano/copy' -しかし、[[Appears to try to upload archive file 2x · Issue #17 · wercker/capistrano-scm-copy:https://github.com/wercker/capistrano-scm-copy/issues/17]]によると、処理が2回走ってしまうためrequireしてはならない。 #pre{{ I had the same problem but could find a proper solution; remove require 'capistrano/copy' anywhere! This problem occurs when we use this module with capistrano/setup because capistrano/setup loads a scm module with the :scm value. https://github.com/capistrano/capistrano/blob/master/lib/capistrano/setup.rb#L18 Good luck! }} *トラブルシューティング [#b298585a] -[[IMplement the new Capistrano Scm plugin system · Issue #34 · wercker/capistrano-scm-copy:https://github.com/wercker/capistrano-scm-copy/issues/34]]にあるよに、Capistrano 3.7以降で警告が表示されるようになった。 #pre{{ [Deprecation Notice] `set :scm, :copy` is deprecated. To ensure this custom SCM will work with future versions of Capistrano, please upgrade it to a version that uses the new SCM plugin mechanism documented here: http://capistranorb.com/documentation/advanced-features/custom-scm }} -[[Capistrano 3 でデプロイサーバから対象サーバにコピー - Qiita:http://qiita.com/Ping/items/57133b6bbb0a3d705fed]]にあるように、[[ydkn/capistrano-git-copy: Capistrano plugin that packages git repository locally and uploads it to server:https://github.com/ydkn/capistrano-git-copy]]を使うのがいいかもしれない。