Sage9 + Capistrano -> dist directory error

[TL;DR] The official bedrock-capistrano deploy script does not include deployment for sage. I want capistrano to generate the theme dist and vendor directories upon deployment, instead of including them in the git repo.

I added code to capistrano’s deploy.rb script that does the above, but it fails when copying the dist directory to the release, complaining that the dist folder isn’t there (while it IS there).

If someone would take a look or test this on a clean bedrock/sage install, any help would be greatly appreciated.

I usually deploy with Capistrano using the deploy scripts from the Bedrock documentation:

The above scripts do NOT automate the sage build process (generate/upload dist folder & composer install from the theme directory). This makes it necessary to manually do a yarn build:production, and push the entire dist + vendor directories to the git repo before deploying.

Not that bad, but it seems to me it should be better to update the capistrano deploy script.

After taking a look at, I’ve added some code to my deploy.rb script:

namespace :deploy do
  set :local_app_path,
  set :local_theme_path, fetch(:local_app_path).join(fetch(:webroot), 'app/themes/', fetch(:theme_dir))
  set :local_dist_path, fetch(:local_theme_path).join('dist')

  task :compile do
    run_locally do
      within fetch(:local_theme_path) do
        execute :yarn, 'build:production'

  task :copy do
    on roles(:web) do
      set :theme_path, fetch(:release_path).join(fetch(:webroot),'app/themes/',fetch(:theme_dir))
      set :remote_dist_path, -> { fetch(:theme_path).join('dist') }

      within fetch(:theme_path) do
          execute :mkdir, 'dist'
          puts "Dist folder created in #{: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), recursive: true

  task assets: %w(compile copy)


I’ve added the execute :mkdir, 'dist' line because the upload! command threw an error complaining that the ‘dist’ directory didn’t exist. Which now works (I’ve checked, dist directory is created in the new releases’ theme directory, and has correct permissions).

What is weird, is that it still throws an error, complaining about the dist directory not being there.

The error:

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as user@ssh_host: scp: ~/subsites/staging/releases/20190225141859/www/app/themes/my_theme/dist: No such file or directory

Caused by:
scp: ~/subsites/staging/releases/20190225141859/www/app/themes/my_theme/dist: No such file or directory

Tasks: TOP => deploy:assets => deploy:copy
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as user@ssh_host: scp: ~/subsi
tes/staging/releases/20190225141859/www/app/themes/my_theme/dist: No such file or directory
1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.