diff --git a/lib/tasks/deploy.rake b/lib/tasks/deploy.rake index f71af79..6f663e0 100644 --- a/lib/tasks/deploy.rake +++ b/lib/tasks/deploy.rake @@ -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