Skip to content

Commit

Permalink
rewrite deploy task
Browse files Browse the repository at this point in the history
  • Loading branch information
yannlugrin committed Mar 6, 2012
1 parent fe800ca commit fa5245f
Showing 1 changed file with 12 additions and 31 deletions.
43 changes: 12 additions & 31 deletions lib/tasks/deploy.rake
Expand Up @@ -5,48 +5,29 @@ if Rails.env.development?
@git ||= Git.open(Rails.root)
end

def deploy(part, branch, environment)
current_branch = git.current_branch.to_s

`git checkout -B deploy_#{part}_#{environment} #{branch}`

case part
when :fronted_server
File.open(Rails.root.join('Procfile'), 'w') do |file|
file << 'web: bundle exec rails server thin -p $PORT -e $RAILS_ENV' << "\n"
end
`git add Procfile`
when :message_server
File.open(Rails.root.join('Procfile'), 'w') do |file|
file << 'web: bundle exec rackup private_pub.ru -s thin -p $PORT -E production' << "\n"
end
`mkdir -p #{Rails.root.join('public/assets')}`
`touch #{Rails.root.join('public/assets/manifest.yml')}`
`git add Procfile #{Rails.root.join('public/assets/manifest.yml')}`
def deploy(branch, environment)
STDOUT.print "Are you sure you want deploy #{branch.upcase} branch to #{environment.upcase} environment? (y/n) "
input = STDIN.gets.strip.downcase
if input == 'y'
STDOUT.puts "Deploy to #{environment}..."
`git push #{environment} #{branch}:master --force`
else
STDOUT.puts "Deployment canceled."
end
`git commit -m "deploy to #{part}"`

`git push #{part}_#{environment} deploy_#{part}_#{environment}:master --force`

`git checkout #{current_branch}`
`git branch -D deploy_#{part}_#{environment}`
end

namespace :deploy do

task :staging do
deploy(:fronted_server, :dev, :production) if !ENV['ONLY'] || ENV['ONLY'] == 'fronted'
deploy(:message_server, :dev, :production) if !ENV['ONLY'] || ENV['ONLY'] == 'message'
deploy(:dev, :staging)
end

task :production do
deploy(:fronted_server, :dev, :production) if !ENV['ONLY'] || ENV['ONLY'] == 'fronted'
deploy(:message_server, :dev, :production) if !ENV['ONLY'] || ENV['ONLY'] == 'message'
task :production do
deploy(:dev, :production)
end

task :testing do
deploy(:fronted_server, git.current_branch.to_s, :production) if !ENV['ONLY'] || ENV['ONLY'] == 'fronted'
deploy(:message_server, git.current_branch.to_s, :production) if !ENV['ONLY'] || ENV['ONLY'] == 'message'
deploy(git.current_branch.to_s, :staging)
end

end
Expand Down

0 comments on commit fa5245f

Please sign in to comment.