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

fix: handle special cases for layer sync #4651

Merged
merged 8 commits into from
Feb 4, 2023
Merged

Conversation

mndeveci
Copy link
Contributor

@mndeveci mndeveci commented Feb 1, 2023

Which issue(s) does this change fix?

#4304

Why is this change necessary?

If a layer resource doesn't have BuildMethod or marked with SkipBuild: True, SAM CLI should skip build step and directly zip contents of the target folder.

How does it address the issue?

By checking layer details and assigning different sync flows depending on the layer details.

What side effects does this change have?

N/A

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mndeveci mndeveci requested a review from a team as a code owner February 1, 2023 22:07
"""

def gather_resources(self) -> None:
zip_file_path = os.path.join(tempfile.gettempdir(), f"data-{uuid.uuid4().hex}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should we try use Pathlib where we can instead of os.path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but I just wanted to follow what we already have in this file. We could do it in another PR for refactoring purposes.

samcli/lib/sync/sync_flow_factory.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jfuss jfuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No integration tests?

@@ -591,7 +591,7 @@ def _collect_single_function_and_dependent_layers(
return

resource_collector.add_function(function)
resource_collector.add_layers([l for l in function.layers if l.build_method is not None and not l.skip_build])
resource_collector.add_layers([l for l in function.layers if BuildContext.is_layer_buildable(l)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I wonder if there was a specific reason for this. Also looks like the function part doesn't filter. I assume that is likely a bug? If so, just want to note it for us to fix later (outside this pr).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure. Existing logic was pretty same with is_layer_buildable. Only difference is, is_layer_buildable additionally checks if codeuri of the layer points to a ZIP file or not.

For function collection part, even if function is set SkipBuild: True, then running sam build {logical-id} will build the function. But if you run sam build to build entire stack, it will skip that function to build. So it feels like this is not the expected behavior.

"""

def gather_resources(self) -> None:
self._zip_file = os.path.join(tempfile.gettempdir(), f"data-{uuid.uuid4().hex}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we cleaning up these temp dirs for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if is_zip_file(layer.codeuri):
LOG.debug("Creating LayerSyncFlowSkipBuildZipFile for '%s' resource", resource_identifier)
return LayerSyncFlowSkipBuildZipFile(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This is how I read the name, which led to some confusion on my end. LayerSyncFlow + SkipBuild + Zip + File. Reading it this way, made me think we were zipping the file/folder but doesn't seem like that is the ended thing. Maybe we should rename or add in some "_" to signal to the reader the right thing from the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is hard and I am also not very happy with these names, open for any suggestion.

@mndeveci mndeveci enabled auto-merge (squash) February 3, 2023 23:51
@mndeveci mndeveci merged commit 37eff86 into aws:develop Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants