1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

use pathname

This commit is contained in:
seenmyfate 2013-03-17 12:40:11 +00:00
parent 2ae1d1664a
commit 68e7632c5f
4 changed files with 38 additions and 28 deletions

View file

@ -1,32 +1,38 @@
require 'pathname'
module Capistrano
module DSL
module Paths
def deploy_path
def deploy_to
fetch(:deploy_to)
end
def deploy_path
Pathname.new(deploy_to)
end
def current_path
File.join(deploy_path, 'current')
deploy_path.join('current')
end
def releases_path
File.join(deploy_path, 'releases')
deploy_path.join('releases')
end
def release_path
File.join(releases_path, release_timestamp)
releases_path.join(release_timestamp)
end
def repo_path
File.join(deploy_path, 'repo')
deploy_path.join('repo')
end
def shared_path
File.join(deploy_path, 'shared')
deploy_path.join('shared')
end
def revision_log
File.join(deploy_path, 'revisions.log')
deploy_path.join('revisions.log')
end
def release_timestamp

View file

@ -43,7 +43,7 @@ namespace :deploy do
task :linked_dirs do
on all do
fetch(:linked_dirs).each do |dir|
dir = File.join(shared_path, dir)
dir = shared_path.join(dir)
unless test "[ -d #{dir} ]"
execute :mkdir, '-p', dir
end
@ -55,11 +55,12 @@ namespace :deploy do
task :linked_files do
on all do
fetch(:linked_files).each do |file|
parent = File.join(shared_path, File.dirname(file))
file_path = shared_path.join(file)
parent = file_path.dirname
unless test "[ -d #{parent} ]"
execute :mkdir, '-p', parent
end
unless test "[ -f #{File.join(shared_path, file)} ]"
unless test "[ -f #{file_path} ]"
error "linked file #{file} does not exist"
exit 1
end
@ -87,9 +88,9 @@ namespace :deploy do
task :linked_dirs do
on all do
fetch(:linked_dirs).each do |dir|
target = File.join(release_path, dir)
source = File.join(shared_path, dir)
parent = File.join(release_path, File.dirname(dir))
target = release_path.join(dir)
source = shared_path.join(dir)
parent = target.dirname
unless test "[ -d #{parent} ]"
execute :mkdir, '-p', parent
end
@ -107,9 +108,9 @@ namespace :deploy do
task :linked_files do
on all do
fetch(:linked_files).each do |file|
target = File.join(release_path, file)
source = File.join(shared_path, file)
parent = File.join(release_path, File.dirname(file))
target = release_path.join(file)
source = shared_path.join(file)
parent = target.dirname
unless test "[ -d #{parent} ]"
execute :mkdir, '-p', parent
end
@ -132,7 +133,7 @@ namespace :deploy do
if releases.length >= count
info "keeping #{count} of #{releases.length} deployed releases"
directories = (releases - releases.last(count)).map { |release|
File.join(releases_path, release) }.join(" ")
releases_path.join(release) }.join(" ")
execute :rm, '-rf', directories
end
end

View file

@ -1,11 +1,12 @@
require 'erb'
require 'pathname'
desc 'Install Capistrano, cap install STAGES=staging,production'
task :install do
envs = ENV['STAGES'] || 'staging,production'
tasks_dir = 'lib/deploy/tasks'
config_dir = 'config'
deploy_dir = File.join(config_dir, 'deploy')
tasks_dir = Pathname.new('lib/capistrano/tasks')
config_dir = Pathname.new('config')
deploy_dir = config_dir.join('deploy')
deploy_rb = File.expand_path("../../templates/deploy.rb.erb", __FILE__)
stage_rb = File.expand_path("../../templates/stage.rb.erb", __FILE__)
@ -14,7 +15,7 @@ task :install do
mkdir_p deploy_dir
template = File.read(deploy_rb)
file = File.join(config_dir, 'deploy.rb')
file = config_dir.join('deploy.rb')
File.open(file, 'w+') do |f|
f.write(ERB.new(template).result(binding))
puts I18n.t(:written_file, scope: :capistrano, file: file)
@ -22,7 +23,7 @@ task :install do
template = File.read(stage_rb)
envs.split(',').each do |stage|
file = File.join(deploy_dir, "#{stage}.rb")
file = deploy_dir.join("#{stage}.rb")
File.open(file, 'w+') do |f|
f.write(ERB.new(template).result(binding))
puts I18n.t(:written_file, scope: :capistrano, file: file)

View file

@ -5,16 +5,18 @@ require 'capistrano/setup'
# provides remote execution of arbitrary commands
require 'capistrano/console'
# require bundled deployment tasks
# remove to start from scratch
# includes default deployment tasks
# remove to start completely from scratch
require 'capistrano/deploy'
require 'capistrano/bundler'
# require 'capistrano/rails'
# require 'capistrano/bundler'
# require 'capistrano/rails/all'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'
# require 'capistrano/heroku'
# Loads any rake tasks from lib/deploy/tasks
Dir.glob('lib/deploy/tasks/*.rake').each { |r| import r }
# loads any rake tasks from lib/capistrano/tasks
# Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
desc "Restart"