dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.19k stars 795 forks source link

serverless offline --useDocker fails to mount volume on a osx #1041

Closed softprops closed 4 months ago

softprops commented 4 years ago

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

service: my-service

plugins:
  - serverless-offline

provider:
  runtime: nodejs12.x
  stage: dev

functions:
  hello:
    events:
      - http:
          method: get
          path: hello
    handler: handler.hello
'use strict'

const { stringify } = JSON

exports.hello = async function hello() {
  return {
    body: stringify({ foo: 'bar' }),
    statusCode: 200,
  }
}

Expected behavior/code

Environment

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

softprops commented 4 years ago

I traced this all the way back to this line https://github.com/dherault/serverless-offline/blob/7485bf303ff55d2ac2a4433504c87edcf8a4783b/src/lambda/LambdaFunction.js#L93

softprops commented 4 years ago

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

softprops commented 4 years ago

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

JimLynchCodes commented 2 years ago

Looks like something for offline support was merged! 🎉

Should this be working now? @softprops @ozbe