3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
6 from __future__
import unicode_literals
9 Extends FBCodeBuilder to produce Docker context directories. 11 In order to get the largest iteration-time savings from Docker's build 12 caching, you will want to: 13 - Use fine-grained steps as appropriate (e.g. separate make & make install), 14 - Start your action sequence with the lowest-risk steps, and with the steps 15 that change the least often, and 16 - Put the steps that you are debugging towards the very end. 24 from fbcode_builder
import FBCodeBuilder
25 from shell_quoting
import (
26 raw_shell, shell_comment, shell_join, ShellQuoted
28 from utils
import recursively_flatten_list, run_command
31 class DockerFBCodeBuilder(FBCodeBuilder):
34 return self.
option(
'user',
'root')
37 return ShellQuoted(
'USER {u}').
format(u=self.
_user())
45 return self.
step(
'Setup', [
49 ShellQuoted(
'SHELL ["/bin/bash", "-c"]'),
52 def step(self, name, actions):
53 assert '\n' not in name,
'Name {0} would span > 1 line'.
format(name)
55 return [ShellQuoted(
'### {0} ###'.
format(name)), b] + actions + [b]
57 def run(self, shell_cmd):
58 return ShellQuoted(
'RUN {cmd}').
format(cmd=shell_cmd)
66 ShellQuoted(
'USER root'),
67 ShellQuoted(
'RUN mkdir -p {d} && chown {u} {d}').
format(
71 ShellQuoted(
'WORKDIR {dir}').
format(dir=dir),
80 fd, archive_path = tempfile.mkstemp(
81 prefix=
'local_repo_{0}_'.
format(dest_name),
83 dir=os.path.abspath(self.
option(
'docker_context_dir')),
86 run_command(
'tar',
'czf', archive_path,
'.', cwd=repo_dir)
88 ShellQuoted(
'ADD {archive} {dest_name}').
format(
89 archive=os.path.basename(archive_path), dest_name=dest_name
92 ShellQuoted(
'USER root'),
93 ShellQuoted(
'RUN chown -R {u} {d}').
format(
94 d=dest_name, u=self.
_user()
103 source_ccache_tgz = self.
option(
'ccache_tgz',
'')
104 if not source_ccache_tgz:
105 logging.info(
'Docker ccache not enabled')
108 dest_ccache_tgz = os.path.join(
109 self.
option(
'docker_context_dir'),
'ccache.tgz' 114 os.link(source_ccache_tgz, dest_ccache_tgz)
117 'Hard-linking {s} to {d} failed, falling back to copy' 118 .
format(s=source_ccache_tgz, d=dest_ccache_tgz)
120 shutil.copyfile(source_ccache_tgz, dest_ccache_tgz)
123 'Failed to copy or link {s} to {d}, aborting' 124 .
format(s=source_ccache_tgz, d=dest_ccache_tgz)
130 self.
run(ShellQuoted(
'apt-get install -yq ccache')),
131 ShellQuoted(
'ADD ccache.tgz /'),
134 'ENV CCACHE_DIR=/ccache ' 136 'CC="ccache gcc" CXX="ccache g++" ' 148 'CCACHE_LOGFILE=/tmp/ccache.log' 150 self.
run(ShellQuoted(
158 'mkdir -p /ccache && time chown -R nobody /ccache && ' 159 'time du -sh /ccache && ' 162 'echo === Prev run stats === && ccache -s && ccache -z && ' 166 'date +%s > /FBCODE_BUILDER_CCACHE_START_TIME && ' 168 'chown nobody /tmp/ccache.log'
def step(self, name, actions)
def _render_impl(self, steps)
def recursively_flatten_list(l)
def debian_ccache_setup_steps(self)
def comment(self, comment)
def install_debian_deps(self)
def run_command(cmd, kwargs)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
def copy_local_repo(self, repo_dir, dest_name)
def option(self, name, default=None)
def shell_join(delim, it)