From 292f0eef8f86ce9bda51d47a3b20d45a86d8aca6 Mon Sep 17 00:00:00 2001 From: Marcin Bilkowski Date: Fri, 30 Nov 2018 14:12:55 +0100 Subject: [PATCH 1/3] Adds a flag 'skip_package_lock_generation' to control if FTL should generate package-lock file at the beginning of the run. Skiping this can improve build speed but can cause older version of depe ndencies to be used. --- ftl/BUILD | 1 + ftl/common/args.py | 6 ++++++ ftl/node/builder.py | 3 +++ ftl/node/layer_builder.py | 12 ++++++++---- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ftl/BUILD b/ftl/BUILD index 9696a9cce..cbc422175 100644 --- a/ftl/BUILD +++ b/ftl/BUILD @@ -68,6 +68,7 @@ py_test( srcs = ["common/util_test.py"], deps = [ ":ftl_lib", + "@mock", ], ) diff --git a/ftl/common/args.py b/ftl/common/args.py index f127127c6..ce350e070 100644 --- a/ftl/common/args.py +++ b/ftl/common/args.py @@ -98,6 +98,12 @@ def base_parser(): default=True, action='store_true', help='Upload to cache during build (default).') + parser.add_argument( + '--skip_package_lock_generation', + dest='skip_package_lock_gen', + default=False, + action='store_true', + help='Do not create package lock file before checking cache.') parser.add_argument( '--output-path', dest='output_path', diff --git a/ftl/node/builder.py b/ftl/node/builder.py index 91ec86c34..bda4c3809 100644 --- a/ftl/node/builder.py +++ b/ftl/node/builder.py @@ -34,6 +34,8 @@ def __init__(self, ctx, args): self._should_use_yarn = self._should_use_yarn(self._ctx) def _gen_package_lock_if_required(self, ctx): + if self._args.skip_package_lock_gen: + return if not ftl_util.has_pkg_descriptor(self._descriptor_files, self._ctx): return @@ -76,6 +78,7 @@ def Build(self): directory=self._args.directory, destination_path=self._args.destination_path, should_use_yarn=self._should_use_yarn, + reuse_cache_key=self._args.skip_package_lock_gen, cache_key_version=self._args.cache_key_version, cache=self._cache) layer_builder.BuildLayer() diff --git a/ftl/node/layer_builder.py b/ftl/node/layer_builder.py index 2ba51b259..7e623ebb7 100644 --- a/ftl/node/layer_builder.py +++ b/ftl/node/layer_builder.py @@ -32,6 +32,7 @@ def __init__(self, directory=None, destination_path=constants.DEFAULT_DESTINATION_PATH, should_use_yarn=None, + reuse_cache_key=False, cache_key_version=None, cache=None): super(LayerBuilder, self).__init__() @@ -41,14 +42,17 @@ def __init__(self, self._directory = directory self._destination_path = destination_path self._should_use_yarn = should_use_yarn + self._reuse_cache_key = reuse_cache_key self._cache_key_version = cache_key_version self._cache = cache + self._cache_key = None def GetCacheKeyRaw(self): - all_descriptor_contents = ftl_util.all_descriptor_contents( - self._descriptor_files, self._ctx) - cache_key = '%s %s' % (all_descriptor_contents, self._destination_path) - return "%s %s" % (cache_key, self._cache_key_version) + if not self._cache_key or not self._reuse_cache_key: + all_descriptor_contents = ftl_util.all_descriptor_contents( + self._descriptor_files, self._ctx) + self._cache_key = '%s %s' % (all_descriptor_contents, self._destination_path) + return "%s %s" % (self._cache_key, self._cache_key_version) def BuildLayer(self): """Override.""" From cf0a61075169d5463c304f1a0a56e5ccb9d15d7d Mon Sep 17 00:00:00 2001 From: Marcin Bilkowski Date: Tue, 4 Dec 2018 17:07:00 +0100 Subject: [PATCH 2/3] Fixes problem with line length. --- ftl/node/layer_builder.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ftl/node/layer_builder.py b/ftl/node/layer_builder.py index 7e623ebb7..f510569ce 100644 --- a/ftl/node/layer_builder.py +++ b/ftl/node/layer_builder.py @@ -51,7 +51,8 @@ def GetCacheKeyRaw(self): if not self._cache_key or not self._reuse_cache_key: all_descriptor_contents = ftl_util.all_descriptor_contents( self._descriptor_files, self._ctx) - self._cache_key = '%s %s' % (all_descriptor_contents, self._destination_path) + self._cache_key = '%s %s' % (all_descriptor_contents, + self._destination_path) return "%s %s" % (self._cache_key, self._cache_key_version) def BuildLayer(self): From 4db60db156558c6ba4bfa79e56e7cdc57c5f2250 Mon Sep 17 00:00:00 2001 From: Marcin Bilkowski Date: Wed, 12 Dec 2018 16:02:41 +0100 Subject: [PATCH 3/3] Updates skip_package_lock_generation flag description. --- ftl/common/args.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftl/common/args.py b/ftl/common/args.py index ce350e070..3c7f21cba 100644 --- a/ftl/common/args.py +++ b/ftl/common/args.py @@ -103,7 +103,7 @@ def base_parser(): dest='skip_package_lock_gen', default=False, action='store_true', - help='Do not create package lock file before checking cache.') + help='Do not create package lock file before using cache.') parser.add_argument( '--output-path', dest='output_path',