serverless-offline
serverless-offline copied to clipboard
serverless offline --useDocker fails to mount volume on a osx
Bug Report
Current Behavior
serverless offline --useDocker seems to mount code from a directory that is not mountable on osx
Error response from daemon: Mounts denied:
The path /var/folders/s3/c9x3_fkd7cj3by3dp663fy0c0000gp/T/serverless-offline/services/aws-rust/hello/ckc866hnm00062anbfl530n0j/code
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.
Sample Code
your default example below should reproduce the issue though any http handler will do. This has less to do with a handler than it does volume mounting
- file: serverless.yml
service: my-service
plugins:
- serverless-offline
provider:
runtime: nodejs12.x
stage: dev
functions:
hello:
events:
- http:
method: get
path: hello
handler: handler.hello
- file: handler.js
'use strict'
const { stringify } = JSON
exports.hello = async function hello() {
return {
body: stringify({ foo: 'bar' }),
statusCode: 200,
}
}
Expected behavior/code
Environment
serverlessversion: v1.74.1serverless-offlineversion: v6.4.0node.jsv14.2.0OS: macOS 10.15.4
Possible Solution
volume mount the serverless directory within the repository or somewhere that's accessible for volume mounting on docker for mac
from the docs
By default, you can share files in /Users/, /Volumes/, /private/, and /tmp directly.
It would be nice if serverless offline --useDocker worked on a mac out of the box
Additional context/Screenshots
I traced this all the way back to this line https://github.com/dherault/serverless-offline/blob/7485bf303ff55d2ac2a4433504c87edcf8a4783b/src/lambda/LambdaFunction.js#L93
this might be related https://github.com/nodejs/node/issues/11422 docker for mac by default allows /tmp and /private paths I tried adding /var but still got a mount permissions error presumable related to this being a symlink path and not a real path
fs.realpathSync may be of use here this resolves the symlink to a real path which docker for mac may have a better time coping with
Looks like something for offline support was merged! 🎉
Should this be working now? @softprops @ozbe