-
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
Bug: sam fails to build subdirectory based Dockerfile images on Windows #5345
Comments
Hi, thanks for reporting this issue! I can reproduce this problem where this sample project is able to be built on Linux, but not on WIndows. Looks like it is able to find the Docker file if it is in the same folder as the As a temporary workaround, would it be possible to move the |
thanks for reviewing this. I confirm that moving the Dockerfile into the parent folder is a workaround. I have tried to track this in the source code, but could not not identify the area, as I am not familiar with the code. Any hint as to which part of the code is responsible for producing aws:asset:dockerfile-path in build.toml? I am happy to suggest a fix to this. I have not found a documentation of build.toml that could shine light on the meaning of the aws:asset:dockerfile-path element. |
Patch is released in v1.94.0. Closing |
Description:
sam build
fails to build images of which the Dockerfile is located in a sub-directory of the directory containing the assets, when using cdk on Windows andfromImageAsset
to construct a docker based lambda function.Such configuration is sometimes needed to share code between docker images. The image is built correctly when running
cdk deploy
, but not when I would like to build docker images usingsam build
for local testing withsam local invoke
.Here is an example:
The issue is likely related to Windows, as the docker images of the demo project are built correctly on Linux. A possible reason could be that aws:asset:dockerfile-path in build.toml contains an unix-style path:
However, using a windows-style path (myimage\\Dockerfile) as file parameter for
fromImageAsset
does not solve the problem.The issue is related but not identical to #4074, aws/aws-cdk#3342 and #4059.
Steps to reproduce:
Observed result:
2023-06-12 20:46:14,681 | Local image was not found.
2023-06-12 20:46:14,682 | Removing rapid images for repo testlambdafunctionc089708a
Building image......
2023-06-12 20:46:17,962 | Failed to build Docker Image
NoneType: None
2023-06-12 20:42:46,106 | Found Lambda function with name='TestLambdaFunctionC089708A' and Imageuri='testlambdafunctionc089708a'
2023-06-12 20:42:46,112 | Error occurred while trying to track an event: Event 'BuildFunctionRuntime' does not accept value 'None'.
2023-06-12 20:42:46,116 | Instantiating build definitions
2023-06-12 20:42:46,146 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(None, C:\Users\Timo\Documents\git\testcdk\cdk.out, Image, ,
eacc9958-29f8-4c8c-8ed2-9fb9e9aae05e, {'aws:cdk:path': 'TestcdkStack/TestLambdaFunction/Resource', 'aws:asset:path': 'asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123',
'aws:asset:dockerfile-path': 'myimage/Dockerfile', 'aws:asset:property': 'Code.ImageUri', 'Dockerfile': 'myimage\Dockerfile', 'DockerContext':
'C:\Users\Timo\Documents\git\testcdk\cdk.out\asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123', 'DockerBuildArgs': {}}, {}, x86_64, []), Function:
Function(function_id='TestLambdaFunction', name='TestLambdaFunctionC089708A', functionname='TestLambdaFunction', runtime=None, memory=None, timeout=None, handler=None, imageuri='testlambdafunctionc089708a',
packagetype='Image', imageconfig=None, codeuri='C:\Users\Timo\Documents\git\testcdk\cdk.out', environment=None,
rolearn='arn:aws:lambda:us-east-1:XXXX:function:TestLambdaFunctionServiceRole0C9E0634', layers=[], events=None, metadata={'aws:cdk:path': 'TestcdkStack/TestLambdaFunction/Resource', 'aws:asset:path':
'asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123', 'aws:asset:dockerfile-path': 'myimage/Dockerfile', 'aws:asset:property': 'Code.ImageUri', 'Dockerfile': 'myimage\Dockerfile',
'DockerContext': 'C:\Users\Timo\Documents\git\testcdk\cdk.out\asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123', 'DockerBuildArgs': {}, 'SamNormalized': True, 'SamResourceId':
'TestLambdaFunction'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, stack_path='', runtime_management_config=None))
2023-06-12 20:42:46,171 | Building codeuri: C:\Users\Timo\Documents\git\testcdk\cdk.out runtime: None metadata: {'aws:cdk:path': 'TestcdkStack/TestLambdaFunction/Resource', 'aws:asset:path':
'asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123', 'aws:asset:dockerfile-path': 'myimage/Dockerfile', 'aws:asset:property': 'Code.ImageUri', 'Dockerfile': 'myimage\Dockerfile',
'DockerContext': 'C:\Users\Timo\Documents\git\testcdk\cdk.out\asset.4721ec417018e85931d81e741803ba44e753dab698cfd355501d8be3c63e3123', 'DockerBuildArgs': {}} architecture: x86_64 functions:
TestLambdaFunction
2023-06-12 20:42:46,174 | Building to following folder C:\Users\Timo\Documents\git\testcdk.aws-sam\build\TestLambdaFunctionC089708A
2023-06-12 20:42:46,176 | Building image for TestLambdaFunctionC089708A function
2023-06-12 20:42:46,190 | Setting DockerBuildArgs: {} for TestLambdaFunctionC089708A function
2023-06-12 20:42:46,525 | CDK Path for resource TestLambdaFunctionServiceRole0C9E0634 is ['TestcdkStack', 'TestLambdaFunction', 'ServiceRole', 'Resource']
2023-06-12 20:42:46,531 | CDK Path for resource TestLambdaFunctionC089708A is ['TestcdkStack', 'TestLambdaFunction', 'Resource']
2023-06-12 20:42:46,534 | CDK Path for resource CDKMetadata is ['TestcdkStack', 'CDKMetadata', 'Default']
2023-06-12 20:42:46,538 | 3 resources found in the stack
2023-06-12 20:42:46,540 | Found Lambda function with name='TestLambdaFunctionC089708A' and Imageuri='testlambdafunctionc089708a'
Build Succeeded
The build does not fail, but no docker image is built, as can be verified by
docker images
.Expected result:
docker images
should show the docker image corresponding to the lambda functionsam local invoke TestLambdaFunction -t cdk.out\TestcdkStack.template.json
should not fail, but run the docker based lambda functionAdditional environment details (Ex: Windows, Mac, Amazon Linux etc)
The text was updated successfully, but these errors were encountered: