Skip to content

Instantly share code, notes, and snippets.

@dsandstrom
Forked from twetzel/deploy.rb
Last active December 26, 2019 22:17
Show Gist options
  • Save dsandstrom/4e6d118b4ca22e0fc7d40d40c5a8f22d to your computer and use it in GitHub Desktop.
Save dsandstrom/4e6d118b4ca22e0fc7d40d40c5a8f22d to your computer and use it in GitHub Desktop.

Revisions

  1. dsandstrom revised this gist Jun 8, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@
    desc 'Copy assets manifest'
    task copy_manifest: [:set_rails_env] do
    on roles(fetch(:assets_roles, [:web])) do
    remote_dir = "#{fetch(:user)}@#{host.hostname}:#{shared_path}/public/assets/"
    remote_dir = "#{fetch(:ssh_options).fetch(:user)}@#{host.hostname}:#{shared_path}/public/assets/"

    run_locally do
    begin
    @@ -48,7 +48,7 @@
    # rsync to each server
    on roles(fetch(:assets_roles, [:web])) do
    # this needs to be done outside run_locally in order for host to exist
    remote_dir = "#{fetch(:user)}@#{host.hostname}:#{shared_path}/public/assets/"
    remote_dir = "#{fetch(:ssh_options).fetch(:user)}@#{host.hostname}:#{shared_path}/public/assets/"

    run_locally do
    execute "rsync -av #{local_dir} #{remote_dir}"
  2. dsandstrom revised this gist May 27, 2016. No changes.
  3. dsandstrom revised this gist May 27, 2016. 1 changed file with 38 additions and 15 deletions.
    53 changes: 38 additions & 15 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -1,39 +1,62 @@
    # Runs rake assets:clean
    # Defaults to nil (no asset cleanup is performed)
    # If you use Rails 4+ and you'd like to clean up old assets after each deploy,
    # set this to the number of versions to keep
    set :keep_assets, 2

    # Clear existing task so we can replace it rather than "add" to it.
    Rake::Task["deploy:compile_assets"].clear

    namespace :deploy do

    desc 'Compile assets'
    task :compile_assets => [:set_rails_env] do
    # invoke 'deploy:assets:precompile'
    invoke 'deploy:assets:copy_manifest'
    invoke 'deploy:assets:precompile_local'
    invoke 'deploy:assets:backup_manifest'
    end



    namespace :assets do

    desc "Precompile assets locally and then rsync to web servers"
    task :precompile_local do
    local_dir = "./public/assets/"

    # Download the asset manifest file so a new one isn't generated. This makes
    # the app use the latest assets and gives Sprockets a complete manifest so
    # it knows which files to delete when it cleans up.
    desc 'Copy assets manifest'
    task copy_manifest: [:set_rails_env] do
    on roles(fetch(:assets_roles, [:web])) do
    remote_dir = "#{fetch(:user)}@#{host.hostname}:#{shared_path}/public/assets/"

    run_locally do
    begin
    execute "mkdir #{local_dir}"
    execute "scp '#{remote_dir}.sprockets-manifest-*' #{local_dir}"
    rescue
    # no manifest yet
    end
    end
    end
    end

    desc "Precompile assets locally and then rsync to web servers"
    task :precompile_local do
    # compile assets locally
    run_locally do
    execute "RAILS_ENV=#{fetch(:stage)} bundle exec rake assets:precompile"
    end

    # rsync to each server
    local_dir = "./public/assets/"
    on roles( fetch(:assets_roles, [:web]) ) do
    on roles(fetch(:assets_roles, [:web])) do
    # this needs to be done outside run_locally in order for host to exist
    remote_dir = "#{host.user}@#{host.hostname}:#{release_path}/public/assets/"

    run_locally { execute "rsync -av --delete #{local_dir} #{remote_dir}" }
    remote_dir = "#{fetch(:user)}@#{host.hostname}:#{shared_path}/public/assets/"

    run_locally do
    execute "rsync -av #{local_dir} #{remote_dir}"
    end
    end

    # clean up
    run_locally { execute "rm -rf #{local_dir}" }
    end

    end


    end
    end
  4. @twetzel twetzel revised this gist Sep 1, 2014. 1 changed file with 31 additions and 16 deletions.
    47 changes: 31 additions & 16 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,39 @@
    # Clear existing task so we can replace it rather than "add" to it.
    Rake::Task["deploy:compile_assets"].clear

    desc "Precompile assets locally and then rsync to web servers"
    task :compile_assets do
    # compile assets locally
    run_locally do
    with rails_env: fetch(:stage) do
    execute :bundle, "exec rake assets:precompile"
    end
    namespace :deploy do
    desc 'Compile assets'
    task :compile_assets => [:set_rails_env] do
    # invoke 'deploy:assets:precompile'
    invoke 'deploy:assets:precompile_local'
    invoke 'deploy:assets:backup_manifest'
    end


    namespace :assets do

    desc "Precompile assets locally and then rsync to web servers"
    task :precompile_local do
    # compile assets locally
    run_locally do
    execute "RAILS_ENV=#{fetch(:stage)} bundle exec rake assets:precompile"
    end

    # rsync to each server
    local_dir = "./public/assets/"
    on roles( fetch(:assets_roles, [:web]) ) do
    # this needs to be done outside run_locally in order for host to exist
    remote_dir = "#{host.user}@#{host.hostname}:#{release_path}/public/assets/"

    run_locally { execute "rsync -av --delete #{local_dir} #{remote_dir}" }
    end

    # rsync to each server
    local_dir = "./public/assets/"
    on roles(:web) do
    # this needs to be done outside run_locally in order for host to exist
    remote_dir = "#{host.user}@#{host.hostname}:#{shared_path}/public/assets/"
    # clean up
    run_locally { execute "rm -rf #{local_dir}" }
    end

    run_locally { execute "rsync -av --delete #{local_dir} #{remote_dir}" }
    end

    # clean up
    run_locally { execute "rm -rf #{local_dir}" }
    end

    end
  5. Jesús Burgos Maciá revised this gist Jul 30, 2014. 1 changed file with 23 additions and 17 deletions.
    40 changes: 23 additions & 17 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,24 @@
    # Clear existing task so we can replace it rather than "add" to it.
    Rake::Task["deploy:compile_assets"].clear
    # Clear existing task so we can replace it rather than "add" to it.
    Rake::Task["deploy:compile_assets"].clear

    desc "Precompile assets locally and then rsync to web servers"
    task :compile_assets do
    on roles(:web) do
    rsync_host = host.to_s

    run_locally do
    with rails_env: :production do ## Set your env accordingly.
    execute :bundle, "exec rake assets:precompile"
    end
    execute "rsync -av --delete ./public/assets/ #{fetch(:user)}@#{rsync_host}:#{shared_path}/public/assets/"
    execute "rm -rf public/assets"
    # execute "rm -rf tmp/cache/assets" # in case you are not seeing changes
    end
    end
    end
    desc "Precompile assets locally and then rsync to web servers"
    task :compile_assets do
    # compile assets locally
    run_locally do
    with rails_env: fetch(:stage) do
    execute :bundle, "exec rake assets:precompile"
    end
    end

    # rsync to each server
    local_dir = "./public/assets/"
    on roles(:web) do
    # this needs to be done outside run_locally in order for host to exist
    remote_dir = "#{host.user}@#{host.hostname}:#{shared_path}/public/assets/"

    run_locally { execute "rsync -av --delete #{local_dir} #{remote_dir}" }
    end

    # clean up
    run_locally { execute "rm -rf #{local_dir}" }
    end
  6. @buntine buntine renamed this gist Jul 14, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. @buntine buntine created this gist Jul 14, 2014.
    18 changes: 18 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # Clear existing task so we can replace it rather than "add" to it.
    Rake::Task["deploy:compile_assets"].clear

    desc "Precompile assets locally and then rsync to web servers"
    task :compile_assets do
    on roles(:web) do
    rsync_host = host.to_s

    run_locally do
    with rails_env: :production do ## Set your env accordingly.
    execute :bundle, "exec rake assets:precompile"
    end
    execute "rsync -av --delete ./public/assets/ #{fetch(:user)}@#{rsync_host}:#{shared_path}/public/assets/"
    execute "rm -rf public/assets"
    # execute "rm -rf tmp/cache/assets" # in case you are not seeing changes
    end
    end
    end