PageRenderTime 96ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/site/config/deploy.rb

https://bitbucket.org/verbbrandslimited/carole-bamford-blog
Ruby | 121 lines | 71 code | 25 blank | 25 comment | 5 complexity | 1d4bccb4c8a5e4922e880760bb415402 MD5 | raw file
  1. set :application, 'cb-blog'
  2. set :repo_url, 'verbbrandslimited@bitbucket.org:verbbrandslimited/carole-bamford-blog.git'
  3. # Urgh, composer tries to build from SVN source, no thanks
  4. set :composer_install_flags, '--prefer-dist'
  5. # Branch options
  6. # Prompts for the branch name (defaults to current branch)
  7. #ask :branch, -> { `git rev-parse --abbrev-ref HEAD`.chomp }
  8. # Hardcodes branch to always be master
  9. # This could be overridden in a stage config file
  10. set :branch, :develop
  11. set :deploy_to, -> { "/home/cbblog/public_html" }
  12. set :tmp_dir, -> { "/home/cbblog/tmp" }
  13. set :theme_directory_name, 'cb-blog'
  14. set :theme_path, Pathname.new('web/app/themes').join(fetch(:theme_directory_name))
  15. set :local_app_path, Pathname.new(Dir.pwd)
  16. set :local_theme_path, fetch(:local_app_path).join(fetch(:theme_path))
  17. set :local_dist_path, fetch(:local_theme_path).join('dist')
  18. # Use :debug for more verbose output when troubleshooting
  19. set :log_level, :info
  20. # Apache users with .htaccess files:
  21. # it needs to be added to linked_files so it persists across deploys:
  22. set :linked_files, fetch(:linked_files, []).push('.env', 'web/.htaccess')
  23. set :linked_dirs, fetch(:linked_dirs, []).push('web/app/uploads')
  24. namespace :deploy do
  25. desc 'Restart application'
  26. task :restart do
  27. on roles(:app), in: :sequence, wait: 5 do
  28. # Your restart mechanism here, for example:
  29. # execute :service, :nginx, :reload
  30. end
  31. end
  32. end
  33. # The above restart task is not run by default
  34. # Uncomment the following line to run it on deploys if needed
  35. # after 'deploy:publishing', 'deploy:restart'
  36. namespace :deploy do
  37. desc 'Update WordPress template root paths to point to the new release'
  38. task :update_option_paths do
  39. on roles(:app) do
  40. within fetch(:release_path) do
  41. if test :wp, :core, 'is-installed'
  42. [:stylesheet_root, :template_root].each do |option|
  43. # Only change the value if it's an absolute path
  44. # i.e. The relative path "/themes" must remain unchanged
  45. # Also, the option might not be set, in which case we leave it like that
  46. value = capture :wp, :option, :get, option, raise_on_non_zero_exit: false
  47. if value != '' && value != '/themes'
  48. execute :wp, :option, :set, option, fetch(:release_path).join('web/wp/wp-content/themes')
  49. end
  50. end
  51. end
  52. end
  53. end
  54. end
  55. end
  56. namespace :deploy do
  57. task :compile do
  58. #puts "Running npm run build in them directory"
  59. run_locally do
  60. # FEW-modification: execute npm build on absolute path
  61. execute "cd #{fetch(:local_theme_path)}; npm install; npm run build"
  62. end
  63. end
  64. task :copy do
  65. on roles(:web) do
  66. # Remote Paths (Lazy-load until actual deploy)
  67. set :release_theme, -> { release_path.join(fetch(:theme_path)) }
  68. set :remote_dist_path, -> { release_path.join(fetch(:theme_path)).join('dist') }
  69. puts "Your local distribution path: #{fetch(:local_dist_path)} "
  70. puts "Your remote distribution path: #{fetch(:remote_dist_path)} "
  71. puts "Uploading files to remote "
  72. upload! fetch(:local_dist_path).to_s, fetch(:remote_dist_path).to_s, recursive: true
  73. puts "Installing Composer dependencies"
  74. execute "cd '#{fetch(:release_theme)}'; composer install;"
  75. end
  76. end
  77. task assets: %w(compile copy)
  78. end
  79. # Folbert Addition. The below tasks give us a way to deploy only assets by running deploy:assetsonly
  80. namespace :deploy do
  81. task :copyonly do
  82. on roles(:web) do
  83. set :remote_dist_path, -> { release_path.join(fetch(:theme_path)) }
  84. puts "Your local distribution path: #{fetch(:local_dist_path)} "
  85. puts "Your remote distribution path: #{fetch(:remote_dist_path)} "
  86. puts "Uploading files to remote "
  87. upload! fetch(:local_dist_path).to_s, fetch(:remote_dist_path).to_s, recursive: true
  88. end
  89. end
  90. task assetsonly: %w(deploy:compile copyonly)
  91. end
  92. after 'deploy:updated', 'deploy:assets'
  93. # The above update_option_paths task is not run by default
  94. # Note that you need to have WP-CLI installed on your server
  95. # Uncomment the following line to run it on deploys if needed
  96. # after 'deploy:publishing', 'deploy:update_option_paths'