/site/config/deploy.rb
Ruby | 121 lines | 71 code | 25 blank | 25 comment | 5 complexity | 1d4bccb4c8a5e4922e880760bb415402 MD5 | raw file
- set :application, 'cb-blog'
- set :repo_url, 'verbbrandslimited@bitbucket.org:verbbrandslimited/carole-bamford-blog.git'
- # Urgh, composer tries to build from SVN source, no thanks
- set :composer_install_flags, '--prefer-dist'
- # Branch options
- # Prompts for the branch name (defaults to current branch)
- #ask :branch, -> { `git rev-parse --abbrev-ref HEAD`.chomp }
- # Hardcodes branch to always be master
- # This could be overridden in a stage config file
- set :branch, :develop
- set :deploy_to, -> { "/home/cbblog/public_html" }
- set :tmp_dir, -> { "/home/cbblog/tmp" }
- set :theme_directory_name, 'cb-blog'
- set :theme_path, Pathname.new('web/app/themes').join(fetch(:theme_directory_name))
- set :local_app_path, Pathname.new(Dir.pwd)
- set :local_theme_path, fetch(:local_app_path).join(fetch(:theme_path))
- set :local_dist_path, fetch(:local_theme_path).join('dist')
- # Use :debug for more verbose output when troubleshooting
- set :log_level, :info
- # Apache users with .htaccess files:
- # it needs to be added to linked_files so it persists across deploys:
- set :linked_files, fetch(:linked_files, []).push('.env', 'web/.htaccess')
- set :linked_dirs, fetch(:linked_dirs, []).push('web/app/uploads')
- namespace :deploy do
- desc 'Restart application'
- task :restart do
- on roles(:app), in: :sequence, wait: 5 do
- # Your restart mechanism here, for example:
- # execute :service, :nginx, :reload
- end
- end
- end
- # The above restart task is not run by default
- # Uncomment the following line to run it on deploys if needed
- # after 'deploy:publishing', 'deploy:restart'
- namespace :deploy do
- desc 'Update WordPress template root paths to point to the new release'
- task :update_option_paths do
- on roles(:app) do
- within fetch(:release_path) do
- if test :wp, :core, 'is-installed'
- [:stylesheet_root, :template_root].each do |option|
- # Only change the value if it's an absolute path
- # i.e. The relative path "/themes" must remain unchanged
- # Also, the option might not be set, in which case we leave it like that
- value = capture :wp, :option, :get, option, raise_on_non_zero_exit: false
- if value != '' && value != '/themes'
- execute :wp, :option, :set, option, fetch(:release_path).join('web/wp/wp-content/themes')
- end
- end
- end
- end
- end
- end
- end
- namespace :deploy do
- task :compile do
- #puts "Running npm run build in them directory"
- run_locally do
- # FEW-modification: execute npm build on absolute path
- execute "cd #{fetch(:local_theme_path)}; npm install; npm run build"
- end
- end
- task :copy do
- on roles(:web) do
- # Remote Paths (Lazy-load until actual deploy)
- set :release_theme, -> { release_path.join(fetch(:theme_path)) }
- set :remote_dist_path, -> { release_path.join(fetch(:theme_path)).join('dist') }
- puts "Your local distribution path: #{fetch(:local_dist_path)} "
- puts "Your remote distribution path: #{fetch(:remote_dist_path)} "
- puts "Uploading files to remote "
- upload! fetch(:local_dist_path).to_s, fetch(:remote_dist_path).to_s, recursive: true
- puts "Installing Composer dependencies"
- execute "cd '#{fetch(:release_theme)}'; composer install;"
- end
- end
- task assets: %w(compile copy)
- end
- # Folbert Addition. The below tasks give us a way to deploy only assets by running deploy:assetsonly
- namespace :deploy do
- task :copyonly do
- on roles(:web) do
- set :remote_dist_path, -> { release_path.join(fetch(:theme_path)) }
- puts "Your local distribution path: #{fetch(:local_dist_path)} "
- puts "Your remote distribution path: #{fetch(:remote_dist_path)} "
- puts "Uploading files to remote "
- upload! fetch(:local_dist_path).to_s, fetch(:remote_dist_path).to_s, recursive: true
- end
- end
- task assetsonly: %w(deploy:compile copyonly)
- end
- after 'deploy:updated', 'deploy:assets'
- # The above update_option_paths task is not run by default
- # Note that you need to have WP-CLI installed on your server
- # Uncomment the following line to run it on deploys if needed
- # after 'deploy:publishing', 'deploy:update_option_paths'