-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
executable file
·54 lines (50 loc) · 1.93 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
#!/usr/bin/env python3
# vim:ts=4:sts=4:sw=4:expandtab
import os
import re
import subprocess
import traceback
IMAGES_SPEC='IMAGES'
REPOSITORIES_SPEC='REPOSITORIES'
PROJECT_PATH=os.path.dirname(__file__)
IMAGES_PATH=os.path.join(PROJECT_PATH, IMAGES_SPEC)
REPOSITORIES_PATH=os.path.join(PROJECT_PATH, REPOSITORIES_SPEC)
DFILE='Dockerfile'
TEMPTAG='kolejkatemp'
repositories=[]
with open(REPOSITORIES_PATH) as repositories_file:
for line in repositories_file.readlines():
line = line.strip()
if line.startswith('#'):
continue
repositories.append(line)
with open(IMAGES_PATH) as images_file:
for line in images_file.readlines():
line = line.strip()
if line.startswith('#'):
continue
m = re.match(r'([a-z]+):([a-z.0-9]+)', line)
if m:
repository = m.group(1)
tag = m.group(2)
build_dir = os.path.join(PROJECT_PATH, repository, tag)
dfile_path = os.path.join(build_dir, DFILE)
try:
build_tag = TEMPTAG+'/'+repository+':'+tag
subprocess.run(['docker', 'build', '--no-cache', os.path.dirname(dfile_path), '--tag', build_tag], check=True)
for repo in repositories:
try:
if repo == TEMPTAG:
continue
pub_tag = repo + '/'+repository+':'+tag
subprocess.run(['docker', 'rmi', pub_tag])
subprocess.run(['docker', 'tag', build_tag, pub_tag], check=True)
subprocess.run(['docker', 'push', pub_tag])
except:
traceback.print_exc()
pass
if (TEMPTAG not in repositories) and (len(repositories) > 0):
subprocess.run(['docker', 'rmi', build_tag])
except:
traceback.print_exc()
pass