Class: Buildizer::Target::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/buildizer/target/base.rb

Direct Known Subclasses

Fpm, Native, Patch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(builder, os, name:, package_name:, package_version:, package_cloud: [], prepare: [], build_dep: [], before_build: [], maintainer: nil, test_options: {}, test_env: {}, test_image: nil, before_test: [], test: [], &blk) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/buildizer/target/base.rb', line 13

def initialize(builder, os,
               name:, package_name:, package_version:, package_cloud: [],
               prepare: [], build_dep: [], before_build: [], maintainer: nil,
               test_options: {}, test_env: {}, test_image: nil, before_test: [], test: [],
               &blk)
  @builder = builder
  @os = os
  @params = {}

  params[:name] = name
  params[:package_name] = package_name
  params[:package_version] = package_version
  params[:package_cloud] = package_cloud
  params[:prepare] = prepare
  params[:build_dep] = build_dep
  params[:before_build] = before_build
  params[:maintainer] = maintainer
  params[:test_options] = test_options
  params[:test_env] = test_env
  params[:test_image] = test_image
  params[:before_test] = before_test
  params[:test] = test

  yield if block_given?

  @build_image = ::Buildizer::Image.new(build_image_name, self, from: os.base_image_name)
  @cache_image = ::Buildizer::Image.new(cache_image_name, self) if cache_image_name
  @test_image = ::Buildizer::Image.new(test_image_name, self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blk) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/buildizer/target/base.rb', line 43

def method_missing(name, *args, &blk)
  param_name = name.to_sym
  if params.key? param_name
    params[param_name]
  else
    super
  end
end

Instance Attribute Details

#build_imageObject (readonly)

Returns the value of attribute build_image.



9
10
11
# File 'lib/buildizer/target/base.rb', line 9

def build_image
  @build_image
end

#builderObject (readonly)

Returns the value of attribute builder.



4
5
6
# File 'lib/buildizer/target/base.rb', line 4

def builder
  @builder
end

#cache_imageObject (readonly)

Returns the value of attribute cache_image.



10
11
12
# File 'lib/buildizer/target/base.rb', line 10

def cache_image
  @cache_image
end

#osObject (readonly)

Returns the value of attribute os.



5
6
7
# File 'lib/buildizer/target/base.rb', line 5

def os
  @os
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/buildizer/target/base.rb', line 7

def params
  @params
end

#test_imageObject (readonly)

Returns the value of attribute test_image.



11
12
13
# File 'lib/buildizer/target/base.rb', line 11

def test_image
  @test_image
end

Instance Method Details

#_package_cloud_path(repo) ⇒ Object



99
100
101
# File 'lib/buildizer/target/base.rb', line 99

def _package_cloud_path(repo)
  "#{repo}/#{os.package_cloud_os_name}/#{os.package_cloud_os_version}"
end

#base_package_nameObject



73
74
75
# File 'lib/buildizer/target/base.rb', line 73

def base_package_name
  params[:package_name].split('-').first
end

#build_image_nameObject



81
82
83
# File 'lib/buildizer/target/base.rb', line 81

def build_image_name
  "#{params[:package_name]}:#{build_image_tag}"
end

#build_image_tagObject



77
78
79
# File 'lib/buildizer/target/base.rb', line 77

def build_image_tag
  params[:name].gsub('/', '__')
end

#cache_image_nameObject



85
86
87
# File 'lib/buildizer/target/base.rb', line 85

def cache_image_name
  "#{os.docker.cache[:repo]}:#{build_image_tag}" if os.docker.cache
end

#container_package_archive_nameObject



115
116
117
# File 'lib/buildizer/target/base.rb', line 115

def container_package_archive_name
  "#{container_package_name}.tar.gz"
end

#container_package_archive_pathObject



123
124
125
# File 'lib/buildizer/target/base.rb', line 123

def container_package_archive_path
  Pathname.new('/').join(container_package_archive_name)
end

#container_package_nameObject



56
57
58
# File 'lib/buildizer/target/base.rb', line 56

def container_package_name
  raise
end

#container_package_pathObject



119
120
121
# File 'lib/buildizer/target/base.rb', line 119

def container_package_path
  Pathname.new('/').join(container_package_name)
end

#image_build_pathObject



103
104
105
# File 'lib/buildizer/target/base.rb', line 103

def image_build_path
  image_work_path.join('build')
end

#image_extra_pathObject



107
108
109
# File 'lib/buildizer/target/base.rb', line 107

def image_extra_path
  image_work_path.join('extra')
end

#image_work_pathObject



52
53
54
# File 'lib/buildizer/target/base.rb', line 52

def image_work_path
  raise
end

#maintainer_emailObject



64
65
66
67
# File 'lib/buildizer/target/base.rb', line 64

def maintainer_email
  match = params[:maintainer].match(/<(.*)>/) if params[:maintainer]
  match[1] if match
end

#package_cloudObject



93
94
95
96
97
# File 'lib/buildizer/target/base.rb', line 93

def package_cloud
  params[:package_cloud].map do |desc|
    desc.merge(package_path: _package_cloud_path(desc[:repo]))
  end
end

#package_versionObject



69
70
71
# File 'lib/buildizer/target/base.rb', line 69

def package_version
  params[:package_version].nil? ? nil : params[:package_version].to_s
end

#package_version_tagObject



111
112
113
# File 'lib/buildizer/target/base.rb', line 111

def package_version_tag
  send(package_version_tag_param_name)
end

#package_version_tag_param_nameObject



60
61
62
# File 'lib/buildizer/target/base.rb', line 60

def package_version_tag_param_name
  raise
end

#test_envObject



127
128
129
130
131
132
133
134
135
136
# File 'lib/buildizer/target/base.rb', line 127

def test_env
  params[:test_env]
    .map {|var, values| Array(values).uniq.map {|value| {var => value}}}
    .reduce {|res, vars| res.product vars}
    .to_a
    .map {|vars|
      vars = [vars] unless vars.is_a? Array
      vars.reduce(&:merge)
    }
end

#test_image_nameObject



89
90
91
# File 'lib/buildizer/target/base.rb', line 89

def test_image_name
  params[:test_image] || os.base_vendor_image_name
end