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

#artifactObject



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

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

#artifact_pathObject



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

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

#create_buildObject



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

def create_build
  empty_directory(artifact_path)
  path = Dir.getwd
  directory path, artifact_path, :verbose => false
  unless(File.exists?("#{artifact_path}/manifests/site.pp"))
    template('templates/puppet/site.erb', "#{artifact_path}/manifests/site.pp")
  end
end

#create_pkgObject



44
45
46
# File 'lib/opskeleton/package.rb', line 44

def create_pkg
  empty_directory('pkg')
end

#metaObject



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

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

#nameObject



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

def name 
  File.basename(Dir.getwd)
end

#packageObject



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

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

#scriptsObject

Raises:

  • (Exception)


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

def scripts
  type = :puppet if File.exists?("#{artifact_path}/Puppetfile")
  type = :chef if File.exists?("#{artifact_path}/Cheffile")
  raise Exception.new('not matching provisoner type found') if type.nil?
  empty_directory("#{artifact_path}/scripts")
  files = {:puppet => %w(lookup.rb run.sh) , :chef => [] }
  files[type].each  do |s|
    unless(File.exists?("#{artifact_path}/scripts/#{s}"))
 template("templates/#{type}/scripts/#{s}", "#{artifact_path}/scripts/#{s}")
 chmod("#{artifact_path}/scripts/#{s}", 0755)
    end
  end
end