Skip to content

Instantly share code, notes, and snippets.

@hidakatsuya
Created March 25, 2014 17:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidakatsuya/9766712 to your computer and use it in GitHub Desktop.
Save hidakatsuya/9766712 to your computer and use it in GitHub Desktop.
Capistrano3 で deploy_via :copy する ref: http://qiita.com/hidakatsuya/items/4d097416516afc229199
$:.unshift File.expand_path(File.dirname(__FILE__) + '/lib') # << 必ず先頭に追加
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# :
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
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 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/.+! ]
config/
deploy/
production.rb
staging.rb
deploy.rb
lib/
capistrano/
tasks/
Capifile
config/
deploy/
production.rb
staging.rb
deploy.rb
lib/
capistrano/
tasks/
copy.rb << Add to here!
Capifile
group :deployment do
gem 'capistrano', '~> 3.0', require: false
gem 'rubyzip', require: false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment