Skip to content

Instantly share code, notes, and snippets.

@steverob
Forked from bipinshashi/gist:703792fa31a5fb0f46f3
Last active September 24, 2015 18:07
Show Gist options
  • Save steverob/fbb7cc05957efd7a2386 to your computer and use it in GitHub Desktop.
Save steverob/fbb7cc05957efd7a2386 to your computer and use it in GitHub Desktop.

Revisions

  1. steverob renamed this gist Sep 24, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. steverob revised this gist Sep 24, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ if Rubber::Util.has_asset_pipeline?

    _cset :asset_env, "RAILS_GROUPS=assets"
    _cset :assets_prefix, "assets"
    _cset :assets_role, [:web]
    _cset :assets_role, [:app]

    _cset :normalize_asset_timestamps, false

    @@ -23,9 +23,9 @@ if Rubber::Util.has_asset_pipeline?
    set :rails_env, "production"
    set :asset_env, "RAILS_GROUPS=assets"
    DESC
    task :precompile, :roles => :web, :except => { :no_release => true } do
    task :precompile, :roles => :app, :except => { :no_release => true } do
    from = source.next_revision(current_revision)
    ast = `#{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/`.strip rescue "1" #always
    ast = `#{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ Gemfile.lock`.strip rescue "1" #always
    if ast.length > 0 or ENV['FORCE_ASSETS']
    logger.info "Precompiling assets locally..."
    run_locally("RAILS_ENV=production rake assets:clean && RAILS_ENV=production rake assets:precompile")
    @@ -48,7 +48,7 @@ if Rubber::Util.has_asset_pipeline?
    for efficiency. If you customize the assets path prefix, override the \
    :assets_prefix variable to match.
    DESC
    task :symlink, :roles => :web, :except => { :no_release => true } do
    task :symlink, :roles => :app, :except => { :no_release => true } do
    run <<-CMD
    rm -rf #{latest_release}/public/#{assets_prefix} &&
    mkdir -p #{latest_release}/public &&
  3. @bipinshashi bipinshashi created this gist Jun 22, 2014.
    66 changes: 66 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    if Rubber::Util.has_asset_pipeline?
    # load 'deploy/assets'

    _cset :asset_env, "RAILS_GROUPS=assets"
    _cset :assets_prefix, "assets"
    _cset :assets_role, [:web]

    _cset :normalize_asset_timestamps, false

    before 'deploy:finalize_update', 'deploy:assets:symlink'
    after 'deploy:update_code', 'deploy:assets:precompile'

    namespace :deploy do
    namespace :assets do

    desc <<-DESC
    Run the asset precompilation rake task. You can specify the full path \
    to the rake executable by setting the rake variable. You can also \
    specify additional environment variables to pass to rake via the \
    asset_env variable. The defaults are:

    set :rake, "rake"
    set :rails_env, "production"
    set :asset_env, "RAILS_GROUPS=assets"
    DESC
    task :precompile, :roles => :web, :except => { :no_release => true } do
    from = source.next_revision(current_revision)
    ast = `#{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/`.strip rescue "1" #always
    if ast.length > 0 or ENV['FORCE_ASSETS']
    logger.info "Precompiling assets locally..."
    run_locally("RAILS_ENV=production rake assets:clean && RAILS_ENV=production rake assets:precompile")
    run_locally "cd public && tar -jcf assets.tar.bz2 assets"
    logger.info "#{shared_path}"
    top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
    run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
    run_locally "rm public/assets.tar.bz2 && rm -r public/assets"
    run_locally("RAILS_ENV=production rake assets:clean && true")
    else
    logger.info "Skipping asset precompilation because there were no asset changes"
    end
    end

    desc <<-DESC
    [internal] This task will set up a symlink to the shared directory \
    for the assets directory. Assets are shared across deploys to avoid \
    mid-deploy mismatches between old application html asking for assets \
    and getting a 404 file not found error. The assets cache is shared \
    for efficiency. If you customize the assets path prefix, override the \
    :assets_prefix variable to match.
    DESC
    task :symlink, :roles => :web, :except => { :no_release => true } do
    run <<-CMD
    rm -rf #{latest_release}/public/#{assets_prefix} &&
    mkdir -p #{latest_release}/public &&
    mkdir -p #{shared_path}/assets &&
    ln -s #{shared_path}/assets #{latest_release}/public/#{assets_prefix}
    CMD
    end
    end
    end

    callbacks[:after].delete_if {|c| c.source == "deploy:assets:precompile"}
    callbacks[:before].delete_if {|c| c.source == "deploy:assets:symlink"}
    before "deploy:assets:precompile", "deploy:assets:symlink"
    after "rubber:config", "deploy:assets:precompile"
    end