Skip to content

Commit

Permalink
feat: Added TF_RECREATE_MISSING_LAMBDA_PACKAGE env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ahlinc committed Jun 10, 2020
1 parent 68e4cc7 commit abf1e4b
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ def source_code_hash(bytes):
return b64encode(hashlib.sha256(bytes).digest()).decode()


def yesno_bool(val):
if val is None:
return
if isinstance(val, bool):
return val
if isinstance(val, int):
return bool(val)
if isinstance(val, str):
if val.isnumeric():
return bool(int(val))
val = val.lower()
if val in ('true', 'yes', 'y'):
return True
elif val in ('false', 'no', 'n'):
return False
else:
raise ValueError("Unsupported value: %s" % val)
return False


################################################################################
# Packaging functions

Expand Down Expand Up @@ -418,6 +438,7 @@ def update_hash(hash_obj, file_root, file_path):
hash_extra_paths = query.hash_extra_paths
source_path = query.source_path
hash_extra = query.hash_extra
recreate_missing_package = yesno_bool(args.recreate_missing_package)

# Compacting docker vars
docker = query.docker
Expand Down Expand Up @@ -446,12 +467,15 @@ def update_hash(hash_obj, file_root, file_path):
# Compute timestamp trigger
was_missing = False
filename_path = os.path.join(os.getcwd(), filename)
if os.path.exists(filename_path):
st = os.stat(filename_path)
timestamp = st.st_mtime_ns
if recreate_missing_package:
if os.path.exists(filename_path):
st = os.stat(filename_path)
timestamp = st.st_mtime_ns
else:
timestamp = timestamp_now_ns()
was_missing = True
else:
timestamp = timestamp_now_ns()
was_missing = True
timestamp = 0

# Replace variables in the build command with calculated values.
build_data = {
Expand Down Expand Up @@ -690,6 +714,8 @@ def args_parser():

def main():
ns = argparse.Namespace(
recreate_missing_package=os.environ.get(
'TF_RECREATE_MISSING_LAMBDA_PACKAGE'),
log_level=os.environ.get('TF_PACKAGE_LOG_LEVEL', 'INFO'),
dump_input=bool(os.environ.get('TF_DUMP_INPUT')),
dump_env=bool(os.environ.get('TF_DUMP_ENV')),
Expand Down

0 comments on commit abf1e4b

Please sign in to comment.