forked from odoo/docker
-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.py
executable file
·72 lines (49 loc) · 1.85 KB
/
build.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
#!/usr/bin/env python3
import toml
from datetime import datetime
from os import path
import os
import shutil
FORMAT = "%Y%m%d"
if 'CUR_DATE' in os.environ:
CUR_DATE = os.environ['CUR_DATE']
else:
CUR_DATE = datetime.now().strftime(FORMAT)
templates = {}
def get_template(template_name):
if template_name in templates:
return templates[template_name]
template_file = path.join("templates", template_name)
with open(template_file) as temp_in:
template = temp_in.read()
templates[template_name] = template
return template
with open("./versions.toml") as config_in:
config = toml.load(config_in)
defaults = config.get('defaults', {})
if path.exists("build"):
shutil.rmtree("build")
os.mkdir("build")
tags = []
for tag, config in config.get("odoo", {}).items():
config['tag'] = tag
config['created_date'] = datetime.now().isoformat()
config = dict(defaults, **config)
if 'release' not in config:
config['release'] = CUR_DATE
template = get_template(config.get('template'))
print("Building version tag %s" % tag, config)
os.mkdir(path.join("build", tag))
with open(path.join("build", tag, "Dockerfile"), "w") as fout:
fout.write(template % config)
shutil.copyfile(path.join("assets", config.get('config')), path.join("build", tag, "odoo.conf"))
shutil.copyfile(path.join("assets", config.get('entrypoint')), path.join("build", tag, "entrypoint.py"))
shutil.copyfile(path.join("assets", 'sudo-%s' % config.get('entrypoint')), path.join("build", tag, "sudo-entrypoint.py"))
os.chmod(path.join("build", tag, "entrypoint.py"), 0o775)
os.chmod(path.join("build", tag, "sudo-entrypoint.py"), 0o775)
tags.append(tag)
for tag in tags:
if path.exists(tag):
shutil.rmtree(tag)
shutil.move(path.join("build", tag), ".")
shutil.rmtree("build")