-
Notifications
You must be signed in to change notification settings - Fork 2
/
make.py
40 lines (27 loc) · 1.12 KB
/
make.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
#!/usr/bin/env python3
from pathlib import Path
import shutil
import re
ROOT = Path(__file__).parent
NOTEBOOKS_DIR = ROOT / 'notebooks'
TEMPLATE_DIR = ROOT / 'template'
# get the base Dockerfile text
DF_TEMPLATE = (TEMPLATE_DIR / 'Dockerfile').read_text()
def main():
shutil.rmtree(NOTEBOOKS_DIR, ignore_errors = True)
NOTEBOOKS_DIR.mkdir()
(NOTEBOOKS_DIR / 'DO_NOT_MODIFY').write_text(
'DO NOT MODIFY ANYTHING IN THIS DIRECTORY\nIT IS GENERATED BY make.py\n'
)
for base_image in (ROOT / 'BASE_IMAGES.txt').read_text().splitlines():
repo, image, tag = re.match(r'(.*)\/(.*):(.*)', base_image).groups()
our_image = 'htc-{}'.format(image)
image_dir = NOTEBOOKS_DIR / our_image
# copy everything but the Dockerfile, which will be done in the next step
shutil.copytree(TEMPLATE_DIR, image_dir, ignore = lambda *_: ['Dockerfile'])
# write out the the modified Dockerfile for this image
df = image_dir / 'Dockerfile'
df_text = DF_TEMPLATE.replace('<BASE_IMAGE>', base_image)
df.write_text(df_text)
if __name__ == '__main__':
main()