Skip to content
This repository was archived by the owner on Dec 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions dbuild/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def docker_build(build_dir, build_type, source_dir='source', force_rm=False,
docker_url='unix://var/run/docker.sock', dist='ubuntu',
release='trusty', extra_repos_file='repos',
extra_repo_keys_file='keys', build_cache=True, proxy="",
build_owner=None, **kwargs):
build_owner=None, parallel=1, **kwargs):
"""
build_dir: build directory, this directory will be mounted to /build in
container
Expand All @@ -117,6 +117,7 @@ def docker_build(build_dir, build_type, source_dir='source', force_rm=False,
proxy: value of proxy to be passed when used behind proxy settings
otherwise it will be default empty
build_owner: user id which will own all build files
parallel: how many processes to run in parallel
kwargs: dict of unknown arguments. Ignored. For forward compatibility.
"""

Expand All @@ -139,7 +140,7 @@ def docker_build(build_dir, build_type, source_dir='source', force_rm=False,
command += "dpkg-source -x /build/*.dsc /build/pkgbuild/ && \
cd /build/pkgbuild && \
/usr/lib/pbuilder/pbuilder-satisfydepends && \
dpkg-buildpackage -b -uc -us -j"
dpkg-buildpackage -b -uc -us -j{}".format(parallel)
cwd = '/build'
else:
raise exceptions.DbuildBuildFailedException(
Expand Down Expand Up @@ -230,6 +231,8 @@ def main(argv=sys.argv):
'otherwise it will be default empty')
ap.add_argument('--build-owner', action='store', type=int,
help='uid to reassign everything to')
ap.add_argument('--parallel', '-j', action='store', type=int,
default=1, help='how many processes to run in parallel')
args = ap.parse_args(argv)

try:
Expand All @@ -254,7 +257,8 @@ def main(argv=sys.argv):
extra_repos_file=args.extra_repos_file,
extra_repo_keys_file=args.extra_repo_keys_file,
build_cache=args.build_cache, proxy=args.proxy,
build_owner=args.build_owner)
build_owner=args.build_owner,
parallel=args.parallel)
except exceptions.DbuildBinaryBuildFailedException:
print('ERROR | Binary build failed for build directory: %s'
% args.build_dir)
Expand Down
14 changes: 12 additions & 2 deletions dbuild/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,16 @@ def test_build(self):
shutil.copytree(os.path.join(os.path.dirname(__file__), 'test_data', 'pkg1'),
os.path.join(tmpdir, 'source'))
dbuild.docker_build(tmpdir, build_type='source', build_owner=os.getuid())
dbuild.docker_build(tmpdir, build_type='binary', build_owner=os.getuid())

create_container_real = dbuild.create_container

# Spy on the calls to create_container
with mock.patch('dbuild.create_container') as create_container:
create_container.side_effect = lambda *args, **kwargs: create_container_real(*args, **kwargs)

dbuild.docker_build(tmpdir, build_type='binary', build_owner=os.getuid(), parallel=7)
self.assertIn('-j7', create_container.call_args[1]['command'][2])

for f in ['buildsvctest_0.1.dsc', 'buildsvctest_0.1.tar.gz',
'buildsvctest_0.1_amd64.changes', 'buildsvctest_0.1_amd64.deb',
'buildsvctest_0.1_source.changes']:
Expand Down Expand Up @@ -168,4 +177,5 @@ def test_build_cli(self, docker_build):
build_type='binary', dist='ubuntu',
docker_url='unix://var/run/docker.sock',
extra_repo_keys_file='keys', extra_repos_file='repos',
force_rm=False, proxy='', release='trusty', source_dir='source')])
force_rm=False, proxy='', parallel=1, release='trusty',
source_dir='source')])