-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.py
More file actions
executable file
·64 lines (53 loc) · 1.67 KB
/
update.py
File metadata and controls
executable file
·64 lines (53 loc) · 1.67 KB
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
#!/usr/bin/env python3
import glob
import re
from pathlib import Path
import os
from subprocess import Popen, PIPE
update_build = set(Path('update_build').read_text().splitlines())
update_push = set(Path('update_push').read_text().splitlines())
dockerfilepaths = [Path(dfp) for dfp in glob.glob("./*/Dockerfile")]
m = {}
for dockerfilepath in dockerfilepaths:
dockerfiletext = dockerfilepath.open('r').read()
f = str(dockerfilepath.parent)
t = re.match(r'^FROM.*', dockerfiletext).group()
if '-' not in t:
continue
t = t.split('-')[1]
if f not in m:
m[f] = set()
m[f].add(t)
completed = set()
def build(target, tag):
if (target in completed) or (target not in update_build):
return
if target in m:
for dep in m[target]:
build(dep, tag)
print("Building {}...".format(target))
p = Popen([
'docker',
'build',
'--no-cache',
'-t',
'brandonmosher/devcontainer-{}:{}'.format(target, tag),
Path(target).resolve()
], stdout=PIPE, stderr=PIPE, stdin=PIPE)
out = Path('{}.out'.format(target))
out.open('wb').write(p.stderr.read())
out.open('ab').write(p.stdout.read())
if target not in update_push:
return
cmd = 'docker push brandonmosher/devcontainer-{}:{}'.format(target, tag)
print("Pushing {}...".format(target))
p = Popen([
'docker',
'push',
'brandonmosher/devcontainer-{}:{}'.format(target, tag)
], stdout=PIPE, stderr=PIPE, stdin=PIPE)
out.open('ab').write(p.stderr.read())
out.open('ab').write(p.stdout.read())
completed.add(target)
for target in m:
build(target, 'latest')