Module: MagicRecipes::Assets

Defined in:
lib/magic_recipes/assets.rb

Overview

Assets - Deploy-Recipes

changed asset deployment .. include chmod 777 for public folder (my server need this)

Tasks:

:symlink # => set up a symlink to the shared directory

:precompile # => Run the asset precompilation rake task

:chmod # => make the public folder public for all (777)

:clean # => Run the asset clean rake task

Callbacks:

before ‘deploy:finalize_update’, ‘deploy:assets:symlink’

after ‘deploy:update_code’, ‘deploy:assets:precompile’

Class Method Summary collapse

Class Method Details

.load_into(configuration) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/magic_recipes/assets.rb', line 22

def self.load_into(configuration)
  configuration.load do
    
    set_default :asset_env, "RAILS_GROUPS=assets"
    set_default :assets_prefix, "assets"
    set_default :assets_role, [:web]

    set_default :normalize_asset_timestamps, false
    set_default :make_pulbic_folder_public, false

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

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

        desc "Run the asset precompilation rake task. You can specify the full path \\\nto the rake executable by setting the rake variable. You can also \\\nspecify additional environment variables to pass to rake via the \\\nasset_env variable. The defaults are:\n\nset :rake,      \"rake\"\nset :rails_env, \"production\"\nset :asset_env, \"RAILS_GROUPS=assets\"\n"
        task :precompile, :roles => assets_role, :except => { :no_release => true } do
          if make_pulbic_folder_public
            chmod
          end
          if use_rvm
            run "\#{rvm_cmd} &&\ncd \#{latest_release} &&\n\#{rake} RAILS_ENV=\#{rails_env} \#{asset_env} assets:precompile\n"
          else
            run "cd \#{latest_release} &&\n\#{rake} RAILS_ENV=\#{rails_env} \#{asset_env} assets:precompile\n"
          end
        end
        
        desc "make the public folder public for all (777)"
        task :chmod, :roles => assets_role, :except => { :no_release => true } do
          run "cd \#{latest_release} &&\n\#{sudo} chmod -R 777 public/ &&\n\#{sudo} chmod -R 777 tmp/\n"
          run "cd \#{shared_path} &&\n\#{sudo} chmod -R 777 assets/\n"
        end

        desc "Run the asset clean rake task. Use with caution, this will delete \\\nall of your compiled assets. You can specify the full path \\\nto the rake executable by setting the rake variable. You can also \\\nspecify additional environment variables to pass to rake via the \\\nasset_env variable. The defaults are:\n\nset :rake,      \"rake\"\nset :rails_env, \"production\"\nset :asset_env, \"RAILS_GROUPS=assets\"\n"
        task :clean, :roles => assets_role, :except => { :no_release => true } do
          if make_pulbic_folder_public
            chmod
          end
          if use_rvm
            run "\#{rvm_cmd} &&\ncd \#{latest_release} &&\n\#{rake} RAILS_ENV=\#{rails_env} \#{asset_env} assets:clean\n"
          else
            run "cd \#{latest_release} &&\n\#{rake} RAILS_ENV=\#{rails_env} \#{asset_env} assets:clean\n"
          end
        end
      end
    end
    
  end
end