3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
6 from __future__
import unicode_literals
8 Reads `fbcode_builder_config.py` from the current directory, and prepares a 9 Docker context directory to build this project. Prints to stdout the path 10 to the context directory. 12 Try `.../make_docker_context.py --help` from a project's `build/` directory. 14 By default, the Docker context directory will be in /tmp. It will always 15 contain a Dockerfile, and might also contain copies of your local repos, and 16 other data needed for the build container. 23 from docker_builder
import DockerFBCodeBuilder
24 from parse_args
import parse_args_to_fbcode_builder_opts
28 get_steps_fn, github_project, opts=
None, default_context_dir=
None 31 Returns a path to the Docker context directory. See parse_args.py. 33 Helper for making a command-line utility that writes your project's 34 Dockerfile and associated data into a (temporary) directory. Your main 35 program might look something like this: 37 print(make_docker_context( 38 lambda builder: [builder.step(...), ...], 39 'facebook/your_project', 47 (
'ubuntu:16.04',
'5'),
52 '--docker-context-dir', metavar=
'DIR',
53 default=default_context_dir,
54 help=
'Write the Dockerfile and its context into this directory. ' 55 'If empty, make a temporary directory. Default: %(default)s.',
58 '--user', metavar=
'NAME', default=opts.get(
'user',
'nobody'),
59 help=
'Build and install as this user. Default: %(default)s.',
62 '--prefix', metavar=
'DIR',
63 default=opts.get(
'prefix',
'/home/install'),
64 help=
'Install all libraries in this prefix. Default: %(default)s.',
67 '--projects-dir', metavar=
'DIR',
68 default=opts.get(
'projects_dir',
'/home'),
69 help=
'Place project code directories here. Default: %(default)s.',
72 '--os-image', metavar=
'IMG', choices=
zip(*valid_versions)[0],
73 default=opts.get(
'os_image', valid_versions[0][0]),
74 help=
'Docker OS image -- be sure to use only ones you trust (See ' 75 'README.docker). Choices: %(choices)s. Default: %(default)s.',
78 '--gcc-version', metavar=
'VER',
79 choices=
set(
zip(*valid_versions)[1]),
80 default=opts.get(
'gcc_version', valid_versions[0][1]),
81 help=
'Choices: %(choices)s. Default: %(default)s.',
84 '--make-parallelism', metavar=
'NUM', type=int,
85 default=opts.get(
'make_parallelism', 1),
86 help=
'Use `make -j` on multi-CPU systems with lots of RAM. ' 87 'Default: %(default)s.',
90 '--local-repo-dir', metavar=
'DIR',
91 help=
'If set, build {0} from a local directory instead of Github.' 95 '--ccache-tgz', metavar=
'PATH',
96 help=
'If set, enable ccache for the build. To initialize the ' 97 'cache, first try to hardlink, then to copy --cache-tgz ' 98 'as ccache.tgz into the --docker-context-dir.' 105 'docker_context_dir',
116 help=textwrap.dedent(
''' 118 Reads `fbcode_builder_config.py` from the current directory, and 119 prepares a Docker context directory to build {github_project} and 120 its dependencies. Prints to stdout the path to the context 123 Pass --option {github_project}:git_hash SHA1 to build something 124 other than the master branch from Github. 126 Or, pass --option {github_project}:local_repo_dir LOCAL_PATH to 127 build from a local repo instead of cloning from Github. 130 (cd $(./make_docker_context.py) && docker build . 2>&1 | tee log) 132 '''.
format(github_project=github_project)),
136 local_repo_dir = opts.pop(
'local_repo_dir',
None)
137 if local_repo_dir
is not None:
138 opts[
'{0}:local_repo_dir'.
format(github_project)] = local_repo_dir
140 if (opts.get(
'os_image'), opts.get(
'gcc_version'))
not in valid_versions:
142 'Due to 4/5 ABI changes (std::string), we can only use {0}'.
format(
143 ' / '.
join(
'GCC {1} on {0}'.
format(*p)
for p
in valid_versions)
147 if opts.get(
'docker_context_dir')
is None:
148 opts[
'docker_context_dir'] = tempfile.mkdtemp(prefix=
'docker-context-')
149 elif not os.path.exists(opts.get(
'docker_context_dir')):
150 os.makedirs(opts.get(
'docker_context_dir'))
152 builder = DockerFBCodeBuilder(**opts)
153 context_dir = builder.option(
'docker_context_dir')
155 dockerfile = builder.render(get_steps_fn(builder))
157 with os.fdopen(os.open(
158 os.path.join(context_dir,
'Dockerfile'),
159 os.O_RDWR | os.O_CREAT | os.O_EXCL,
167 if __name__ ==
'__main__':
168 from utils
import read_fbcode_builder_config, build_fbcode_builder_config
174 config[
'github_project'],
def make_docker_context(get_steps_fn, github_project, opts=None, default_context_dir=None)
def build_fbcode_builder_config(config)
def read_fbcode_builder_config(filename)
def parse_args_to_fbcode_builder_opts(add_args_fn, top_level_opts, opts, help)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)