Method: SourceCookbook#cleanup_and_repackage

Defined in:
lib/mofa/source_cookbook.rb

#cleanup_and_repackageObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/mofa/source_cookbook.rb', line 127

def cleanup_and_repackage
  say "Shrinking Cookbook #{pkg_name}... "

  tar_verbose = (Mofa::CLI::option_debug) ? 'v' : ''

  inside pkg_dir do
    empty_directory 'tmp'
    run "tar x#{tar_verbose}fz #{pkg_name} -C tmp/"

    COOKBOOK_IGNORE.each do |remove_this|
      if File.exists?("tmp/cookbooks/#{name}/#{remove_this}")
        run "rm -rf tmp/cookbooks/#{name}/#{remove_this}"
      end
    end
  end
  inside "#{pkg_dir}/tmp" do
    # Sync in mofa_secrets
    if override_mofa_secrets
      path_translated = @override_mofa_secrets.sub(/^([a-zA-Z]):/,"/\1/")
      if File.directory?("#{path_translated}/#{name}/cookbooks")
        run "rsync -vr #{path_translated}/#{name}/cookbooks/ cookbooks/"
      end
    end
  end
  inside "#{pkg_dir}/tmp" do
    run "tar c#{tar_verbose}fz ../#{pkg_name}.new ."
  end
  inside pkg_dir do
    run "rm #{pkg_name}"
    run "mv #{pkg_name}.new #{pkg_name}"
    run 'rm -rf tmp/'
  end

  ok
end