Class: Opsk::Package

Inherits:
Thor::Group
  • Object
show all
Includes:
Thorable, Thor::Actions
Defined in:
lib/opskeleton/package.rb

Instance Method Summary collapse

Methods included from Thorable

#artifact, #artifact_path, included, #machines, #meta, #name, #type_of

Instance Method Details

#create_build ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/opskeleton/package.rb', line 7

def create_build
	empty_directory(artifact_path)
	path = Dir.getwd
	meta.includes.each {|f| 
	  if(File.directory?("#{path}/#{f}"))
 directory "#{path}/#{f}", "#{artifact_path}/#{f}", :verbose => false
	  elsif(File.exists?("#{path}/#{f}"))
 copy_file "#{path}/#{f}", "#{artifact_path}/#{f}"
	  else
 raise Exception.new("#{f} not found please validate opks.yaml includes section")
	  end
	}
	unless(File.exists?("#{artifact_path}/manifests/site.pp"))
	  template('templates/puppet/site.erb', "#{artifact_path}/manifests/site.pp")
	end
end

#dockercopy ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/opskeleton/package.rb', line 49

def dockercopy
	tar = "#{artifact}.tar.gz"
	if(File.exists?('dockerfiles'))
	  images = Dir['dockerfiles/*'].select{|file| File.ftype(file) == 'directory'}
	  images.each do |path|
 if(File.ftype(path) == 'directory')
		empty_directory "#{path}/pkg"
		FileUtils.copy "pkg/#{tar}", "#{path}/pkg/#{tar}"
 end
	  end
	end
end

#package ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/opskeleton/package.rb', line 35

def package
	ignored = IO.readlines('.gitignore').map(&:chomp)
	ignored.delete('modules')
	ignored.delete('cookbooks')
	ignored = ignored.select {|ig| !meta.includes.include?(ig)}
	excludes = ignored.map{|f| "'#{f}'"}.join(" --exclude=") << ' --exclude-backups --exclude-vcs --exclude=pkg'
	tar = "#{artifact}.tar.gz"
	input = artifact
	inside('pkg') do
	  run("tar --exclude=#{excludes} -czf #{tar} #{input} >> /dev/null" , :verbose => false) 
	end

end

#scripts ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/opskeleton/package.rb', line 24

def scripts
	empty_directory("#{artifact_path}/scripts")
	files = {:puppet => %w(lookup.rb run.sh) , :chef => [] }
	files[type_of].each  do |s|
	  unless(File.exists?("#{artifact_path}/scripts/#{s}"))
 template("templates/#{type_of}/scripts/#{s}", "#{artifact_path}/scripts/#{s}")
 chmod("#{artifact_path}/scripts/#{s}", 0755)
	  end
	end
end