forked from deadsnakes/runbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·69 lines (59 loc) · 2.2 KB
/
build
File metadata and controls
executable file
·69 lines (59 loc) · 2.2 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
64
65
66
67
68
69
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import os.path
import subprocess
import sys
from typing import NoReturn
HERE = os.path.abspath(os.path.dirname(__file__))
def main() -> NoReturn:
parser = argparse.ArgumentParser()
parser.add_argument('--source', action='store_true')
parser.add_argument('--git-build', action='store_true')
args = parser.parse_args()
print('*' * 79)
print('Parsing target distribution')
print('*' * 79)
dist = subprocess.check_output((
'dpkg-parsechangelog', '--show-field=distribution',
)).decode().strip()
tag = f'ghcr.io/deadsnakes/{dist}'
print('*' * 79)
print(f'Pulling image (tag: {tag})')
print('*' * 79)
subprocess.check_call((os.path.join(HERE, 'pull-image'), tag))
print('*' * 79)
print('Running build (results will be in ../dist)')
print('*' * 79)
os.makedirs('../dist', exist_ok=True)
pwd = os.getcwd()
home = os.environ['HOME']
gbp_args = '' if args.source else '-us -uc'
gbp_args += (
'' if not args.git_build else
' --git-pristine-tar-commit '
"--git-upstream-tag='deadsnakes/v%(version%~%_)s'"
)
extra = '--git-builder="debuild -S"' if args.source else ''
prog = (
f'apt-get update -qq && '
f'mk-build-deps --install --remove --tool "apt-get --yes" /code/debian/control && ' # noqa: E501
f'cp -r /code /tmp && '
f'cd /tmp/code && '
f'git config --global user.name "Anthony Sottile" && '
f'git config --global user.email "asottile@umich.edu" && '
f'gbp buildpackage {gbp_args} --git-pristine-tar --git-debian-branch=ubuntu/{dist} {extra} && ' # noqa
f'find .. -maxdepth 1 -type f | xargs --replace cp {{}} /dist'
)
interactive = '-ti' if sys.stdin.isatty() else '-i'
cmd = (
'docker', 'run', '--rm', interactive,
'-v', f'{pwd}:/code:ro',
'-v', f'{pwd}/../dist:/dist:rw',
'-v', f'{home}/.gnupg/pubring.gpg:/root/.gnupg/pubring.gpg:ro',
'-v', f'{home}/.gnupg/secring.gpg:/root/.gnupg/secring.gpg:ro',
tag, 'bash', '-euxc', prog,
)
os.execvp(cmd[0], cmd)
if __name__ == '__main__':
raise SystemExit(main())