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

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: Lint clean up. 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
« blimp/engine/Dockerfile ('K') | « blimp/engine/testing/Dockerfile ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, relpath):
Wez 2016/07/16 00:26:36 Here & below, Python Style Guide is to use unix_ha
Jess 2016/07/16 01:10:32 Updated the variable names you mentioned.
19 """Read the manifest and return the list of dependencies. 19 """Read the manifest and return the list of dependencies.
20 :raises IOError: if the manifest could not be read. 20 :raises IOError: if the manifest could not be read.
21 """ 21 """
22 deps = [] 22 deps = []
23 with open(manifest) as f: 23 with open(manifest) as f:
24 for line in f.readlines(): 24 for line in f.readlines():
25 # Strip comments. 25 # Strip comments.
26 dep = line.partition('#')[0].strip() 26 dep = line.partition('#')[0].strip()
27 # Ignore empty strings. 27 # Ignore empty strings.
28 if dep: 28 if dep:
29 if relpath != '':
30 dep = os.path.normpath(os.path.join(relpath, dep))
29 deps.append(dep) 31 deps.append(dep)
30 return deps 32 return deps
31 33
32 def main(): 34 def main():
33 parser = argparse.ArgumentParser(description=__doc__) 35 parser = argparse.ArgumentParser(description=__doc__)
34 parser.add_argument('--build-dir', 36 parser.add_argument('--build-dir',
35 help=('build output directory (e.g. out/Debug)'), 37 help=('build output directory (e.g. out/Debug)'),
36 required=True, 38 required=True,
37 metavar='DIR') 39 metavar='DIR')
38 parser.add_argument('--filelist', 40 parser.add_argument('--filelist',
39 help=('optional space separated list of files (e.g. ' 41 help=('optional space separated list of files (e.g. '
40 'Dockerfile and startup script) to add to the ' 42 'Dockerfile and startup script) to add to the '
41 'bundle'), 43 'bundle'),
42 required=False, 44 required=False,
43 metavar='FILE', 45 metavar='FILE',
44 nargs='*') 46 nargs='*')
45 parser.add_argument('--manifest', 47 parser.add_argument('--manifest',
46 help=('file listing the set of files to include in ' 48 help=('file listing the set of files to include in '
47 'the bundle'), 49 'the bundle'),
48 required=True) 50 required=True)
49 parser.add_argument('--output', 51 parser.add_argument('--output',
50 help=('name and path of bundle to create'), 52 help=('name and path of bundle to create'),
51 required=True, 53 required=True,
52 metavar='FILE') 54 metavar='FILE')
55 parser.add_argument('--root-dir',
56 help=('optional docker rootdir to use to reference '
57 'dependencies; defaults to build-dir'),
58 required=False,
59 metavar='DIR')
53 args = parser.parse_args() 60 args = parser.parse_args()
54 61
55 deps = ReadDependencies(args.manifest) 62 deppath = args.build_dir
63 if args.root_dir:
64 deppath = args.root_dir
65 relpath = os.path.relpath(args.build_dir, deppath)
66
67 deps = ReadDependencies(args.manifest, relpath)
56 68
57 try: 69 try:
58 env = os.environ.copy() 70 env = os.environ.copy()
59 # Use fastest possible mode when gzipping. 71 # Use fastest possible mode when gzipping.
60 env["GZIP"] = "-1" 72 env["GZIP"] = "-1"
61 subprocess_args = [ 73 subprocess_args = [
62 "tar", 74 "tar",
63 "-zcf", args.output, 75 "-zcf", args.output,
64 # Ensure tarball content group permissions are appropriately set for 76 # Ensure tarball content group permissions are appropriately set for
65 # use as part of a "docker build". That is group readable with 77 # use as part of a "docker build". That is group readable with
66 # executable files also being group executable. 78 # executable files also being group executable.
67 "--mode=g+rX", 79 "--mode=g+rX",
68 "-C", args.build_dir] + deps 80 "-C", deppath] + deps
69 for f in args.filelist: 81 for f in args.filelist:
70 dirname, basename = os.path.split(f) 82 dirname, basename = os.path.split(f)
71 subprocess_args.extend(["-C", dirname, basename]) 83 subprocess_args.extend(["-C", dirname, basename])
72 subprocess.check_output( 84 subprocess.check_output(
73 subprocess_args, 85 subprocess_args,
74 # Redirect stderr to stdout, so that its output is captured. 86 # Redirect stderr to stdout, so that its output is captured.
75 stderr=subprocess.STDOUT, 87 stderr=subprocess.STDOUT,
76 env=env) 88 env=env)
77 except subprocess.CalledProcessError as e: 89 except subprocess.CalledProcessError as e:
78 print >> sys.stderr, "Failed to create tarball:" 90 print >> sys.stderr, "Failed to create tarball:"
79 print >> sys.stderr, e.output 91 print >> sys.stderr, e.output
80 sys.exit(1) 92 sys.exit(1)
81 93
82 if __name__ == "__main__": 94 if __name__ == "__main__":
83 main() 95 main()
OLDNEW
« blimp/engine/Dockerfile ('K') | « blimp/engine/testing/Dockerfile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698