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' => 'almalinux:8',
'el9' => 'almalinux:9',
'ubuntu-20.04' => 'ubuntu:20.04',
'ubuntu-22.04' => 'ubuntu:22.04',
'amzn2023' => 'amazonlinux:2023'
}.freeze
- CODENAMES =
{
'ubuntu-20.04' => 'focal',
'ubuntu-22.04' => 'jammy'
}.freeze
- ARCH_PLATFORMS =
{
'x86_64' => 'linux/amd64',
'aarch64' => 'linux/arm64',
'ppc64le' => 'linux/ppc64le'
}.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, #ondemand_rpm_repo_baseurl, #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.
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/ood_packaging/build_box.rb', line 32
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
unless valid_arch?(arch)
raise ArgumentError, "Invalid arch selected: #{arch}. Valid choices are #{valid_arches.join(' ')}"
end
end
|
Instance Method Details
#arch ⇒ Object
50
51
52
|
# File 'lib/ood_packaging/build_box.rb', line 50
def arch
@arch ||= ENV['OOD_PACKAGING_ARCH'] || @config[:arch] || 'x86_64'
end
|
#base_image ⇒ Object
104
105
106
|
# File 'lib/ood_packaging/build_box.rb', line 104
def base_image
@base_image ||= BASE_IMAGES[dist]
end
|
#build! ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/ood_packaging/build_box.rb', line 176
def build!
scripts
cmd = [container_runtime]
cmd.concat build_command
cmd.concat ['--platform', platform]
cmd.concat ['--tag', image_tag]
cmd.concat build_output
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_command ⇒ Object
160
161
162
163
164
165
166
|
# File 'lib/ood_packaging/build_box.rb', line 160
def build_command
if container_runtime == 'docker'
['buildx', 'build']
else
['build']
end
end
|
#build_dir ⇒ Object
116
117
118
|
# File 'lib/ood_packaging/build_box.rb', line 116
def build_dir
File.join(File.dirname(__FILE__), 'build_box/docker-image')
end
|
#build_gem ⇒ Object
144
145
146
147
148
149
|
# File 'lib/ood_packaging/build_box.rb', line 144
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
|
#build_output ⇒ Object
168
169
170
171
172
173
174
|
# File 'lib/ood_packaging/build_box.rb', line 168
def build_output
if container_runtime == 'docker'
['--output', 'type=docker']
else
[]
end
end
|
#codename ⇒ Object
108
109
110
|
# File 'lib/ood_packaging/build_box.rb', line 108
def codename
@codename ||= CODENAMES[dist]
end
|
#deb? ⇒ Boolean
58
59
60
|
# File 'lib/ood_packaging/build_box.rb', line 58
def deb?
!rpm?
end
|
#dist ⇒ Object
46
47
48
|
# File 'lib/ood_packaging/build_box.rb', line 46
def dist
@dist ||= ENV['OOD_PACKAGING_DIST'] || @config[:dist]
end
|
#dnf? ⇒ Boolean
62
63
64
65
66
67
|
# File 'lib/ood_packaging/build_box.rb', line 62
def dnf?
return false unless rpm?
return false if dist == 'el7'
true
end
|
#dockerfile ⇒ Object
151
152
153
|
# File 'lib/ood_packaging/build_box.rb', line 151
def dockerfile
template_file('build_box/docker-image/Dockerfile.erb')
end
|
#image_name ⇒ Object
132
133
134
|
# File 'lib/ood_packaging/build_box.rb', line 132
def image_name
@config[:build_box_name] || ENV['OOD_PACKAGING_BUILD_BOX_NAME'] || 'ood-buildbox'
end
|
#image_org ⇒ Object
128
129
130
|
# File 'lib/ood_packaging/build_box.rb', line 128
def image_org
@config[:build_box_org] || ENV['OOD_PACKAGING_BUILX_BOX_ORG'] || 'ohiosupercomputer'
end
|
#image_registry ⇒ Object
124
125
126
|
# File 'lib/ood_packaging/build_box.rb', line 124
def image_registry
@config[:build_box_registry] || ENV['OOD_PACKAGING_BUILD_BOX_REGISTRY'] || nil
end
|
#image_tag ⇒ Object
140
141
142
|
# File 'lib/ood_packaging/build_box.rb', line 140
def image_tag
[image_registry, image_org, "#{image_name}-#{dist}-#{arch}:#{image_version}"].compact.join('/')
end
|
#image_version ⇒ Object
136
137
138
|
# File 'lib/ood_packaging/build_box.rb', line 136
def image_version
(ENV['OOD_PACKAGING_BUILD_BOX_VERSION'] || OodPackaging::VERSION).gsub(/^v/, '')
end
|
#legacy_gpg? ⇒ Boolean
75
76
77
78
79
|
# File 'lib/ood_packaging/build_box.rb', line 75
def legacy_gpg?
return true if ['el7', 'el8'].include?(dist)
false
end
|
#package_manager ⇒ Object
81
82
83
84
85
86
|
# File 'lib/ood_packaging/build_box.rb', line 81
def package_manager
return 'apt' if deb?
return 'dnf' if dnf?
'yum'
end
|
112
113
114
|
# File 'lib/ood_packaging/build_box.rb', line 112
def platform
@platform ||= ARCH_PLATFORMS[arch]
end
|
#pull! ⇒ Object
194
195
196
|
# File 'lib/ood_packaging/build_box.rb', line 194
def pull!
sh [container_runtime, 'pull', image_tag].join(' ')
end
|
#push! ⇒ Object
190
191
192
|
# File 'lib/ood_packaging/build_box.rb', line 190
def push!
sh [container_runtime, 'push', image_tag].join(' ')
end
|
#rpm? ⇒ Boolean
54
55
56
|
# File 'lib/ood_packaging/build_box.rb', line 54
def rpm?
dist.start_with?('el') || dist.start_with?('amzn')
end
|
#save!(path) ⇒ Object
198
199
200
|
# File 'lib/ood_packaging/build_box.rb', line 198
def save!(path)
sh [container_runtime, 'save', image_tag, '| gzip >', path].join(' ')
end
|
#scl? ⇒ Boolean
69
70
71
72
73
|
# File 'lib/ood_packaging/build_box.rb', line 69
def scl?
return true if dist == 'el7'
false
end
|
#scripts ⇒ Object
155
156
157
158
|
# File 'lib/ood_packaging/build_box.rb', line 155
def scripts
template_file('build_box/docker-image/inituidgid.sh.erb')
template_file('build_box/docker-image/install.sh.erb')
end
|
#valid_arch?(value) ⇒ Boolean
96
97
98
|
# File 'lib/ood_packaging/build_box.rb', line 96
def valid_arch?(value)
ARCH_PLATFORMS.key?(value)
end
|
#valid_arches ⇒ Object
100
101
102
|
# File 'lib/ood_packaging/build_box.rb', line 100
def valid_arches
ARCH_PLATFORMS.keys
end
|
#valid_dist?(value) ⇒ Boolean
88
89
90
|
# File 'lib/ood_packaging/build_box.rb', line 88
def valid_dist?(value)
BASE_IMAGES.key?(value)
end
|
#valid_dists ⇒ Object
92
93
94
|
# File 'lib/ood_packaging/build_box.rb', line 92
def valid_dists
BASE_IMAGES.keys
end
|
#work_dir ⇒ Object
120
121
122
|
# File 'lib/ood_packaging/build_box.rb', line 120
def work_dir
File.join('/work', "#{dist}-#{arch}")
end
|