Bug: sam build problem in Rancher Desktop
Description:
I am trying to build an AWS python lambda function in a container for debugging. When executing sam build --use-container an error is generated because dependencies are not build. This is because it says it cannot find the requirements.txt file. The requirements.txt file is present. The complete setup worked without any change under Docker Desktop, so it looks like it is Rancher related.
Steps to reproduce:
Install rancher desktop. Container runtime is set to dockerd (moby) Exposed Rancher Desktop Kubernetes configuration an docker socket to WSL is set to Ubuntu-20.04 Kubernetes version is set to 1.24.3
Observed result:
PS C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app> sam build --use-container --debug 2022-08-18 14:43:37,696 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics 2022-08-18 14:43:37,696 | Using config file: samconfig.toml, config environment: default 2022-08-18 14:43:37,697 | Expand command line arguments to: 2022-08-18 14:43:37,697 | --template_file=C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\template.yaml --use_container --build_dir=.aws-sam\build --cache_dir=.aws-sam\cache 2022-08-18 14:43:38,716 | 'build' command is called 2022-08-18 14:43:38,716 | Starting Build inside a container 2022-08-18 14:43:38,719 | No Parameters detected in the template 2022-08-18 14:43:38,734 | There is no customer defined id or cdk path defined for resource ProcessMail2021, so we will use the resource logical id as the resource id 2022-08-18 14:43:38,734 | There is no customer defined id or cdk path defined for resource KadasterMetingParse2021, so we will use the resource logical id as the resource id 2022-08-18 14:43:38,735 | 0 stacks found in the template 2022-08-18 14:43:38,735 | No Parameters detected in the template 2022-08-18 14:43:38,743 | There is no customer defined id or cdk path defined for resource ProcessMail2021, so we will use the resource logical id as the resource id 2022-08-18 14:43:38,744 | There is no customer defined id or cdk path defined for resource KadasterMetingParse2021, so we will use the resource logical id as the resource id 2022-08-18 14:43:38,744 | 2 resources found in the stack 2022-08-18 14:43:38,744 | Found Serverless function with name='ProcessMail2021' and CodeUri='ProcessMail2021/' 2022-08-18 14:43:38,745 | --base-dir is not presented, adjusting uri ProcessMail2021/ relative to C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\template.yaml 2022-08-18 14:43:38,745 | Found Serverless function with name='KadasterMetingParse2021' and CodeUri='KadasterMetingParse2021/' 2022-08-18 14:43:38,745 | --base-dir is not presented, adjusting uri KadasterMetingParse2021/ relative to C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\template.yaml 2022-08-18 14:43:38,749 | Instantiating build definitions 2022-08-18 14:43:38,752 | Same function build definition found, adding function (Previous: BuildDefinition(python3.8, C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021, Zip, , 22fa8c0f-c842-4add-b22b-b61dd32be94c, {}, {}, x86_64, []), Current: BuildDefinition(python3.8, C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021, Zip, , 8cbbde39-4ccc-435d-894f-5f8b6b4f9c16, {}, {}, x86_64, []), Function: Function(function_id='ProcessMail2021', name='ProcessMail2021', functionname='ProcessMail2021', runtime='python3.8', memory=None, timeout=3, handler='ProcessMail.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021', environment=None, rolearn=None, layers=[], events=None, metadata={'SamResourceId': 'ProcessMail2021'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, stack_path='')) 2022-08-18 14:43:38,753 | Same function build definition found, adding function (Previous: BuildDefinition(python3.8, C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\KadasterMetingParse2021, Zip, , cf40a036-b307-460c-bc2d-55033f694430, {}, {}, x86_64, []), Current: BuildDefinition(python3.8, C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\KadasterMetingParse2021, Zip, , 289c9d91-2cfe-4189-a0ba-08a2ffc51318, {}, {}, x86_64, []), Function: Function(function_id='KadasterMetingParse2021', name='KadasterMetingParse2021', functionname='KadasterMetingParse2021', runtime='python3.8', memory=None, timeout=3, handler='Kadaster_MetingParse.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\KadasterMetingParse2021', environment=None, rolearn=None, layers=[], events=None, metadata={'SamResourceId': 'KadasterMetingParse2021'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, stack_path='')) 2022-08-18 14:43:38,754 | Building codeuri: C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021 runtime: python3.8 metadata: {} architecture: x86_64 functions: ProcessMail2021 2022-08-18 14:43:38,756 | Building to following folder C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app.aws-sam\build\ProcessMail2021
Fetching public.ecr.aws/sam/build-python3.8:latest-x86_64 Docker container image......
2022-08-18 14:43:40,230 | Mounting C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021 as /tmp/samcli/source:ro,delegated inside runtime container
Using the request object from command line argument
Loading workflow module 'aws_lambda_builders.workflows'
Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)'
Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)'
requirements.txt file not found. Continuing the build without dependencies.
Running workflow 'PythonPipBuilder'
Running PythonPipBuilder:CopySource
Creating target folders at /tmp/samcli/artifacts
Copying directory metadata from source (/tmp/samcli/source) to destination (/tmp/samcli/artifacts)
PythonPipBuilder:CopySource succeeded
2022-08-18 14:43:40,829 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '33afc1f0-1091-47c2-b3ce-971cc2d2d4b7', 'installationId': '73f2b68e-1de6-4d57-9b90-0cb69a0ecdf3', 'sessionId': 'c1e8073f-1048-48b1-a264-de2d2c24486c', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.55.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN'}, 'duration': 3131, 'exitReason': 'error', 'exitCode': 255}}]}
2022-08-18 14:43:41,460 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Traceback (most recent call last):
File "runpy.py", line 194, in _run_module_as_main
File "runpy.py", line 87, in run_code
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli_main.py", line 12, in
Expected result:
A build lambda ready for debugging
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Windows 10 Enterprise edition
sam --version: SAM CLI, version 1.55.0- AWS region: eu-central-1
Add --debug flag to command you are running
@EdeBont Maybe multiple things are happening here. I will start off by saying, I am not familiar with Rancher Desktop but will be speaking in Docker terms.
So if your function does have a requirements.txt file in it's CodeUri directory, then this could be a mounting issue of the CodeUri into the container. With Docker, I know there are setting to enable what directories can be mounted. Is there something similar with Rancher Desktop that might be failing? Docker hides this and basically acts as if the mount was successful, so not sure if Rancher does the same thing.
The stacktrace seems to suggest we can't read the file from the container. So before we get to that, I want to make sure things are getting into the container correctly.
@jfuss According to Rancher documentation mount settings are as following: "Q: Does file sharing work similarly to Docker Desktop? Do I have to do any additional configuration to mount volumes to VMs? A: Currently, the following directories are shared by default: /Users/$USER on macOS, /home/$USER on Linux, and /tmp/rancher-desktop on both. For Windows, all files are automatically shared via WSL2."
@EdeBont Does this only happen in Rancher? What about Docker?
@EdeBont Does this only happen in Rancher? What about Docker?
@jfuss As I mentioned in my initial post we had no problem when we using Docker Desktop. So at this moment this problem only exists when using Rancher Desktop.
@EdeBont Sorry I am been jumping between issues and was brought up to check from the team.
Does this happen all the time?
Can you provide an example project or tell me how your project is setup? Trying to see maybe if there are other issues going on that is just masked by the failure.
@EdeBont Sorry I am been jumping between issues and was brought up to check from the team.
Does this happen all the time?
Can you provide an example project or tell me how your project is setup? Trying to see maybe if there are other issues going on that is just masked by the failure.
Hi @jfuss , No need to apologize!!
Yes it happens all the time, also in other projects which used to work ok using Docker Desktop.
The project setup is simple: root (containing template.yaml) |project folder | init.py |_____ process.py |_____ requirements.txt (containing ptvsd, requests, psycopg2-binary, boto3)
As mentioned this setup works without any problem when using Docker Desktop. As soon as I switch to Rancher Desktop there is a problem.
And it looks like I am not the only one running into this problem: https://github.com/aws/aws-sam-cli/issues/3595#issuecomment-1217674852
@EdeBont Sorry I am been jumping between issues and was brought up to check from the team.
Does this happen all the time?
Can you provide an example project or tell me how your project is setup? Trying to see maybe if there are other issues going on that is just masked by the failure.
same with me.
Running PythonPipBuilder:ResolveDependencies
Running PythonPipBuilder:CopySource
Traceback (most recent call last):
File "runpy.py", line 194, in _run_module_as_main
File "runpy.py", line 87, in run_code
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli_main.py", line 12, in
Environment details
Docker version 20.10.17, build 100c701 SAM CLI, version 1.57.0 OS: Windows 11
I got it working again using the nightly build of SAM:
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-windows.html#serverless-sam-cli-install-windows-nightly-build
I got it working again using the nightly build of SAM:
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-windows.html#serverless-sam-cli-install-windows-nightly-build
That actually solved my problem to at first glance, at second not!! Though it still says "requirements.txt file not found"
PS C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app> sam-nightly build --use-container
Starting Build inside a container
Building codeuri: C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021 runtime: python3.8 metadata: {} architecture: x86_64 functions: ProcessMail2021
Fetching public.ecr.aws/sam/build-python3.8:latest-x86_64 Docker container image......
Mounting C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021 as /tmp/samcli/source:ro,delegated inside runtime container
requirements.txt file not found. Continuing the build without dependencies.
Running PythonPipBuilder:CopySource
Building codeuri: C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\KadasterMetingParse2021 runtime: python3.8 metadata: {} architecture: x86_64 functions: KadasterMetingParse2021
Fetching public.ecr.aws/sam/build-python3.8:latest-x86_64 Docker container image......
Mounting C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\KadasterMetingParse2021 as /tmp/samcli/source:ro,delegated inside runtime container
Build Succeeded
Built Artifacts : .aws-sam\build
Built Template : .aws-sam\build\template.yaml
Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {stack-name} --watch
[*] Deploy: sam deploy --guided
SAM CLI update available (1.57.0); (1.57.0.dev202209200902 installed)
To download: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
requirements.txt file not found. Continuing the build without dependencies.
Running PythonPipBuilder:CopySource
Almost but no sigar. After some more testing it is still not working, not able to debug anything.
getting the same issue with the hello world app. requirements.txt is not found. I'm on Windows 11, using Rancher Desktop 1.62 and sam cli 1.66.0. if you need additional logs/details to troubleshoot, I'm happy to provide
Hi folks, sorry I just saw this. I tried with a sam init template for python on MacOS and it didn't have any issues. It seems this might be a problem on Rancher Desktop's side, specifically on Windows. I found this issue on Rancher's github which might be the problem: https://github.com/rancher-sandbox/rancher-desktop/issues/3014
SAM CLI does mount a temporary directory onto the container, so that we can perform the building in there. It seems like Rancher Desktop on Windows is potentially not creating this directory or not mounting it properly.
Docker Desktop does automatically create these directories: https://docs.docker.com/engine/reference/commandline/run/#mount-volume--v---read-only
When the host directory of a bind-mounted volume doesn’t exist, Docker will automatically create this directory on the host for you.
Thanks for investigating. Is there a way for sam to create the folder before starting the container? wondering if that would solve the problem
I am not sure if creating this folder by SAM CLI is a good solution or not, as the problem is related to Rancher and not SAM CLI. I will share this issue with the team and discuss this as a feature request.
Same issue :(