Class: Rebi::ZipHelper
- Inherits:
-
Object
- Object
- Rebi::ZipHelper
- Defined in:
- lib/rebi/zip_helper.rb
Instance Method Summary collapse
-
#gen(env_conf) ⇒ Object
Create zip archivement.
-
#initialize ⇒ ZipHelper
constructor
A new instance of ZipHelper.
- #ls_files ⇒ Object
- #message ⇒ Object
- #raw_zip_archive(opts = {}) ⇒ Object
- #version_label ⇒ Object
Constructor Details
Instance Method Details
#gen(env_conf) ⇒ Object
Create zip archivement
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 |
# File 'lib/rebi/zip_helper.rb', line 28 def gen env_conf Rebi.log("Creating zip archivement", env_conf.name) start = Time.now ebextensions = env_conf.ebextensions files = ls_files tmp_file = raw_zip_archive tmp_folder = Dir.mktmpdir Zip::File.open(tmp_file) do |z| ebextensions.each do |ex_folder| Dir.glob("#{ex_folder}/*.config") do |fname| next unless (File.file?(fname) && files.include?(fname)) next unless y = YAML::load(ErbHelper.new(File.read(fname), env_conf).result) basename = File.basename(fname) target = ".ebextensions/#{basename}" tmp_yaml = "#{tmp_folder}/#{basename}" File.open(tmp_yaml, 'w') do |f| f.write y.to_yaml end z.remove target if z.find_entry target z.add target, tmp_yaml end end end FileUtils.rm_rf tmp_folder Rebi.log("Zip was created in: #{Time.now - start}s", env_conf.name) return { label: Time.now.strftime("app_#{env_conf.name}_#{version_label}_%Y%m%d_%H%M%S"), file: File.open(tmp_file.path), message: , } end |
#ls_files ⇒ Object
9 10 11 |
# File 'lib/rebi/zip_helper.rb', line 9 def ls_files `git ls-files`.split("\n") end |
#message ⇒ Object
23 24 25 |
# File 'lib/rebi/zip_helper.rb', line 23 def `git log --oneline -1`.chomp.split(" ")[1..-1].join(" ")[0..190] end |
#raw_zip_archive(opts = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/rebi/zip_helper.rb', line 13 def raw_zip_archive opts={} tmp_file = Tempfile.new("git_archive") system "git archive --format=zip HEAD > #{tmp_file.path}" return tmp_file end |
#version_label ⇒ Object
19 20 21 |
# File 'lib/rebi/zip_helper.rb', line 19 def version_label `git describe --always --abbrev=8`.chomp end |