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',
'el9' => 'almalinux:9',
'ubuntu-20.04' => 'ubuntu:20.04',
'ubuntu-22.04' => 'ubuntu:22.04'
}.freeze
- CODENAMES =
{
'ubuntu-20.04' => 'focal',
'ubuntu-22.04' => 'jammy'
}.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.
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/ood_packaging/build_box.rb', line 25
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
82
83
84
|
# File 'lib/ood_packaging/build_box.rb', line 82
def base_image
@base_image ||= BASE_IMAGES[dist]
end
|
#build! ⇒ Object
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/ood_packaging/build_box.rb', line 130
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
90
91
92
|
# File 'lib/ood_packaging/build_box.rb', line 90
def build_dir
File.join(File.dirname(__FILE__), 'build_box/docker-image')
end
|
#build_gem ⇒ Object
114
115
116
117
118
119
|
# File 'lib/ood_packaging/build_box.rb', line 114
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
86
87
88
|
# File 'lib/ood_packaging/build_box.rb', line 86
def codename
@codename ||= CODENAMES[dist]
end
|
#deb? ⇒ Boolean
44
45
46
|
# File 'lib/ood_packaging/build_box.rb', line 44
def deb?
!rpm?
end
|
#dist ⇒ Object
36
37
38
|
# File 'lib/ood_packaging/build_box.rb', line 36
def dist
@dist ||= ENV['OOD_PACKAGING_DIST'] || @config[:dist]
end
|
#dnf? ⇒ Boolean
48
49
50
51
52
53
|
# File 'lib/ood_packaging/build_box.rb', line 48
def dnf?
return false unless rpm?
return false if dist == 'el7'
true
end
|
#dockerfile ⇒ Object
121
122
123
|
# File 'lib/ood_packaging/build_box.rb', line 121
def dockerfile
template_file('build_box/docker-image/Dockerfile.erb')
end
|
#image_name ⇒ Object
102
103
104
|
# File 'lib/ood_packaging/build_box.rb', line 102
def image_name
@config[:build_box_name] || ENV['OOD_PACKAGING_BUILD_BOX_NAME'] || 'ood-buildbox'
end
|
#image_org ⇒ Object
98
99
100
|
# File 'lib/ood_packaging/build_box.rb', line 98
def image_org
@config[:build_box_org] || ENV['OOD_PACKAGING_BUILX_BOX_ORG'] || 'ohiosupercomputer'
end
|
#image_registry ⇒ Object
94
95
96
|
# File 'lib/ood_packaging/build_box.rb', line 94
def image_registry
@config[:build_box_registry] || ENV['OOD_PACKAGING_BUILD_BOX_REGISTRY'] || nil
end
|
#image_tag ⇒ Object
110
111
112
|
# File 'lib/ood_packaging/build_box.rb', line 110
def image_tag
[image_registry, image_org, "#{image_name}-#{dist}:#{image_version}"].compact.join('/')
end
|
#image_version ⇒ Object
106
107
108
|
# File 'lib/ood_packaging/build_box.rb', line 106
def image_version
(ENV['OOD_PACKAGING_BUILD_BOX_VERSION'] || OodPackaging::VERSION).gsub(/^v/, '')
end
|
#legacy_gpg? ⇒ Boolean
61
62
63
64
65
|
# File 'lib/ood_packaging/build_box.rb', line 61
def legacy_gpg?
return true if ['el7', 'el8'].include?(dist)
false
end
|
#package_manager ⇒ Object
67
68
69
70
71
72
|
# File 'lib/ood_packaging/build_box.rb', line 67
def package_manager
return 'apt' if deb?
return 'dnf' if dnf?
'yum'
end
|
#pull! ⇒ Object
145
146
147
|
# File 'lib/ood_packaging/build_box.rb', line 145
def pull!
sh [container_runtime, 'pull', image_tag].join(' ')
end
|
#push! ⇒ Object
141
142
143
|
# File 'lib/ood_packaging/build_box.rb', line 141
def push!
sh [container_runtime, 'push', image_tag].join(' ')
end
|
#rpm? ⇒ Boolean
40
41
42
|
# File 'lib/ood_packaging/build_box.rb', line 40
def rpm?
dist.start_with?('el')
end
|
#save!(path) ⇒ Object
149
150
151
|
# File 'lib/ood_packaging/build_box.rb', line 149
def save!(path)
sh [container_runtime, 'save', image_tag, '| gzip >', path].join(' ')
end
|
#scl? ⇒ Boolean
55
56
57
58
59
|
# File 'lib/ood_packaging/build_box.rb', line 55
def scl?
return true if dist == 'el7'
false
end
|
#scripts ⇒ Object
125
126
127
128
|
# File 'lib/ood_packaging/build_box.rb', line 125
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
74
75
76
|
# File 'lib/ood_packaging/build_box.rb', line 74
def valid_dist?(value)
BASE_IMAGES.key?(value)
end
|
#valid_dists ⇒ Object
78
79
80
|
# File 'lib/ood_packaging/build_box.rb', line 78
def valid_dists
BASE_IMAGES.keys
end
|