1# Copyright 2018 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# Recipe which generates the Gold images for lottie-web using docker
6
7DEPS = [
8  'checkout',
9  'env',
10  'infra',
11  'recipe_engine/file',
12  'recipe_engine/path',
13  'recipe_engine/properties',
14  'recipe_engine/python',
15  'recipe_engine/step',
16  'run',
17  'vars',
18]
19
20
21DOCKER_IMAGE = 'gcr.io/skia-public/gold-lottie-web-puppeteer:v2'
22LOTTIECAP_SCRIPT = '/SRC/skia/infra/lottiecap/docker/lottiecap_gold.sh'
23
24
25def RunSteps(api):
26  api.vars.setup()
27  checkout_root = api.checkout.default_checkout_root
28  out_dir = api.vars.swarming_out_dir
29  lottie_files_src = api.vars.slave_dir.join('lottie-samples')
30  lottie_files_dir = '/tmp/lottie_files'
31  # The lottie-web repo is DEP'd in. This links to its build directory
32  # to make finding the lottie.min.js easier to reference from inside
33  # the docker image.
34  lottie_build = checkout_root.join('lottie', 'build', 'player')
35
36  api.checkout.bot_update(checkout_root=checkout_root)
37
38  # Make sure this exists, otherwise Docker will make it with root permissions.
39  api.file.ensure_directory('mkdirs out_dir', out_dir, mode=0777)
40  # When lottie files are brought in via isolate or CIPD, they are just
41  # symlinks, which does not work well with Docker because we can't mount
42  # the folder as a volume.
43  # e.g. /LOTTIE_FILES/foo.json -> ../.cipd/alpha/beta/foo.json
44  # To get around this, we just copy the lottie files into a temporary
45  # directory.
46  api.file.rmtree('remove previous lottie files', lottie_files_dir)
47  api.file.copytree('copy lottie files', lottie_files_src, lottie_files_dir)
48
49  api.python.inline(
50      name='Set up for docker',
51      program='''
52import os
53import sys
54
55lottie_files_dir = sys.argv[1]
56out_dir = sys.argv[2]
57lottie_build = sys.argv[3]
58
59# Make sure all the lottie files are readable by everyone so we can see
60# them in the docker container.
61os.system('chmod 0644 %s/*' % lottie_files_dir)
62os.system('chmod 0644 %s/*' % lottie_build)
63
64# Prepare output folder, api.file.ensure_directory doesn't touch
65# the permissions of the out directory if it already exists.
66# This typically means that the non-privileged docker won't be able to write.
67os.chmod(out_dir, 0o777)
68''',
69      args=[lottie_files_dir, out_dir, lottie_build],
70      infra_step=True)
71
72  cmd = ['docker', 'run', '--shm-size=2gb', '--rm',
73         '-v', '%s:/SRC' % checkout_root,
74         '-v', '%s:/OUT' % out_dir,
75         '-v', '%s:/LOTTIE_BUILD' % lottie_build,
76         '-v', '%s:/LOTTIE_FILES' % lottie_files_dir]
77
78  cmd.extend([
79         DOCKER_IMAGE,             LOTTIECAP_SCRIPT,
80         '--builder',              api.vars.builder_name,
81         '--git_hash',             api.properties['revision'],
82         '--buildbucket_build_id', api.properties.get('buildbucket_build_id',
83                                                      ''),
84         '--bot_id',               api.vars.swarming_bot_id,
85         '--task_id',              api.vars.swarming_task_id,
86         '--browser',              'Chrome',
87         '--config',               api.vars.configuration,
88         ])
89
90  if api.vars.is_trybot:
91    cmd.extend([
92      '--issue',         api.vars.issue,
93      '--patchset',      api.vars.patchset,
94      '--patch_storage', api.vars.patch_storage,
95    ])
96
97  # Override DOCKER_CONFIG set by Kitchen.
98  env = {'DOCKER_CONFIG': '/home/chrome-bot/.docker'}
99  with api.env(env):
100    api.run(
101        api.step,
102        'Create lottie-web Gold output with Docker',
103        cmd=cmd)
104
105
106def GenTests(api):
107  yield (
108      api.test('Test-Debian9-none-GCE-CPU-AVX2-x86_64-Debug-All-LottieWeb') +
109      api.properties(buildername=('Test-Debian9-none-GCE-CPU-AVX2'
110                                  '-x86_64-Debug-All-LottieWeb'),
111                     repository='https://skia.googlesource.com/skia.git',
112                     revision='abc123',
113                     path_config='kitchen',
114                     swarm_out_dir='[SWARM_OUT_DIR]')
115  )
116
117  yield (
118      api.test('lottie_web_trybot') +
119      api.properties(buildername=('Test-Debian9-none-GCE-CPU-AVX2'
120                                  '-x86_64-Debug-All-LottieWeb'),
121                     repository='https://skia.googlesource.com/skia.git',
122                     revision='abc123',
123                     path_config='kitchen',
124                     swarm_out_dir='[SWARM_OUT_DIR]',
125                     patch_ref='89/456789/12',
126                     patch_repo='https://skia.googlesource.com/skia.git',
127                     patch_storage='gerrit',
128                     patch_set=7,
129                     patch_issue=1234,
130                     gerrit_project='skia',
131                     gerrit_url='https://skia-review.googlesource.com/')
132  )
133