ostbuild: Add preserve_net config option

This is going to be necessary for the builder.
This commit is contained in:
Colin Walters 2012-03-13 17:06:06 -04:00
parent 5bf65be10b
commit 277843f3a2
6 changed files with 43 additions and 24 deletions

View File

@ -14,7 +14,7 @@ dependency problems.
At the end, the Yocto build process generates two tarballs: one for a At the end, the Yocto build process generates two tarballs: one for a
base "runtime", and one "devel" with all of the development tools like base "runtime", and one "devel" with all of the development tools like
gcc. We then import that into an OSTree branch gcc. We then import that into an OSTree branch
e.g. "bases/gnomeos-3.4-yocto-i686-devel". e.g. "bases/yocto/gnomeos-3.4-i686-devel".
We also have a Yocto recipe "ostree-native" which generates (as you We also have a Yocto recipe "ostree-native" which generates (as you
might guess) a native binary of ostree. That binary is used to import might guess) a native binary of ostree. That binary is used to import

View File

@ -21,6 +21,7 @@ import urlparse
import tempfile import tempfile
import StringIO import StringIO
from . import ostbuildrc
from .subprocess_helpers import run_sync_get_output from .subprocess_helpers import run_sync_get_output
BUILD_ENV = { BUILD_ENV = {
@ -141,3 +142,12 @@ def compose(repo, target, artifacts):
revision = run_sync_get_output(child_args, log_initiation=True).strip() revision = run_sync_get_output(child_args, log_initiation=True).strip()
os.unlink(path) os.unlink(path)
return revision return revision
def get_base_user_chroot_args():
path = find_user_chroot_path()
args = [path, '--unshare-pid', '--unshare-ipc']
if not ostbuildrc.get_key('preserve_net', default=False):
args.append('--unshare-net')
return args

View File

@ -208,6 +208,7 @@ class OstbuildBuild(builtins.Builtin):
parser = argparse.ArgumentParser(description=self.short_description) parser = argparse.ArgumentParser(description=self.short_description)
parser.add_argument('--skip-built', action='store_true') parser.add_argument('--skip-built', action='store_true')
parser.add_argument('--recompose', action='store_true') parser.add_argument('--recompose', action='store_true')
parser.add_argument('--skip-compose', action='store_true')
parser.add_argument('--start-at') parser.add_argument('--start-at')
parser.add_argument('--shell-on-failure', action='store_true') parser.add_argument('--shell-on-failure', action='store_true')
parser.add_argument('--debug-shell', action='store_true') parser.add_argument('--debug-shell', action='store_true')
@ -255,7 +256,8 @@ class OstbuildBuild(builtins.Builtin):
component = self.snapshot['components'].get(component_name) component = self.snapshot['components'].get(component_name)
self._build_one_component(component_name, component) self._build_one_component(component_name, component)
for target in self.snapshot['targets']: if not args.skip_compose:
self._compose(target) for target in self.snapshot['targets']:
self._compose(target)
builtins.register(OstbuildBuild) builtins.register(OstbuildBuild)

View File

@ -23,6 +23,7 @@ import json
from . import builtins from . import builtins
from . import buildutil from . import buildutil
from . import fileutil from . import fileutil
from . import ostbuildrc
from .ostbuildlog import log, fatal from .ostbuildlog import log, fatal
from .subprocess_helpers import run_sync, run_sync_get_output from .subprocess_helpers import run_sync, run_sync_get_output
@ -128,16 +129,15 @@ class OstbuildChrootCompileOne(builtins.Builtin):
chroot_sourcedir = os.path.join('/ostbuild', 'source', component_name) chroot_sourcedir = os.path.join('/ostbuild', 'source', component_name)
ostbuild_user_chroot_path = buildutil.find_user_chroot_path() child_args = buildutil.get_base_user_chroot_args()
child_args.extend([
child_args = [ostbuild_user_chroot_path, '--unshare-pid', '--unshare-net', '--unshare-ipc', '--mount-readonly', '/',
'--mount-readonly', '/', '--mount-proc', '/proc',
'--mount-proc', '/proc', '--mount-bind', '/dev', '/dev',
'--mount-bind', '/dev', '/dev', '--mount-bind', child_tmpdir, '/tmp',
'--mount-bind', child_tmpdir, '/tmp', '--mount-bind', os.getcwd(), chroot_sourcedir,
'--mount-bind', os.getcwd(), chroot_sourcedir, '--mount-bind', resultdir, '/ostbuild/results',
'--mount-bind', resultdir, '/ostbuild/results', '--chdir', chroot_sourcedir])
'--chdir', chroot_sourcedir]
if args.debug_shell: if args.debug_shell:
child_args.extend([rootdir, '/bin/sh']) child_args.extend([rootdir, '/bin/sh'])
else: else:

View File

@ -35,15 +35,11 @@ class OstbuildChrootRunTriggers(builtins.Builtin):
args = parser.parse_args(argv) args = parser.parse_args(argv)
ostbuild_user_chroot_path = buildutil.find_user_chroot_path() child_args = buildutil.get_base_user_chroot_args()
child_args.extend(['--mount-proc', '/proc',
child_args = [ostbuild_user_chroot_path, '--mount-bind', '/dev', '/dev',
'--unshare-pid', '--unshare-net', '--unshare-ipc', args.root,
'--mount-proc', '/proc', '/usr/bin/ostree-run-triggers'])
'--mount-bind', '/dev', '/dev',
args.root,
'/usr/bin/ostree-run-triggers']
print "%r" % (child_args,)
env_copy = dict(buildutil.BUILD_ENV) env_copy = dict(buildutil.BUILD_ENV)
env_copy['PWD'] = '/' env_copy['PWD'] = '/'
run_sync(child_args, env=env_copy) run_sync(child_args, env=env_copy)

View File

@ -31,11 +31,22 @@ def get():
_config[k.strip()] = v.strip() _config[k.strip()] = v.strip()
return _config return _config
def get_key(name, provided_args=None): # This hack is because we want people to be able to pass None
# for "default", but still distinguish default=None from default
# not passed.
_default_not_supplied = object()
def get_key(name, provided_args=None, default=_default_not_supplied):
global _default_not_supplied
config = get() config = get()
if provided_args: if provided_args:
v = provided_args.get(name) v = provided_args.get(name)
if v is not None: if v is not None:
return v return v
return config[name] if default is _default_not_supplied:
# Possibly throw a KeyError
return config[name]
value = config.get(name, _default_not_supplied)
if value is _default_not_supplied:
return default
return value