-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconventions.py
executable file
·206 lines (156 loc) · 5.16 KB
/
conventions.py
1
2
3
4
5
6
7
8
9
10
11
12
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env python3
import argparse
# Purposes:
# Functions containing naming conventions for images, dockerfiles, tags
def supported_osnames():
return ['fedora36', 'almalinux94', 'ubuntu24']
def supported_cvmfs_osnames():
return [f'cvmfs-{osname}' for osname in supported_osnames()]
def supported_geant4_versions():
return ['10.6.2', '10.7.4', '11.3.0']
def modules_path_base_dir():
return '/cvmfs/oasis.opensciencegrid.org/jlab'
def modules_path():
return modules_path_base_dir() + '/geant4/modules'
def localSetupFilename():
return '/etc/profile.d/localSetup.sh'
def dockerfile_name(image):
return 'dockerfiles/Dockerfile-' + image
def is_base_container(image):
if image in supported_osnames() or image in supported_cvmfs_osnames():
return True
return False
def is_fedora_line(image):
if 'fedora' in image or 'almalinux' in image:
return True
return False
def is_alma_line(image):
if 'almalinux' in image:
return True
return False
def is_ubuntu_line(image):
if 'ubuntu' in image:
return True
return False
def is_cvmfs_image(image):
if image.startswith('cvmfs'):
return True
return False
def is_geant4_image(image):
if 'g4v' in image:
return True
return False
def is_gemc_image(image):
if 'gemc' in image:
return True
return False
def jlab_certificate():
return "/etc/pki/ca-trust/source/anchors/JLabCA.crt"
# execute system curl command to download file
# notice: both the cacert and the -k option are given here. For some reason the cacert option
# was not enough on fedora line OSes
# see also https://curl.se/docs/sslcerts.html
def curl_command(filename):
return f'curl -S --location-trusted --progress-bar --retry 4 --cacert {jlab_certificate()} {filename} -k -O'
def from_image(requested_image):
if requested_image.count('-') == 0 or 'cvmfs' in requested_image:
return os_base_image_from_imagename(requested_image)
# sim image, requesting base image
elif is_geant4_image(requested_image):
return base_imagename_from_sim(requested_image)
# gemc image, requesting sim image
elif is_gemc_image(requested_image):
return geant4_imagename_from_gemc(requested_image)
def os_base_image_from_imagename(requested_image):
if 'fedora36' in requested_image:
return 'fedora:36'
elif 'almalinux94' in requested_image:
return 'almalinux:9.4'
elif 'ubuntu24' in requested_image:
return 'ubuntu:24.04'
else:
# not supported
print(f'Error: platform {requested_image} not supported')
exit(1)
def base_imagename_from_sim(requested_image):
for osname in supported_osnames():
if osname in requested_image:
from_image = 'jeffersonlab/base:' + osname
return from_image
def geant4_imagename_from_gemc(requested_image):
from_image = 'jeffersonlab/geant4:g4v' + g4_version_from_image(
requested_image) + '-' + osname_from_image(requested_image)
return from_image
def osname_from_image(requested_image):
if is_base_container(requested_image):
return requested_image
elif is_cvmfs_image(requested_image):
return requested_image.split('-')[1]
elif is_geant4_image(requested_image):
return requested_image.split('-')[1]
elif is_gemc_image(requested_image):
return requested_image.split('-')[2]
else:
print(f'Error: osname {requested_image} not supported')
exit(1)
def g4_version_from_image(requested_image):
# return the string between 'g4v' and '-'
if 'g4v' in requested_image:
return requested_image.split('g4v')[1].split('-')[0]
elif 'gemc' in requested_image:
gtag = requested_image.split('-')[1]
if gtag == 'prod1':
return '10.6.2'
elif gtag == 'dev':
return '10.7.4'
else:
print(f'g4_version_from_image error: tag {gtag} not supported for {requested_image}')
exit(1)
else:
print(f'Error: geant4 version not found in {requested_image}')
exit(1)
# as of july 2024:
# prod1: gemc versions 4.4.2
# dev: gemc versions 5.10, dev
def gemc_tags_from_docker_image(image):
gtag = image.split('-')[1]
if gtag == 'prod1':
return ['4.4.2']
elif gtag == 'dev':
return ['5.10', 'dev']
# return ['2.12', '5.10', 'dev']
else:
print(f'gemc_tags_from_docker_image error: tag {gtag} not supported')
exit(1)
def main():
desc_str = 'Naming for images, dockerfile, tags'
example = 'Example: -i fedora36'
parser = argparse.ArgumentParser(description=desc_str, epilog=example)
parser.add_argument('-i', action='store', help='FROM container image based on what to build')
args = parser.parse_args()
image = args.i
if image:
osname = osname_from_image(image)
modulespath = modules_path()
from_label = from_image(image)
dockerfile = dockerfile_name(image)
g4_version = g4_version_from_image(image)
gemc_tags = gemc_tags_from_docker_image(image)
print()
print(f'Supported images:\t {supported_osnames()}')
print(f'Supported cvmfs images:\t {supported_cvmfs_osnames()}')
if image.split('-')[0] != 'cvmfs':
print(f'Supported geant4 versions:\t {supported_geant4_versions()}')
print()
print(f'OS Name: {osname}')
print(f'Modules Directory: {modulespath}')
print(f'FROM Label: {from_label}')
print(f'Dockerfile: {dockerfile}')
print()
if g4_version != 'na':
print(f'Geant4 Version: {g4_version}')
if gemc_tags:
print(f'clas12 tags:\t\t {gemc_tags}')
print()
if __name__ == "__main__":
main()