-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(build): use container directories in executable_search_paths when building in container #1030
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
Changes from all commits
d546702
4deea27
f846d56
fff8d06
32e8e01
5aa557c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,18 @@ def __init__(self, # pylint: disable=too-many-locals | |
|
|
||
| container_dirs = LambdaBuildContainer._get_container_dirs(source_dir, manifest_dir) | ||
|
|
||
| # `executable_search_paths` are provided as a list of paths on the host file system that needs to passed to | ||
| # the builder. But these paths don't exist within the container. We use the following method to convert the | ||
| # host paths to container paths. But if a host path is NOT mounted within the container, we will simply ignore | ||
| # it. In essence, only when the path is already in the mounted path, can the path resolver within the | ||
| # container even find the executable. | ||
| executable_search_paths = LambdaBuildContainer._convert_to_container_dirs( | ||
| host_paths_to_convert=executable_search_paths, | ||
| host_to_container_path_mapping={ | ||
| source_dir: container_dirs["source_dir"], | ||
| manifest_dir: container_dirs["manifest_dir"] | ||
| }) | ||
|
|
||
| request_json = self._make_request(protocol_version, | ||
| language, | ||
| dependency_manager, | ||
|
|
@@ -163,6 +175,54 @@ def _get_container_dirs(source_dir, manifest_dir): | |
|
|
||
| return result | ||
|
|
||
| @staticmethod | ||
| def _convert_to_container_dirs(host_paths_to_convert, host_to_container_path_mapping): | ||
| """ | ||
| Use this method to convert a list of host paths to a list of equivalent paths within the container | ||
| where the given host path is mounted. This is necessary when SAM CLI needs to pass path information to | ||
| the Lambda Builder running within the container. | ||
|
|
||
| If a host path is not mounted within the container, then this method simply passes the path to the result | ||
|
||
| without any changes. | ||
|
|
||
| Ex: | ||
| [ "/home/foo", "/home/bar", "/home/not/mounted"] => ["/tmp/source", "/tmp/manifest", "/home/not/mounted"] | ||
|
|
||
| Parameters | ||
| ---------- | ||
| host_paths_to_convert : list | ||
| List of paths in host that needs to be converted | ||
|
|
||
| host_to_container_path_mapping : dict | ||
| Mapping of paths in host to the equivalent paths within the container | ||
|
|
||
| Returns | ||
| ------- | ||
| list | ||
| Equivalent paths within the container | ||
| """ | ||
|
|
||
| if not host_paths_to_convert: | ||
| # Nothing to do | ||
| return host_paths_to_convert | ||
|
|
||
| # Make sure the key is absolute host path. Relative paths are tricky to work with because two different | ||
| # relative paths can point to the same directory ("../foo", "../../foo") | ||
| mapping = {str(pathlib.Path(p).resolve()): v for p, v in host_to_container_path_mapping.items()} | ||
|
|
||
| result = [] | ||
| for original_path in host_paths_to_convert: | ||
| abspath = str(pathlib.Path(original_path).resolve()) | ||
|
|
||
| if abspath in mapping: | ||
|
||
| result.append(mapping[abspath]) | ||
|
||
| else: | ||
| result.append(original_path) | ||
| LOG.debug("Cannot convert host path '%s' to its equivalent path within the container. " | ||
| "Host path is not mounted within the container", abspath) | ||
|
|
||
| return result | ||
|
|
||
| @staticmethod | ||
| def _get_image(runtime): | ||
| return "{}:build-{}".format(LambdaBuildContainer._IMAGE_REPO_NAME, runtime) | ||
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.
Perfect 🔥