Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: blimp/tools/create-bundle.py

Issue 2154873002: Update ADD handling in Dockerfiles and test bundle creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clarifying new script behavior in comments and argument naming. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''Bundles the Blimp target and its runtime dependencies into a tarball. 6 '''Bundles the Blimp target and its runtime dependencies into a tarball.
7 7
8 The created bundle can be passed as input to docker build. E.g. 8 The created bundle can be passed as input to docker build. E.g.
9 docker build - < ../../out-linux/Debug/blimp_engine_deps.tar.gz 9 docker build - < ../../out-linux/Debug/blimp_engine_deps.tar.gz
10 ''' 10 '''
11 11
12 12
13 import argparse 13 import argparse
14 import os 14 import os
15 import subprocess 15 import subprocess
16 import sys 16 import sys
17 17
18 def ReadDependencies(manifest): 18 def ReadDependencies(manifest, relative_path):
19 """Read the manifest and return the list of dependencies. 19 """Read the manifest. Takes each dependency found within prepends it with
maniscalco 2016/07/19 21:52:36 nit: Need a comma between "within" and "prepends".
Jess 2016/07/19 22:32:41 Done.
20 relative path (optional), normalizes the resulting combined path, and adds
21 it to the returned dependency list.
20 :raises IOError: if the manifest could not be read. 22 :raises IOError: if the manifest could not be read.
21 """ 23 """
22 deps = [] 24 dependency_list = []
23 with open(manifest) as f: 25 with open(manifest) as f:
24 for line in f.readlines(): 26 for line in f.readlines():
25 # Strip comments. 27 # Strip comments.
26 dep = line.partition('#')[0].strip() 28 dependency = line.partition('#')[0].strip()
27 # Ignore empty strings. 29 # Ignore empty strings.
28 if dep: 30 if dependency:
29 deps.append(dep) 31 if relative_path != '':
maniscalco 2016/07/19 21:52:36 I'm no python expert, but I believe the idiomatic
Jess 2016/07/19 22:32:41 Acknowledged. Comment below overrides.
30 return deps 32 dependency = os.path.normpath(os.path.join(relative_path, dependency))
33 dependency_list.append(dependency)
34 return dependency_list
31 35
32 def main(): 36 def main():
33 parser = argparse.ArgumentParser(description=__doc__) 37 parser = argparse.ArgumentParser(description=__doc__)
34 parser.add_argument('--build-dir', 38 parser.add_argument('--build-dir',
35 help=('build output directory (e.g. out/Debug)'), 39 help=('build output directory (e.g. out/Debug)'),
36 required=True, 40 required=True,
37 metavar='DIR') 41 metavar='DIR')
38 parser.add_argument('--filelist', 42 parser.add_argument('--filelist',
39 help=('optional space separated list of files (e.g. ' 43 help=('optional space separated list of files (e.g. '
40 'Dockerfile and startup script) to add to the ' 44 'Dockerfile and startup script) to add to the '
41 'bundle'), 45 'bundle'),
42 required=False, 46 required=False,
43 metavar='FILE', 47 metavar='FILE',
44 nargs='*') 48 nargs='*')
45 parser.add_argument('--manifest', 49 parser.add_argument('--manifest',
46 help=('file listing the set of files to include in ' 50 help=('file listing the set of files to include in '
47 'the bundle'), 51 'the bundle'),
48 required=True) 52 required=True)
49 parser.add_argument('--output', 53 parser.add_argument('--output',
50 help=('name and path of bundle to create'), 54 help=('name and path of bundle to create'),
51 required=True, 55 required=True,
52 metavar='FILE') 56 metavar='FILE')
57 parser.add_argument('--tar-contents-rooted-in',
58 help=('optional path prefix to use inside the resulting '
59 'tar file.'),
maniscalco 2016/07/19 21:52:36 nit: Remove the period at the end of the help text
Jess 2016/07/19 22:32:41 Done.
60 required=False,
61 metavar='DIR')
53 args = parser.parse_args() 62 args = parser.parse_args()
54 63
55 deps = ReadDependencies(args.manifest) 64 dependencies_path = args.build_dir
65 if args.tar_contents_rooted_in:
66 dependencies_path = args.tar_contents_rooted_in
67 relative_path = os.path.relpath(args.build_dir, dependencies_path)
maniscalco 2016/07/19 21:52:36 So relative_path is always non-empty, right? If t
Jess 2016/07/19 22:32:41 Ah, even cleaner.
68
69 dependency_list = ReadDependencies(args.manifest, relative_path)
56 70
57 try: 71 try:
58 env = os.environ.copy() 72 env = os.environ.copy()
59 # Use fastest possible mode when gzipping. 73 # Use fastest possible mode when gzipping.
60 env["GZIP"] = "-1" 74 env["GZIP"] = "-1"
61 subprocess_args = [ 75 subprocess_args = [
62 "tar", 76 "tar",
63 "-zcf", args.output, 77 "-zcf", args.output,
64 # Ensure tarball content group permissions are appropriately set for 78 # Ensure tarball content group permissions are appropriately set for
65 # use as part of a "docker build". That is group readable with 79 # use as part of a "docker build". That is group readable with
66 # executable files also being group executable. 80 # executable files also being group executable.
67 "--mode=g+rX", 81 "--mode=g+rX",
68 "-C", args.build_dir] + deps 82 "-C", dependencies_path] + dependency_list
69 for f in args.filelist: 83 for f in args.filelist:
70 dirname, basename = os.path.split(f) 84 dirname, basename = os.path.split(f)
71 subprocess_args.extend(["-C", dirname, basename]) 85 subprocess_args.extend(["-C", dirname, basename])
72 subprocess.check_output( 86 subprocess.check_output(
73 subprocess_args, 87 subprocess_args,
74 # Redirect stderr to stdout, so that its output is captured. 88 # Redirect stderr to stdout, so that its output is captured.
75 stderr=subprocess.STDOUT, 89 stderr=subprocess.STDOUT,
76 env=env) 90 env=env)
77 except subprocess.CalledProcessError as e: 91 except subprocess.CalledProcessError as e:
78 print >> sys.stderr, "Failed to create tarball:" 92 print >> sys.stderr, "Failed to create tarball:"
79 print >> sys.stderr, e.output 93 print >> sys.stderr, e.output
80 sys.exit(1) 94 sys.exit(1)
81 95
82 if __name__ == "__main__": 96 if __name__ == "__main__":
83 main() 97 main()
OLDNEW
« blimp/engine/testing/Dockerfile ('K') | « blimp/engine/testing/Dockerfile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698