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

Bundle without test development #14

Open
wilkosz opened this issue Apr 19, 2020 · 9 comments
Open

Bundle without test development #14

wilkosz opened this issue Apr 19, 2020 · 9 comments

Comments

@wilkosz
Copy link

wilkosz commented Apr 19, 2020

Agenda

Drop test and development gems during build:
bundle install --standalone --path vendor/bundle --without test development;

@joshuaflanagan
Copy link
Owner

I’m not sure what build this is referring to. Gems in test and development groups should already be excluded from the package that is deployed to lambda. Are you seeing otherwise? Or is there something else you want them excluded from?

@wilkosz
Copy link
Author

wilkosz commented Apr 20, 2020

I could be wrong about the package the gets uploaded to the cloud provider, but the serverless package when built using serverless package contains gems listed in the test and development groups. Looking at https://github.com/joshuaflanagan/serverless-ruby-package/blob/master/index.js#L108 it appears that docker is building all the groups in the package for deployment.

Again I may be wrong. The setup.rb file of the serverless package contains gems within the test group i.e. rspec
Screen Shot 2020-04-21 at 7 43 27 am

Gemfile:

source "https://rubygems.org"

ruby '~> 2.5.5'

# development and test groups are not bundled as part of the deployment
group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  # gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'rake'
  gem 'pry'
  gem 'awesome_print'
end

group :test do
  gem 'rspec'
  gem 'launchy'
  gem 'capybara'
end

gem 'aws-sdk-secretsmanager'
gem 'redis-activesupport'
gem 'content_disposition'
gem 'mechanize'

@joshuaflanagan
Copy link
Owner

You may be right - I might have broken that part when I added the dockerized packaging step. I'll look into this.

@joshuaflanagan
Copy link
Owner

Oh, I see what you are referring to. Yes, the setup.rb still adds those gem directories to the load path, but the gem files are not actually included in the package zip. If you unzip the zip file and look in vendor/bundle/ruby/2.5.0/gems/ you will see that rspec, etc are not included.

The extra load paths are annoying, but should not break anything. I'm not sure how to fix that without manually building that setup.rb file. I was explicitly avoiding using the --without flag, since that changes your local working install - not just what goes in the package. You would then have to re-bundle every time to be able to use rspec again.

@apsoto
Copy link

apsoto commented May 4, 2020

This is causing breakage for me as well because dev dependencies that are native (debase) are failing the package step.

@joshuaflanagan
Copy link
Owner

@apsoto don't you need those dev dependencies installed in order to develop?
Or does this only come up in a separate build/package environment?

@apsoto
Copy link

apsoto commented May 4, 2020

I've tried to troubleshoot this a bit and I had some success excluding dev and test groups without breaking the host's bundle environment.

The solution is to mount .bundle so it does not over write the host's config file

docker run --rm --mount type=volume,dst=/var/task/.bundle -v "$PWD:/var/task" lambci/lambda:build-ruby2.5 bundle install --standalone --path vendor/bundle --without='development test'

The .bundle mount options have to be before the -v otherwise it's ignored if they are mounted after the parent dir was mounted.

In addition to updating the docker command that is run, we need some additional enhancements:

  • You have to specify --without, when I use --with=default I still get the dev and test groups included.
    We would need the ability to pass the bundle groups to exclude via serverless config

NOTE I haven't fully vetted this, beyond getting the bundle task to run AND exclude certain bundle groups.

@apsoto
Copy link

apsoto commented May 4, 2020

I use the dev and test groups for local unit testing, yard for docs, simplecov for code coverage, etc., some dev dependencies are necessary for VSCode plugins I use, but aren't necessary for production

@apsoto
Copy link

apsoto commented May 4, 2020

also, forgot to mention, this only became a problem once I added a native package to the default group.

I had a native package in dev/test group and things would package and deploy without a problem.
However, once I added a gem with native dependencies in the default group, I started getting problems with the package step trying to build the native gems in my dev/test group

I have to comment out my native gems in the dev/test groups to get package/deploy to work rt now

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

No branches or pull requests

3 participants