serverless-offline icon indicating copy to clipboard operation
serverless-offline copied to clipboard

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

Open softprops opened this issue 5 years ago • 4 comments

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

  • serverless version: v1.74.1
  • serverless-offline version: v6.4.0
  • node.js v14.2.0
  • OS: 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

softprops avatar Jul 04 '20 23:07 softprops

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

softprops avatar Jul 05 '20 02:07 softprops

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 avatar Jul 05 '20 11:07 softprops

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

softprops avatar Jul 05 '20 11:07 softprops

Looks like something for offline support was merged! 🎉

Should this be working now? @softprops @ozbe

JimLynchCodes avatar Feb 22 '22 15:02 JimLynchCodes