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

included

Instance Method Details

#artifact ⇒ Object



13
14
15
# File 'lib/opskeleton/package.rb', line 13

def artifact
	"#{name}-#{meta.version}"
end

#artifact_path ⇒ Object



17
18
19
# File 'lib/opskeleton/package.rb', line 17

def artifact_path
	"pkg/#{name}-#{meta.version}"
end

#create_build ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/opskeleton/package.rb', line 27

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

#meta ⇒ Object



5
6
7
# File 'lib/opskeleton/package.rb', line 5

def meta 
	OpenStruct.new(YAML.load_file('opsk.yaml'))
end

#name ⇒ Object



9
10
11
# File 'lib/opskeleton/package.rb', line 9

def name 
	File.basename(Dir.getwd)
end

#package ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/opskeleton/package.rb', line 55

def package
	ignored = IO.readlines('.gitignore').map(&:chomp)
	ignored.delete('modules')
	ignored.delete('cookbooks')
	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



44
45
46
47
48
49
50
51
52
53
# File 'lib/opskeleton/package.rb', line 44

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

#type_of ⇒ Object

Raises:

  • (Exception)


21
22
23
24
25
# File 'lib/opskeleton/package.rb', line 21

def type_of
	return :puppet if meta.includes.include?('Puppetfile')
	return :chef if meta.includes.include?('Cheffile')
	raise Exception.new('no matching provisoner type found, make sure to include Cheffile or Pupppetfile in opsk.yaml')
end