Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization - deterministic deployments #131

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions stack/cloud_function_ais_analysis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""cloud function to find slick culprits from AIS tracks"""

import time

import database
import git
import pulumi
Expand Down Expand Up @@ -58,7 +56,7 @@
# source code. ("main.py" and "requirements.txt".)
source_archive_object = storage.BucketObject(
construct_name("source-cf-ais"),
name=f"handler.py-{time.time():f}",
name="handler.py",
bucket=bucket.name,
source=archive,
)
Expand Down
4 changes: 1 addition & 3 deletions stack/cloud_function_historical_run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""cloud function to select appropriate scenes (over water and IW) from SNS notification"""

import time

import cloud_function_scene_relevancy
import cloud_run_orchestrator
import database
Expand Down Expand Up @@ -37,7 +35,7 @@
# source code. ("main.py" and "requirements.txt".)
source_archive_object = storage.BucketObject(
construct_name("source-cf-historical-run"),
name=f"handler.py-{time.time():f}",
name="handler.py",
bucket=cloud_function_scene_relevancy.bucket.name,
source=archive,
)
Expand Down
4 changes: 1 addition & 3 deletions stack/cloud_function_scene_relevancy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""cloud function to select appropriate scenes (over water and IW) from SNS notification"""

import time

import cloud_run_orchestrator
import database
import pulumi
Expand Down Expand Up @@ -60,7 +58,7 @@
# source code. ("main.py" and "requirements.txt".)
source_archive_object = storage.BucketObject(
construct_name("source-cf-sr"),
name=f"handler.py-{time.time():f}",
name="handler.py",
bucket=bucket.name,
source=archive,
)
Expand Down
20 changes: 16 additions & 4 deletions stack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ def create_zip(
:param compression: The compression type to use for the zip file (default is ZIP_DEFLATED)
"""
if not zip_filepath:
_, zip_filepath = mkstemp(
suffix=".zip",
)
_, zip_filepath = mkstemp(suffix=".zip")
else:
zip_filepath = os.path.abspath(zip_filepath)

Expand All @@ -142,7 +140,21 @@ def create_zip(
):
# Store the file relative to the directory specified
archive_name = os.path.relpath(full_path, dir_to_zip)
zipf.write(full_path, archive_name)

# Create ZipInfo object to set the date_time manually
zinfo = zipfile.ZipInfo.from_file(full_path, archive_name)
# Set date_time to January 1, 1980
zinfo.date_time = (1980, 1, 1, 0, 0, 0)

# Write file data to zip in chunks to be memory efficient
with open(full_path, "rb") as f:
with zipf.open(zinfo, "w") as zf:
while True:
chunk = f.read(1024 * 1024) # Read 1MB at a time
if not chunk:
break
zf.write(chunk)

return zip_filepath


Expand Down
Loading