-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-images.py
executable file
·149 lines (114 loc) · 3.12 KB
/
build-images.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! /usr/bin/env python3
import argparse
import os
import pathlib
import subprocess
import sys
THIS_DIR = pathlib.Path(__file__).parent
IMAGE_PREFIX = "joshuawatt"
def get_image_tag(name, tag):
return "%s/%s:%s" % (IMAGE_PREFIX, name, tag)
def build_crops(tag, push):
tag = get_image_tag("crops-ubuntu-20.04", tag)
env = os.environ.copy()
env["DOCKER_BUILDKIT"] = "1"
dockerfile = (
THIS_DIR
/ "yocto-dockerfiles"
/ "dockerfiles"
/ "ubuntu"
/ "ubuntu-20.04"
/ "ubuntu-20.04-base"
/ "Dockerfile"
)
subprocess.run(
[
"docker",
"build",
"-t",
tag,
"-f",
dockerfile,
THIS_DIR / "yocto-dockerfiles",
],
env=env,
check=True,
)
if push:
subprocess.run(["docker", "push", tag], check=True)
def build_labgrid(image, push=False):
p = subprocess.run(
["python3", "./setup.py", "--version"],
cwd=THIS_DIR / "labgrid",
stdout=subprocess.PIPE,
check=True,
)
version = p.stdout.decode("utf-8").rstrip().splitlines()[-1]
tag = "%s/%s" % (IMAGE_PREFIX, image)
env = os.environ.copy()
env["DOCKER_BUILDKIT"] = "1"
subprocess.run(
[
"docker",
"build",
"-t",
tag,
"-f",
THIS_DIR / "labgrid" / "dockerfiles" / "Dockerfile",
"--target",
image,
"--build-arg",
"VERSION=%s" % version,
THIS_DIR / "labgrid",
],
env=env,
check=True,
)
if push:
subprocess.run(["docker", "push", tag], check=True)
def build_coordinator(push=False):
build_labgrid("labgrid-coordinator", push)
def build_exporter(push=False):
build_labgrid("labgrid-exporter", push)
def build_pdudaemon(tag, push):
tag = get_image_tag("pdudaemon", tag)
subprocess.run(
[
"docker",
"build",
"-t",
tag,
"-f",
THIS_DIR / "pdudaemon" / "Dockerfile.dockerhub",
THIS_DIR / "pdudaemon",
],
check=True,
)
if push:
subprocess.run(["docker", "push", tag], check=True)
def build_go_http_tunnel(tag, push):
tag = get_image_tag("go-http-tunnel", tag)
subprocess.run(
[
"docker",
"build",
"-t",
tag,
"-f",
THIS_DIR / "dockerfiles" / "go-http-tunnel" / "Dockerfile",
THIS_DIR / "dockerfiles" / "go-http-tunnel",
],
check=True,
)
if push:
subprocess.run(["docker", "push", tag], check=True)
def main():
parser = argparse.ArgumentParser(description="Build container images")
parser.add_argument("tag", help="Image tag")
parser.add_argument("--push", help="Push images to server", action="store_true")
args = parser.parse_args()
build_crops(args.tag, args.push)
build_pdudaemon(args.tag, args.push)
build_go_http_tunnel(args.tag, args.push)
if __name__ == "__main__":
sys.exit(main())