Class: OodPackaging::BuildBox
- Inherits:
-
Object
- Object
- OodPackaging::BuildBox
show all
- Includes:
- FileUtils, Utils
- Defined in:
- lib/ood_packaging/build_box.rb
Overview
Build the packaging build boxes
Constant Summary
collapse
- BASE_IMAGES =
{
'el7' => 'centos:7',
'el8' => 'rockylinux/rockylinux:8',
'ubuntu-20.04' => 'ubuntu:20.04'
}.freeze
- CODENAMES =
{
'ubuntu-20.04' => 'focal'
}.freeze
Instance Method Summary
collapse
Methods included from Utils
#container_runtime, #ctr_gems_dir, #ctr_gpg_dir, #ctr_home, #ctr_rpmmacros, #ctr_scripts_dir, #ctr_user, #docker_runtime?, #gpg_passphrase, #gpg_private_key, #nodejs_version, #ondemand_repo_version, #podman_runtime?, #proj_root, #rt_specific_flags, #ruby_version, #scl_ruby, #sed, #tar, #template_file
Constructor Details
#initialize(config = {}) ⇒ BuildBox
Returns a new instance of BuildBox.
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/ood_packaging/build_box.rb', line 22
def initialize(config = {})
@config = config
raise ArgumentError, 'Must provide dist' if dist.nil?
unless valid_dist?(dist)
raise ArgumentError, "Invalid dist selected: #{dist}. Valid choices are #{valid_dists.join(' ')}"
end
end
|
Instance Method Details
#base_image ⇒ Object
73
74
75
|
# File 'lib/ood_packaging/build_box.rb', line 73
def base_image
@base_image ||= BASE_IMAGES[dist]
end
|
#build! ⇒ Object
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/ood_packaging/build_box.rb', line 121
def build!
scripts
cmd = [container_runtime, 'build']
cmd.concat ['--tag', image_tag]
cmd.concat [ENV['OOD_PACKAGING_BUILD_BOX_ARGS']] if ENV['OOD_PACKAGING_BUILD_BOX_ARGS']
cmd.concat ['-f', dockerfile]
cmd.concat [build_dir]
build_gem
sh cmd.join(' ')
end
|
#build_dir ⇒ Object
81
82
83
|
# File 'lib/ood_packaging/build_box.rb', line 81
def build_dir
File.join(File.dirname(__FILE__), 'build_box/docker-image')
end
|
#build_gem ⇒ Object
105
106
107
108
109
110
|
# File 'lib/ood_packaging/build_box.rb', line 105
def build_gem
gem = File.join(proj_root, 'pkg', "ood_packaging-#{OodPackaging::VERSION}.gem")
Rake::Task['build'].invoke
sh "rm -f #{build_dir}/*.gem"
sh "cp #{gem} #{build_dir}/"
end
|
#codename ⇒ Object
77
78
79
|
# File 'lib/ood_packaging/build_box.rb', line 77
def codename
@codename ||= CODENAMES[dist]
end
|
#deb? ⇒ Boolean
41
42
43
|
# File 'lib/ood_packaging/build_box.rb', line 41
def deb?
!rpm?
end
|
#dist ⇒ Object
33
34
35
|
# File 'lib/ood_packaging/build_box.rb', line 33
def dist
@dist ||= ENV['OOD_PACKAGING_DIST'] || @config[:dist]
end
|
#dnf? ⇒ Boolean
45
46
47
48
49
50
|
# File 'lib/ood_packaging/build_box.rb', line 45
def dnf?
return false unless rpm?
return false if dist == 'el7'
true
end
|
#dockerfile ⇒ Object
112
113
114
|
# File 'lib/ood_packaging/build_box.rb', line 112
def dockerfile
template_file('build_box/docker-image/Dockerfile.erb')
end
|
#image_name ⇒ Object
93
94
95
|
# File 'lib/ood_packaging/build_box.rb', line 93
def image_name
@config[:builx_box_name] || ENV['OOD_PACKAGING_BUILD_BOX_NAME'] || 'ood-buildbox'
end
|
#image_org ⇒ Object
89
90
91
|
# File 'lib/ood_packaging/build_box.rb', line 89
def image_org
@config[:build_box_org] || ENV['OOD_PACKAGING_BUILX_BOX_ORG'] || 'ohiosupercomputer'
end
|
#image_registry ⇒ Object
85
86
87
|
# File 'lib/ood_packaging/build_box.rb', line 85
def image_registry
@config[:builx_box_registry] || ENV['OOD_PACKAGING_BUILD_BOX_REGISTRY'] || nil
end
|
#image_tag ⇒ Object
101
102
103
|
# File 'lib/ood_packaging/build_box.rb', line 101
def image_tag
[image_registry, image_org, "#{image_name}-#{dist}:#{image_version}"].compact.join('/')
end
|
#image_version ⇒ Object
97
98
99
|
# File 'lib/ood_packaging/build_box.rb', line 97
def image_version
(ENV['OOD_PACKAGING_BUILD_BOX_VERSION'] || OodPackaging::VERSION).gsub(/^v/, '')
end
|
#package_manager ⇒ Object
58
59
60
61
62
63
|
# File 'lib/ood_packaging/build_box.rb', line 58
def package_manager
return 'apt' if deb?
return 'dnf' if dnf?
'yum'
end
|
#push! ⇒ Object
132
133
134
|
# File 'lib/ood_packaging/build_box.rb', line 132
def push!
sh [container_runtime, 'push', image_tag].join(' ')
end
|
#rpm? ⇒ Boolean
37
38
39
|
# File 'lib/ood_packaging/build_box.rb', line 37
def rpm?
dist.start_with?('el')
end
|
#save!(path) ⇒ Object
136
137
138
|
# File 'lib/ood_packaging/build_box.rb', line 136
def save!(path)
sh [container_runtime, 'save', image_tag, '| gzip >', path].join(' ')
end
|
#scl? ⇒ Boolean
52
53
54
55
56
|
# File 'lib/ood_packaging/build_box.rb', line 52
def scl?
return true if dist == 'el7'
false
end
|
#scripts ⇒ Object
116
117
118
119
|
# File 'lib/ood_packaging/build_box.rb', line 116
def scripts
template_file('build_box/docker-image/inituidgid.sh.erb')
template_file('build_box/docker-image/install.sh.erb')
end
|
#valid_dist?(value) ⇒ Boolean
65
66
67
|
# File 'lib/ood_packaging/build_box.rb', line 65
def valid_dist?(value)
BASE_IMAGES.key?(value)
end
|
#valid_dists ⇒ Object
69
70
71
|
# File 'lib/ood_packaging/build_box.rb', line 69
def valid_dists
BASE_IMAGES.keys
end
|