Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Implementation for adding custom container support #1611

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jcampbell05
Copy link

@jcampbell05 jcampbell05 commented Nov 14, 2022

Description

This is an initial proof of concept of adding custom container support to Serverless Offline. This PR was opened so we can discuss the implementation to hopefully land on something that can be merged.

  • Serverless Offline will now build any images in the provider.ecr.images section.
  • Serverless Offline can now run functions with an image instead of a handler

The current implementation has a few limitations and drawbacks:

  • Doesn't support simple reference to container image, most of the code asumes you have configured it using the dict format.
  • No support for layers (It's not clear how we would add support or if we would need by first release of this feature)
  • The current implementation communicates with the default lambda runtime port of 8080 and the function is always reached at the "function" endpoint.
  • Always assumes the docker container is on the same host which may not be the case (i.e for dind)

These can be changed from the default settings which would break this code since there is no way at the moment to tell this code how the Dockerfile has been configured. However as a workaround the code in the container could just detect the SLS_OFFLNE environmental variable and configure itself in a manner that would work.

  • We need better robust handling of various configuration formats including just referencing the container image as a string rather than a dictionary of options.
  • Currently this code only handles the setting of the command and platform used.
  • Mapping the local code into the docker image is currently disabled as this can cause issues with certain docker setups. It may be better to instead just trigger a re-build of the docker image and let the Dockerfile figure out what to do.
  • Ping and Status checking are disabled or have a naïve implementation as the existing code relied on assumptions which only applied to the specific runtime container serverless offline was using
  • Response templates are loaded based on the image name which will may be too limited for people reusing same image across multiple functions
  • AWS Credentials currently aren't persisted or loaded in the docker container.

The intention is we would incrementally add support for more configurations and use cases over time. Rather than waiting for the perfect implementation which covers all use cases which in my view would increase likelihood this project just ends up not supporting any use case.

Motivation and Context

For those who have moved to using containers with lambda then currently you cannot use serverless offline since it only supports handlers uploaded as a .zip file which forces workarounds such as two configuration files one for production and one for development.

You can read more here #1324

How Has This Been Tested?

At the moment I have tested against our own project which already specified a lambda and a Dockerfile since this is a POC. But when I make this code production ready I aim to add a suite of tests to the ones which already exist here.

The majority of the code has been untouched so it should work.

Screenshots (if appropriate):

@dnalborczyk
Copy link
Collaborator

thank you for putting in the time and effort @jcampbell05 ! this is greatly appreciated! it might take some time to get to your PR, stay tuned. 😉

@jcampbell05
Copy link
Author

@dnalborczyk I'm keen to get a working solution as this would be very useful to us. Do you have time to walk through this ?

@shide1989
Copy link

any updates about the status of this PR ?

@jcampbell05
Copy link
Author

any updates about the status of this PR ?

Still waiting on @dnalborczyk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants