• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
6from . import default
7
8"""Docker flavor, used for running inside a Docker container."""
9
10
11# TODO(dogben): Move this mapping to a machine-editable file.
12# TODO(dogben): Use images without extra packages installed.
13IMAGES = {
14    'gcc-debian10': (
15        'gcr.io/skia-public/gcc-debian10@sha256:'
16        '89a72df1e2fdea6f774a3fa4199bb9aaa4a0526a3ac1f233e604d689b694f95c'),
17    'gcc-debian10-x86': (
18        'gcr.io/skia-public/gcc-debian10-x86@sha256:'
19        'b1ec55403ac66d9500d033d6ffd7663894d32335711fbbb0fb4c67dfce812203'),
20}
21
22
23class DockerFlavor(default.DefaultFlavor):
24  def __init__(self, m):
25    super(DockerFlavor, self).__init__(m)
26
27  def _map_host_path_to_docker(self, path):
28    """Returns the path in the Docker container mapped to the given path.
29
30    Returns None if the path is not mapped into the Docker container.
31    """
32    path = str(path)
33    for (docker_dir, host_dir) in [
34        (self.m.docker.mount_out(), str(self.m.vars.swarming_out_dir)),
35        (self.m.docker.mount_src(), str(self.m.path['start_dir'])),
36    ]:
37      if path.startswith(host_dir):
38        return docker_dir + path[len(host_dir):]
39    return None
40
41  def step(self, name, cmd, **unused_kwargs):
42    extra_tokens = [t for t in self.m.vars.extra_tokens if t != 'Docker']
43    os = self.m.vars.builder_cfg.get('os', '')
44    model = self.m.vars.builder_cfg.get('model', '')
45    cpu_or_gpu = self.m.vars.builder_cfg.get('cpu_or_gpu', '')
46    arch = self.m.vars.builder_cfg.get('arch', '')
47
48    image_name = None
49    if (os == 'Debian10' and model == 'GCE' and cpu_or_gpu == 'CPU' and
50        not extra_tokens):
51      if arch == 'x86_64':
52        image_name = 'gcc-debian10'
53      elif arch == 'x86':
54        image_name = 'gcc-debian10-x86'
55
56    if not image_name:  # pragma: nocover
57      raise Exception('Not implemented: ' + self.m.vars.builder_name)
58
59    image_hash = IMAGES[image_name]
60
61    # TODO(dogben): Currently Linux-specific.
62    app = self._map_host_path_to_docker(self.device_dirs.bin_dir.join(cmd[0]))
63    args = [self.m.docker.mount_src(), 'catchsegv', app] + [
64        self._map_host_path_to_docker(x) or x for x in cmd[1:]]
65    self.m.docker.run('symbolized %s in Docker' % name, image_hash,
66                      self.m.path['start_dir'], self.m.vars.swarming_out_dir,
67                      self.module.resource('symbolize_stack_trace.py'),
68                      args=args)
69