generated from UCL-MIRSG/mirsg-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_docker_label.py
50 lines (36 loc) · 1.43 KB
/
generate_docker_label.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
"""generate_docker_label.py
Creates a docker label for use with the XNAT container service.
This script is for generating a label which you manually add to the Dockerfile.
You do not need to use this script if your labels are automatically generated
as part of the automated GitHub Actions automated Docker image build process.
Before using this script you must have one or more JSON command definition
files which describe the commands that will run with your docker image.
See the XNAT documentation:
https://wiki.xnat.org/container-service/json-command-definition
Run this script in the directory containing all your JSON command definition
files:
python ./generate_docker_label.py
This will output to the command line a LABEL statement which can be added to
your Dockerfile.
"""
import json
import os
def main():
repo_dir = os.getcwd()
command_list = []
for file in os.listdir(repo_dir):
if file.endswith(".json"):
with open(file) as f:
command_object = json.load(f)
command_string = (
json.dumps(command_object)
.replace("\\", "\\\\")
.replace('"', '\\"')
.replace("$", "\\$")
)
command_list.append(command_string)
commands = ", \\\n\t".join(command_list)
label = f'org.nrg.commands="[{commands}]"'
print(f"LABEL {label}")
if __name__ == "__main__":
main()