Skip to content

Conversation

@Macok
Copy link

@Macok Macok commented Aug 4, 2021

Which issue(s) does this change fix?

#3133

Why is this change necessary?

During the build, additional env variable LAMBDA_BUILDERS_LOG_LEVEL is added to the dict.
This additional variable ends up being persisted in build.toml, making cache always invalid.
This was already addressed here #2943 for Lambda Functions, but similar problems affects Lambda Layers.

How does it address the issue?

A copy of the dictionary is made, so the original dictionary stays unchanged.

What side effects does this change have?

None.

Checklist

  • Add input/output type hints to new functions/methods
  • Write design document (Do I need to write a design document?)
  • Write unit tests
  • Write/update functional tests
  • Write/update integration tests
  • 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.

Comment on lines 1349 to 1381
@skipIf(SKIP_DOCKER_TESTS, SKIP_DOCKER_MESSAGE)
def test_cached_build_with_env_vars(self):
"""
Build 2 times to verify that second time hits the cached build
"""
overrides = {
"FunctionCodeUri": "Python",
"Function1Handler": "main.first_function_handler",
"Function2Handler": "main.second_function_handler",
"FunctionRuntime": "python3.8",
}
cmdlist = self.get_command_list(
use_container=True, parameter_overrides=overrides, cached=True, container_env_var="FOO=BAR"
)

LOG.info("Running Command (cache should be invalid): %s", cmdlist)
command_result = run_command(cmdlist, cwd=self.working_dir)
self.assertTrue(
"Cache is invalid, running build and copying resources to function build definition"
in command_result.stderr.decode("utf-8")
)

LOG.info("Re-Running Command (valid cache should exist): %s", cmdlist)
command_result_with_cache = run_command(cmdlist, cwd=self.working_dir)

self.assertTrue(
"Valid cache found, copying previously built resources from function build definition"
in command_result_with_cache.stderr.decode("utf-8")
)

Copy link
Author

Choose a reason for hiding this comment

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

I removed this test because TestRepeatedBuildHitsCache covers all this.

@Macok Macok marked this pull request as draft August 4, 2021 08:19
@Macok Macok marked this pull request as ready for review August 4, 2021 08:35
@jfuss jfuss added area/build sam build command pr/external labels Aug 4, 2021
template = "layers-functions-template.yaml"

@parameterized.expand([(True,), (False,)])
@skipIf(SKIP_DOCKER_TESTS, SKIP_DOCKER_MESSAGE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just move this test under the "cache builds" class we already have?

Copy link
Author

@Macok Macok Aug 4, 2021

Choose a reason for hiding this comment

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

@jfuss You mean to move this test inside the TestBuildWithCacheBuilds class?
The problem is that TestBuildWithCacheBuilds uses dedup-functions-template.yaml, which doesn't have any Layers. So it won't test what we want.

Maybe a solution would be to refactor TestBuildWithCacheBuilds to use layers-functions-template.yaml, but I think dedup-functions-template.yaml fits better there. layers-functions-template.yaml has a lot of layers inside, so the test would get much slower without improving the coverage.

@jfuss jfuss added the stage/pr Has a PR ready for review label Aug 4, 2021
@mndeveci mndeveci self-requested a review August 4, 2021 18:39
@Macok Macok force-pushed the copy_env_dict_before_passing branch from a84f5ee to 723e4fd Compare August 4, 2021 19:24
@Macok Macok requested a review from jfuss August 4, 2021 19:27
@Macok Macok force-pushed the copy_env_dict_before_passing branch 3 times, most recently from 684a603 to 6ba0b68 Compare August 4, 2021 19:41
Copy link
Contributor

@mndeveci mndeveci left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @Macok!

I verified your changes on my local machine and I can confirm that these changes are working as expected.

One thing though, when I tried to run integration test pytest tests/integration/buildcmd/test_build_cmd.py -k TestRepeatedBuildHitsCache it fails. Can you check what is the issue there?

@Macok
Copy link
Author

Macok commented Aug 7, 2021

Thanks for the changes @Macok!

I verified your changes on my local machine and I can confirm that these changes are working as expected.

One thing though, when I tried to run integration test pytest tests/integration/buildcmd/test_build_cmd.py -k TestRepeatedBuildHitsCache it fails. Can you check what is the issue there?

@mndeveci
Aren't you simply forgetting about SAM_CLI_DEV flag?
For me, SAM_CLI_DEV=1 pytest tests/integration/buildcmd/test_build_cmd.py -k TestRepeatedBuildHitsCache runs fine on 2 different machines; make pr passes as well.

If that's not it, could you post the logs?

@Macok Macok requested a review from mndeveci August 7, 2021 07:22
@Macok Macok force-pushed the copy_env_dict_before_passing branch from 6ba0b68 to 66a392b Compare August 7, 2021 08:29
@Macok
Copy link
Author

Macok commented Aug 19, 2021

@mndeveci , @jfuss would you take a look again?

@mndeveci
Copy link
Contributor

Thanks for the changes @Macok!
I verified your changes on my local machine and I can confirm that these changes are working as expected.
One thing though, when I tried to run integration test pytest tests/integration/buildcmd/test_build_cmd.py -k TestRepeatedBuildHitsCache it fails. Can you check what is the issue there?

@mndeveci
Aren't you simply forgetting about SAM_CLI_DEV flag?
For me, SAM_CLI_DEV=1 pytest tests/integration/buildcmd/test_build_cmd.py -k TestRepeatedBuildHitsCache runs fine on 2 different machines; make pr passes as well.

If that's not it, could you post the logs?

Thanks @Macok, I guess that was my bad at that time, when I run this I was able to verify that tests are working fine.

@Macok
Copy link
Author

Macok commented Aug 31, 2021

@jfuss Only your approval missing.

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.

@Macok Thanks for the contribution and going back to refactor.

@jfuss jfuss added stage/accepted Accepted and will be fixed stage/pr-approved PR is approved but shouldn't be merged for now labels Aug 31, 2021
@jfuss jfuss merged commit 84a085a into aws:develop Sep 3, 2021
jonife pushed a commit to jonife/aws-sam-cli that referenced this pull request Sep 3, 2021
) (aws#3139)

Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
Co-authored-by: Sriram Madapusi Vasudevan <3770774+sriram-mv@users.noreply.github.com>
Co-authored-by: Jacob Fuss <32497805+jfuss@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build sam build command pr/external stage/accepted Accepted and will be fixed stage/pr Has a PR ready for review stage/pr-approved PR is approved but shouldn't be merged for now

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants