serverless-plugin-simulate icon indicating copy to clipboard operation
serverless-plugin-simulate copied to clipboard

simulate plugin and docker in docker

Open nathHy opened this issue 6 years ago • 1 comments

This is a Bug Report/Feature Proposal

Description

I'm attempting to dockerise this plugin within a dev environment to simulate firing up lamdba containers. To do this I'm mounting the docker.sock into the container along with the docker binary. This works great and is fine however there is a problem with mounting the lambdas source code into the spawned container.

The spawned container has a volume with -v ${taskdir}:/var/task (lib/invoke/run.js) mounted into it. The taskdir variable comes all the way from the serverless.config.servicePath definition in config.js

The issue comes that this servicePath is wherever the serverless command is run from within the container. EG I copy all my source into /app within the container. This means the volume becomes /app:/var/task

However due to using the hosts docker socket these mount points are actually from the hosts point of view. EG /app outside the container on the host. This causes the lambda to fail as it cannot find the handler since nothing is mounted there, (my source might be in ~/dev/functions for instance which is volumed into the simulate containers /app)

Proposed fix

Allow the user to overwrite the taskDir that gets mounted into the lambda containers via some config.

Currently to fix the issue I've hacked a environment variable into lib/invoke/local.js that overrides the taskDir property but am not 100% sure that is the best implementation.

Any help would be appreciated

nathHy avatar May 07 '18 23:05 nathHy

Turns out this isn't entirely needed. It could be useful for someone else however.

I solved it by running a proper DIND container. This meant the lambdas volume itself was inside the container and therefore didn't get confused about host mounts or internal container mounts

nathHy avatar May 09 '18 04:05 nathHy