forked from maxking/docker-mailman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·79 lines (60 loc) · 1.61 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
73
74
75
76
77
78
79
#/usr/bin/env python3
# This is the build script to build container images for Mailman.
import sys
import subprocess
from pathlib import Path
STABLE_DOCKERFILES = {
'core-stable': Path('core/Dockerfile'),
'web-stable': Path('web/Dockerfile'),
'postorius-stable': Path('postorius/Dockerfile'),
}
ROLLING_DOCKERFILES = {
'core-rolling': Path('core/Dockerfile.dev'),
'web-rolling': Path('web/Dockerfile.dev'),
'postorius-rolling': Path('postorius/Dockerfile.dev'),
}
VARIANTS = {
'stable': STABLE_DOCKERFILES,
'rolling': ROLLING_DOCKERFILES,
}
def run_command(args):
print(' '.join(args))
subprocess.run(
args,
stdout=sys.stdout,
stderr=sys.stderr,
check=True)
def docker_build(dockerfile, tag, args=None, labels=None):
cmd = [
'docker', 'build',
'-t', tag,
'-f', str(dockerfile),
str(dockerfile.parent)
]
if args:
for arg in args:
cmd.append('--build-arg')
cmd.append(arg)
if labels:
for label in labels:
cmd.append('--label')
cmd.append(label)
return run_command(cmd)
def docker_tag(from_tag, to_tag):
cmd = [
'docker', 'tag',
from_tag, to_tag,
]
return run_command(cmd)
def usage():
print('usage: python build.py (stable|rolling)')
if __name__ == '__main__':
if len(sys.argv) < 2:
usage()
sys.exit(1)
variant = sys.argv[1]
if variant not in VARIANTS:
usage()
sys.exit(1)
for name, path in VARIANTS[variant].items():
docker_build(dockerfile=path, tag=name)