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..3c7f21cba 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 using 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..f510569ce 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,18 @@ 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."""