require "readline" # Helpers def ask(question, default = "") question << " (#{default})" unless default.empty? begin response = Readline.readline(question + " ", true).strip response = default if response.empty? end while response.empty? response end def ask_yn(question, default = false) question << (default == true ? " (Y/n) " : " (y/N) ") response = Readline.readline(question, true).strip.downcase[0] return true if response == "y" return true if response.nil? && default == true false end # Config set :domain, "cnam-paca.fr" set :deploy_to, "/www/cnam-paca.fr" set :repository, "/www/cnam-paca.fr" set :local_branch, "master" set :branch, "master" set :user, "root" # Se mettre dans bon répertoire avant tout queue! "cd #{deploy_to}" # Tasks task :push do system "cd #{repository}" system "git push -f #{user}@#{domain}:#{deploy_to} #{local_branch}:#{branch}" queue! "git checkout -f" end task :bundle do queue! "bundle" end task :migrate do queue! "bundle exec rake db:migrate RAILS_ENV=production" end task :start do queue! "bundle exec puma -e production -w 2 -t 16:32 --preload -b unix://./tmp/puma.sock -d -S ./tmp/puma.state" end task :stop do queue! "bundle exec pumactl -S ./tmp/puma.state stop" end task :restart do queue! "bundle exec pumactl -S ./tmp/puma.state restart" end task :reload do queue! "bundle exec pumactl -S ./tmp/puma.state phased-restart" end task :status do queue! "bundle exec pumactl -S ./tmp/puma.state status" end task :cache do queue! "bundle exec rails runner 'Rails.cache.clear' -e production" end task :deploy do invoke :push invoke :bundle if ask_yn("Bundle ?", false) invoke :migrate if ask_yn("Migrate ?", false) invoke :reload if ask_yn("Reload ?", true) invoke :restart if ask_yn("Restart ?", false) invoke :cache if ask_yn("Clear cache ?", true) end task :db do db = ask "DB ?", "cnampaca" file = ask "File ?", Dir.glob("db/dumps/*.sql").first.to_s task :import do `mysql -uroot -p #{db} < #{file} --default_character_set utf8` end task :export do `mysqldump -uroot -p #{db} > #{file}` end task :dump do invoke :export end end