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

Ruby packaging does not include gems #5567

Closed
dholdren opened this Issue Dec 5, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@dholdren
Copy link
Contributor

dholdren commented Dec 5, 2018

This is a Bug Report

Description

When I first deployed my Ruby lambda to AWS via serverless, it did not have any of the gems available.
In order to successfully run my lambda, I had to run bundle install --deployment first. At this point the .bundle andvendor/bundle directories were created, and then when I deployed they were included in the zip file uploaded to AWS

Potential Fix

During the package step, detect if a Gemfile is present.
If so, spawn bundle install --deployment

@dschep

This comment has been minimized.

Copy link
Member

dschep commented Dec 5, 2018

This is out of scope for serverless framework. We don't even do this for NodeJS. Since ruby dependencies at least live in the same directory as your source code, you're lucky. I had to write serverless-python-requirements because of how python manages dependencies.

If you want to automatically install dependencies on deploy, I recommend writing a plugin to do so, or using the serverless hooks plugin.

first install the plugin:

sls plugin install -n serverless-hooks-plugin

Then add this to your serverless.yml:

plugins:
  - serverless-hooks-plugin
custom:
  hooks:
    package:initialize:
      - bundle install --deployment

@dschep dschep closed this Dec 5, 2018

@dholdren

This comment has been minimized.

Copy link
Contributor

dholdren commented Dec 5, 2018

well they don't typically live in the same directory.
when running it locally, you just do bundle install and the gems are saved in a shared location.

but when you are packaging an app for deployment, you would run bundle install --deployment (maybe on a build server), this "vendors" the dependencies to a subdirectory

thanks for the info on the python way and the hooks plugin. I'll look into those

@jalerson

This comment has been minimized.

Copy link

jalerson commented Dec 9, 2018

Hey guys,

This is not a problem for nodejs apps because npm builds the node_modules folder inside the project with all dependencies, and, since the framework packs everything inside the project folder, it automatically tackles this problem.

I respectfully disagree that this is out of scope for serverless framework because the framework can even exclude development dependencies (still unclear for which runtimes, but Ruby isn't one of them): https://serverless.com/framework/docs/providers/aws/guide/packaging#development-dependencies

@dholdren I just published a blog post handling this problem: https://dev.to/jalerson/building-aws-lambdas-for-real-world-using-ruby-and-serverless-framework-2p49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment