PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/config/deploy.rb

https://bitbucket.org/clemsos/ethermashup-ui
Ruby | 125 lines | 90 code | 23 blank | 12 comment | 1 complexity | 3ef30b8ab52f51670003ecbf8f4c41a0 MD5 | raw file
  1. require 'capistrano/ext/multistage'
  2. ##### Load server-specific variables
  3. set :stages, ["staging", "production"]
  4. set :default_stage, "production"
  5. set :application, "ethermashup"
  6. set :scm, :git
  7. set :repository, "git@bitbucket.org:clemsos/ethermashup-ui.git"
  8. set :scm_passphrase, ""
  9. set :node_file, "start.sh"
  10. set :application_binary, 'bash'
  11. set :deploy_via, :remote_cache
  12. # role :app, :host
  13. set :use_sudo, false
  14. default_run_options[:pty] = true
  15. set :ssh_options, {:forward_agent => true}
  16. desc "Echo the server's hostname"
  17. task :echo_hostname do
  18. run "echo `hostname`"
  19. end
  20. namespace :deploy do
  21. # before 'deploy:node_additional_setup', 'deploy:setup_npm'
  22. after 'deploy:setup', 'deploy:node_additional_setup'
  23. before 'deploy:start', 'deploy:npm_install'
  24. before 'deploy:restart', 'deploy:npm_install'
  25. after 'deploy:create_symlink', 'deploy:symlink_node_folders'
  26. after 'deploy:create_symlink', 'deploy:symlink_config_files'
  27. # before 'deploy:restart', 'deploy:update_viz'
  28. before 'deploy:setup', 'deploy:create_deploy_to_with_sudo'
  29. after 'deploy:setup', 'deploy:write_upstart_script'
  30. task :start, :roles => :app, :except => { :no_release => true } do
  31. # run "#{try_sudo :as => 'root'} start #{application}"
  32. run "#{try_sudo :as => 'root'} start #{application}"
  33. end
  34. desc 'Install the current npm environment.'
  35. task :setup_npm, :roles => :app do
  36. invoke_command "bash -c '. ~/nvm/nvm.sh && cd #{current_path} && npm install'", :via => run_method
  37. end
  38. task :stop, :roles => :app, :except => { :no_release => true } do
  39. run "#{try_sudo :as => 'root'} stop #{application}"
  40. end
  41. task :restart, :roles => :app, :except => { :no_release => true } do
  42. run "#{try_sudo :as => 'root'} restart #{application}"
  43. end
  44. task :create_deploy_to_with_sudo, :roles => :app do
  45. run "#{try_sudo :as => 'root'} mkdir -p #{deploy_to}"
  46. run "#{try_sudo :as => 'root'} chown #{admin_runner}:#{admin_runner} #{deploy_to}"
  47. end
  48. desc 'Create symlink between static npm modules and current path.'
  49. task :symlink_node_folders, :roles => :app, :except => { :no_release => true } do
  50. run "ln -s #{applicationdir}/shared/node_modules #{applicationdir}/current/node_modules"
  51. run "ln -s #{applicationdir}/data #{applicationdir}/current/public/data"
  52. end
  53. task :symlink_config_files do
  54. # run "ln -s #{shared_path}/config/db.json #{release_path}/config/"
  55. run "ln -s #{shared_path}/config/config.json #{release_path}/config/"
  56. end
  57. task :node_additional_setup, :roles => :app, :except => { :no_release => true } do
  58. # run "mkdir -p #{applicationdir}/shared/node_modules"
  59. invoke_command "bash -c '. ~/nvm/nvm.sh && cd #{current_path} && npm install forever -g'", :via => run_method
  60. invoke_command "bash -c '. ~/nvm/nvm.sh && cd #{current_path} && npm install supervisor -g'", :via => run_method
  61. # run "npm install forever -g"
  62. # run "npm install supervisor -g"
  63. end
  64. desc 'Install all npm packages'
  65. task :npm_install, :roles => :app, :except => { :no_release => true } do
  66. invoke_command "bash -c '. ~/nvm/nvm.sh && cd #{current_path} && npm install'", :via => run_method
  67. end
  68. desc 'Update all npm packages'
  69. task :npm_update, :roles => :app, :except => { :no_release => true } do
  70. run "cd #{applicationdir}/current/ #{try_sudo :as => 'root'} npm update"
  71. end
  72. # task :update_viz, :roles => :app, :except => { :no_release => true } do
  73. # run "cd #{shared_path}/submodules/seuron_viz && git pull origin master"
  74. # run "ln -s #{shared_path}/submodules/seuron_viz #{release_path}/public/viz/"
  75. # end
  76. desc 'Write the bash script in /etc/init.d with upstart'
  77. task :write_upstart_script, :roles => :app do
  78. upstart_script = <<-UPSTART
  79. description "#{application}"
  80. start on startup
  81. stop on shutdown
  82. script
  83. # We found $HOME is needed. Without it, we ran into problems
  84. env HOME="/home/#{admin_runner}"
  85. export HOME
  86. cd #{current_path}
  87. #{application_binary} #{current_path}/#{node_file} >> #{shared_path}/log/#{application}.log 2>&1
  88. end script
  89. respawn
  90. UPSTART
  91. put upstart_script, "/tmp/#{application}_upstart.conf"
  92. sudo "mv /tmp/#{application}_upstart.conf /etc/init/#{application}.conf"
  93. end
  94. end