-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-via-yum
executable file
·59 lines (51 loc) · 1.84 KB
/
build-via-yum
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
#!/usr/bin/env python
import os
import sys
import subprocess
import tempfile
import shutil
import argparse
def fatal(msg):
sys.stdout.write(msg + '\n')
sys.exit(1)
def run_sync(argv, **kwargs):
print "%s" % (subprocess.list2cmdline(argv), )
sys.stdout.flush()
subprocess.check_call(argv, **kwargs)
parser = argparse.ArgumentParser(description='Create base image')
parser.add_argument('--target', action='store', help='centos or fedora', required=True)
parser.add_argument('--releasever', action='store', help='Release version', required=True)
args = parser.parse_args()
if args.target == 'centos':
cmd=['yum']
elif args.target == 'fedora':
cmd=['dnf', '--setopt=install_weak_deps=False']
else:
fatal("Unknown target {}".format(args.target))
imgname = args.target + 'min'
tempdir = tempfile.mkdtemp('dockerbase')
root = tempdir + '/root'
try:
for setopt in ['cachedir=' + os.getcwd() + '/cache',
'keepcache=1',
'tsflags=nodocs',
'override_install_langs=en',
'reposdir={}/repos-{}'.format(os.getcwd(), args.target)]:
cmd.append('--setopt=' + setopt)
cmd.extend(['-y', '--releasever=' + args.releasever,
'--installroot={}'.format(root),
'install',
'micro-yuminst', '{}-release'.format(args.target)])
run_sync(cmd)
# We need to run this in target context in the general case
run_sync(['install', '-m', '0755', 'locales.sh', '{}/tmp'.format(root)])
run_sync(['chroot', root, '/tmp/locales.sh'])
run_sync(['./postprocess.sh', root])
tarname = '{}-{}.tar.gz'.format(imgname, args.releasever)
try:
os.unlink(tarname)
except:
pass
run_sync(['tar', '--numeric-owner', '-zf', tarname, '-C', root, '-c', '.'])
finally:
subprocess.call(['rm', '-rf', tempdir])