Module: OodPackaging::Utils

Included in:
Build, BuildBox, Package, RakeTask
Defined in:
lib/ood_packaging/utils.rb

Overview

Shared utility functions

Instance Method Summary collapse

Instance Method Details

#container_runtimeObject



33
34
35
# File 'lib/ood_packaging/utils.rb', line 33

def container_runtime
  podman_runtime? ? 'podman' : 'docker'
end

#ctr_gems_dirObject



91
92
93
# File 'lib/ood_packaging/utils.rb', line 91

def ctr_gems_dir
  File.join(ctr_scripts_dir, 'gems')
end

#ctr_gpg_dirObject



115
116
117
# File 'lib/ood_packaging/utils.rb', line 115

def ctr_gpg_dir
  File.join(ctr_home, '.gnupg')
end

#ctr_homeObject



107
108
109
# File 'lib/ood_packaging/utils.rb', line 107

def ctr_home
  File.join('/home', ctr_user)
end

#ctr_rpmmacrosObject



111
112
113
# File 'lib/ood_packaging/utils.rb', line 111

def ctr_rpmmacros
  File.join(ctr_home, '.rpmmacros')
end

#ctr_scripts_dirObject



87
88
89
# File 'lib/ood_packaging/utils.rb', line 87

def ctr_scripts_dir
  '/ondemand-packaging'
end

#ctr_userObject



103
104
105
# File 'lib/ood_packaging/utils.rb', line 103

def ctr_user
  'ood'
end

#docker_runtime?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ood_packaging/utils.rb', line 29

def docker_runtime?
  !podman_runtime?
end

#gpg_passphraseObject



99
100
101
# File 'lib/ood_packaging/utils.rb', line 99

def gpg_passphrase
  File.join(ctr_scripts_dir, '.gpgpass')
end

#gpg_private_keyObject



95
96
97
# File 'lib/ood_packaging/utils.rb', line 95

def gpg_private_key
  File.join(ctr_scripts_dir, 'ondemand.sec')
end

#nodejs_packageObject



81
82
83
84
85
# File 'lib/ood_packaging/utils.rb', line 81

def nodejs_package
  return "nodejs#{nodejs_version}" if dist == 'amzn2023'

  'nodejs'
end

#nodejs_versionObject



77
78
79
# File 'lib/ood_packaging/utils.rb', line 77

def nodejs_version
  '20'
end

#ondemand_repo_versionObject



57
58
59
# File 'lib/ood_packaging/utils.rb', line 57

def ondemand_repo_version
  '4.0'
end

#ondemand_rpm_repo_baseurlObject



61
62
63
# File 'lib/ood_packaging/utils.rb', line 61

def ondemand_rpm_repo_baseurl
  "https://yum.osc.edu/ondemand/build/#{ondemand_repo_version}/web/#{dist}/\\$basearch/"
end

#podman_runtime?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ood_packaging/utils.rb', line 25

def podman_runtime?
  @podman_runtime ||= ENV['CONTAINER_RT'] == 'podman' || ENV['container'] == 'podman'
end

#proj_rootObject



7
8
9
# File 'lib/ood_packaging/utils.rb', line 7

def proj_root
  File.expand_path(File.join(File.dirname(__FILE__), '../..'))
end

#rt_specific_flagsObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/ood_packaging/utils.rb', line 37

def rt_specific_flags
  if podman_runtime?
    # SELinux doesn't like it if you're mounting from $HOME
    [
      '--security-opt', 'label=disable'
    ]
  else
    ['--privileged', '--tty']
  end
end

#ruby_packageObject



71
72
73
74
75
# File 'lib/ood_packaging/utils.rb', line 71

def ruby_package
  return "ruby#{ruby_version}" if dist == 'amzn2023'

  'ruby'
end

#ruby_versionObject



65
66
67
68
69
# File 'lib/ood_packaging/utils.rb', line 65

def ruby_version
  return '3.2' if dist == 'amzn2023'

  '3.3'
end

#sedObject



18
19
20
21
22
23
# File 'lib/ood_packaging/utils.rb', line 18

def sed
  @sed ||= begin
    `which gsed 1>/dev/null 2>&1`
    $CHILD_STATUS.success? ? 'gsed' : 'sed'
  end
end

#tarObject



11
12
13
14
15
16
# File 'lib/ood_packaging/utils.rb', line 11

def tar
  @tar ||= begin
    `which gtar 1>/dev/null 2>&1`
    $CHILD_STATUS.success? ? 'gtar' : 'tar'
  end
end

#template_file(filename) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/ood_packaging/utils.rb', line 48

def template_file(filename)
  cwd = File.expand_path(__dir__).to_s
  src = File.join(cwd, filename)
  dest = File.join(cwd, filename.gsub('.erb', ''))
  content = ERB.new(File.read(src), trim_mode: '-').result(binding)
  File.open(dest, 'w') { |f| f.write(content) }
  dest
end