-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: support dotnet lambda container builds #4665
Merged
Merged
Changes from 30 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
d93a5ba
allow use container for dotnet with write permission to source code d…
mrkdeng 31b7083
Merge branch 'develop' into develop
mrkdeng 986a804
fix typo
mrkdeng 654b0dc
Merge branch 'aws:develop' into develop
mrkdeng 59e5ff6
Merge branch 'aws:develop' into mount_with_write
mrkdeng c7c4149
major code changes to allow mount with write
mrkdeng 84c623b
remove dotnet env vars and add logic to make tmp dir on host
mrkdeng 3a48b99
integration tests
mrkdeng 871e9d2
consist help text and click confirm
mrkdeng 628da19
cleaner approach to make tmp dir on host, refactor regarding dev guide
mrkdeng 1c30b3f
update and add new unit tests
mrkdeng f7a013d
fix failed unit tests
mrkdeng ef34e17
Merge branch 'aws:develop' into develop
mrkdeng f03cd46
Merge branch 'develop' into mount_with_write
mrkdeng 89b2414
update test comments
mrkdeng 99d785e
update CONFIG and remove unnecessary Json dump
mrkdeng b9432ea
update integration tests
mrkdeng f3716f8
Merge branch 'develop' into mount_with_write
mrkdeng 05ba6cc
Merge branch 'mount_with_write' of https://github.com/mrkdeng/aws-sam…
mrkdeng 6819eed
Merge branch 'develop' into mount_with_write
mrkdeng ccde63c
pass ruff tests
mrkdeng 60ceabf
Merge branch 'develop' into mount_with_write
mrkdeng 888aadf
change mount with click to enum
mrkdeng db30045
add debug logging and remove unused exception
mrkdeng 461202d
update unit and integration tests
mrkdeng ca2e77b
update click
mrkdeng 6c7217e
add MountMode enum and set default to READ
mrkdeng 8a22584
add unit tests for prompting
mrkdeng 4196279
default mount_with to READ in all places
mrkdeng ccfb879
early exit
mrkdeng a2f15e6
better use of enum and constant, update unit tests
mrkdeng d00e842
Merge branch 'develop' into mount_with_write
mrkdeng 6a2afca
Merge branch 'mount_with_write' of https://github.com/mrkdeng/aws-sam…
mrkdeng 280b160
make tmp dir on sam build dir on host
mrkdeng 2ba803b
Merge branch 'develop' into mount_with_write
mndeveci 7f5d6a4
Merge branch 'develop' into mount_with_write
mndeveci bc63a8a
Merge branch 'develop' into mount_with_write
mndeveci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
""" | ||
Utilities for sam build command | ||
""" | ||
import pathlib | ||
from enum import Enum | ||
from typing import List | ||
|
||
import click | ||
|
||
from samcli.lib.build.workflow_config import CONFIG, get_workflow_config | ||
from samcli.lib.providers.provider import ResourcesToBuildCollector | ||
|
||
|
||
class MountMode(Enum): | ||
""" | ||
Enums that represent mount mode used when build lambda functions/layers inside container | ||
""" | ||
|
||
READ = "READ" | ||
WRITE = "WRITE" | ||
|
||
@classmethod | ||
def values(cls) -> List[str]: | ||
""" | ||
A getter to retrieve the accepted value list for mount mode | ||
|
||
Returns: List[str] | ||
The accepted mount mode list | ||
""" | ||
return [e.value for e in cls] | ||
mrkdeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def prompt_user_to_enable_mount_with_write_if_needed( | ||
resources_to_build: ResourcesToBuildCollector, | ||
base_dir: str, | ||
) -> bool: | ||
""" | ||
First check if mounting with write permissions is needed for building inside container or not. If it is needed, then | ||
prompt user to choose if enables mounting with write permissions or not. | ||
|
||
Parameters | ||
---------- | ||
resources_to_build: | ||
Resource to build inside container | ||
|
||
base_dir : str | ||
Path to the base directory | ||
|
||
Returns | ||
------- | ||
bool | ||
True, if user enabled mounting with write permissions. | ||
""" | ||
|
||
for function in resources_to_build.functions: | ||
code_uri = function.codeuri | ||
if not code_uri: | ||
continue | ||
runtime = function.runtime | ||
code_dir = str(pathlib.Path(base_dir, code_uri).resolve()) | ||
# get specified_workflow if metadata exists | ||
metadata = function.metadata | ||
specified_workflow = metadata.get("BuildMethod", None) if metadata else None | ||
config = get_workflow_config(runtime, code_dir, base_dir, specified_workflow) | ||
# at least one function needs mount with write, return with prompting | ||
if not config.must_mount_with_write_in_container: | ||
continue | ||
return prompt(config, code_dir) | ||
|
||
for layer in resources_to_build.layers: | ||
code_uri = layer.codeuri | ||
if not code_uri: | ||
continue | ||
code_dir = str(pathlib.Path(base_dir, code_uri).resolve()) | ||
specified_workflow = layer.build_method | ||
config = get_workflow_config(None, code_dir, base_dir, specified_workflow) | ||
# at least one layer needs mount with write, return with prompting | ||
if not config.must_mount_with_write_in_container: | ||
continue | ||
return prompt(config, code_dir) | ||
|
||
return False | ||
|
||
|
||
def prompt(config: CONFIG, source_dir: str) -> bool: | ||
""" | ||
Prompt user to choose if enables mounting with write permissions or not when building lambda functions/layers | ||
|
||
Parameters | ||
---------- | ||
config: namedtuple(Capability) | ||
Config specifying the particular build workflow | ||
|
||
source_dir : str | ||
Path to the function source code | ||
|
||
Returns | ||
------- | ||
bool | ||
True, if user enabled mounting with write permissions. | ||
""" | ||
if click.confirm( | ||
f"\nBuilding functions with {config.language} inside containers needs " | ||
f"mounting with write permissions to the source code directory {source_dir}. " | ||
f"Some files in this directory may be changed or added by the build process. " | ||
f"Pass `--mount-with WRITE` to `sam build` CLI to avoid this confirmation. " | ||
f"\nWould you like to enable mounting with write permissions? " | ||
): | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click.Choice takes [str] only. Workaround: Convert str to enum in BuildContext.init()
aws-sam-cli/samcli/commands/build/build_context.py
Line 178 in 280b160