&tag(Capistrano3);
#> dbサーバーのデータベースを生成するタスク。
#> デプロイ前に実行する必要がある。
task :db_create do
on roles(:db) do |host|
q1 = 'CREATE DATABASE IF NOT EXISTS <app_name>;'
q2 = 'GRANT ALL ON <app_name>.* TO <app_user>@localhost IDENTIFIED BY "<app_passsword>";'
q3 = "FLUSH PRIVILEGES;"
sql = "#{q1}#{q2}#{q3}"
execute "mysql --user=<mysql_user> --password=<msql_password> -e '#{sql}' "
end
end
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'
end
end
TODO:
gem "capistrano-scm-copy"
set :scm, :copy set :exclude_dir, ['vendor/bundle']
set :deploy_to, '/home/tanaka/www/demoapp'
require 'capistrano/copy'
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!
group :deployment do gem 'capistrano', '~> 3.0', require: false gem 'rubyzip', require: false end
require 'zip'
Zip.setup do |c|
c.unicode_names = true
c.on_exists_proc = true
c.continue_on_exists_proc = true
end
namespace :copy do
task :check do
end
task :set_current_revision do
end
task create_release: 'release.zip' do |t|
file = t.prerequisites.first
on roles(:app) do
execute :mkdir, '-p', fetch(:tmp_dir)
upload! file, fetch(:tmp_dir)
execute :unzip, '-o', "#{fetch(:tmp_dir)}/release.zip", '-d', release_path
end
File.delete file if File.exists?(file)
end
file 'release.zip' do |t|
release_filename = File.join(Dir.pwd, t.name)
Dir.chdir fetch(:copy_dir) do
Zip::File.open(release_filename, Zip::File::CREATE) do |zipfile|
files = FileList['**/*']
files.exclude(*fetch(:copy_exclude)).each do |file|
zipfile.add(file, file)
end
end
end
end
end
set :scm, 'copy' set :copy_dir, '.' set :tmp_dir, '/tmp' set :copy_exclude, [ /\.log$/, %r!^files/.+! ]
set :copy_exclude, [
/^logs/,
/^tmp/,
/^vendor/
]
set :rails_env, "staging"
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/uploads')role :app, %w{deploy@example.com}
role :web, %w{deploy@example.com}
role :db, %w{deploy@example.com}
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server definition into the
# server list. The second argument is a, or duck-types, Hash and is
# used to set extended properties on the server.
server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
sudo apt-get install nodejs sudo yum install nodejs
gem.files = `git ls-files`.split($\)
ssh-add -D