-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.py
More file actions
executable file
·94 lines (82 loc) · 3.31 KB
/
header.py
File metadata and controls
executable file
·94 lines (82 loc) · 3.31 KB
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
#!/usr/bin/env python3
import argparse
from conventions import *
# Purposes:
# Return commands to satisfy container prerequisites
def copy_files(image):
copy_string = ''
localSetupFile = localSetupFilename()
if is_base_container(image):
copy_string += 'COPY bg_merge_bk_file.sh /bin/bg_merge_bk_file.sh\n'
copy_string += f'COPY localSetupBase.sh {localSetupFile}\n\n'
return copy_string
# the destination is hardcoded, and must be mimicked in ceInstall functions.zsh
def load_jlab_certificate(image):
jcertificate = jlab_certificate()
certificate_string = ''
if is_base_container(image):
certificate_string += '# JLab certificate\n'
certificate_string += f'ADD https://pki.jlab.org/JLabCA.crt {jcertificate}\n'
if is_fedora_line(image):
certificate_string += 'RUN update-ca-trust \n\n'
if is_alma_line(image):
certificate_string += '# alma specific:\n'
certificate_string += '# crb: for mysql-devel\n'
certificate_string += '# synergy: root, scons, vnc\n'
certificate_string += 'RUN dnf install -y \'dnf-command(config-manager)\' \\\n'
certificate_string += ' && dnf config-manager --set-enabled crb \\\n'
certificate_string += ' && dnf install -y almalinux-release-synergy \n\n'
elif is_ubuntu_line(image):
certificate_string += '# Update needed at beginning to use the right package repos\n'
certificate_string += 'RUN apt update\n'
certificate_string += '\n'
certificate_string += '# Install ca-certificates tools\n'
certificate_string += 'RUN apt-get install -y ca-certificates\n'
certificate_string += '\n'
certificate_string += 'RUN update-ca-certificates \n\n'
return certificate_string
def main():
desc_str = 'Header for dockerfile'
example = 'Example: -i fedora36'
parser = argparse.ArgumentParser(description=desc_str, epilog=example)
parser.add_argument('-i', action='store', help='Docker header based on image to build')
args = parser.parse_args()
image = args.i
if image:
header = create_dockerfile_header(image)
print(header)
def create_dockerfile_header(image):
from_label = from_image(image)
localSetupFile = localSetupFilename()
header = f'FROM {from_label} \n'
header += 'LABEL maintainer="Maurizio Ungaro <ungaro@jlab.org>"\n\n'
header += '# run shell instead of sh\n'
header += 'SHELL ["/bin/bash", "-c"]\n'
header += 'ENV AUTOBUILD=1\n\n'
header += copy_files(image)
header += load_jlab_certificate(image)
if is_cvmfs_image(image):
header += install_pelican(image)
if is_cvmfs_image(image) or is_geant4_image(image):
header += f'RUN echo "module use { modules_path()}" >> {localSetupFile} \n'
if is_geant4_image(image):
header += f'RUN echo "module load geant4/{g4_version_from_image(image)}" >> {localSetupFile} \n\n'
if is_gemc_image(image):
tags = gemc_tags_from_docker_image(image)
if len(tags) >= 2:
gemc_to_load = tags[-2]
else:
gemc_to_load = tags[0] # or None, or handle differently depending on your logic
header += f'RUN echo "module load gemc/{gemc_to_load}" >> {localSetupFile} \n\n'
header += '\n'
return header
# install pelican
def install_pelican(image):
commands = ''
if is_alma_line(image):
commands = '\n'
commands += '# pelican RPM repository\n'
commands += f'RUN rpm -i https://repo.osg-htc.org/osg/24-main/osg-24-main-el9-release-latest.rpm \n\n'
return commands
if __name__ == "__main__":
main()