cdk synth: spawnSync docker ENOENT because cdk is not looking at the right directory
damshenas opened this issue · comments
Describe the bug
When using cdk synth
to bundle my lambda code (in python) CDK throws spawnSync docker ENOENT
Expected Behavior
cdk to look in the right location /Applications/Docker.app/Contents/Resources/bin/docker
or look into possible locations.
Current Behavior
Currently cdk is looking at the wrong directory which caused the confusing error of spawnSync docker ENOENT
Reproduction Steps
OS: Macos 13.6.7 (22G720)
Docker: Docker Desktop 4.31.0 (153195)
CDK: 2.146.0 (b368c78)
new lambda.Function(this, 'myFn', {
runtime: lambda.Runtime.PYTHON_3_12,
handler: 'main.handler',
code: lambda.Code.fromAsset(path.join(__dirname, './src'), {
bundling: {
image: lambda.Runtime.PYTHON_3_12.bundlingImage,
command: [
'bash', '-c',
'pip install -r requirements.txt -t /asset-output && cp -au . /asset-output'
],
},
}),
});
Possible Solution
ln -s '/Applications/Docker.app/Contents/Resources/bin/docker' '/usr/local/bin/docker'
This will solve the issue.
Additional Information/Context
No response
CDK CLI Version
2.146.0
Framework Version
No response
Node.js Version
v22.1.0
OS
Macos 13.6.7 (22G720)
Language
TypeScript
Language Version
No response
Other information
Searching for this message can be misleading as 99% of people suggesting installing esbuild and things related to that. But the point is this spawnSync xyz ENOENT
just means the xyz is missing. I hope this will save some people some time. And the issue is fixed in future.
Hi @damshenas , thanks for reaching out. I found previously filed similar issue-
Issue - #22997
Suggested solution - #22997 (comment)
Could you please check if this is the exact condition you are running into and the solution might help ??
Hi @khushail, thanks for the follow up. Short answer is no, it does not help. Long answer is that, unfortunately the solution in the other issue does not fix my problem. In my case, there is nothing needed to be installed. Docker is already there but cdk can not find it. I also posted the solution that worked for me, but I think CDK can do better.
Thanks @damshenas for the confirmation.
I guess this is how CDK finds the docker
CLI
aws-cdk/packages/cdk-assets/lib/private/docker.ts
Lines 273 to 275 in b196b13
Looks like it won't search /Applications/Docker.app/Contents/Resources/bin/docker
Can you try which docker
and see if it returns /Applications/Docker.app/Contents/Resources/bin/docker
?
And, is /Applications/Docker.app/Contents/Resources/bin
in your $PATH?
@pahud indeed that path is what which docker
returns. It is not in the $PATH. I checked with another laptop (arm) and it also did not have it in the $PATH (but cdk worked fine there). Seems adding those directories to $PATH is not common in Mac.
Logically, adding the path to $PATH should also fix the issue. But ideally CDK should be able to work out of the box on all Macs.