Setting the Environment in Gemfile for Bundling Install/Update Based on a Customize File

Setting the environment in Gemfile for bundling install/update based on a customize file

When doing a bundler require you can specify which groups to be required.

For example:

require 'rubygems'
require 'bundler'

if ENV['RACK_ENV'] == 'development'
Bundler.require(:default, :development)
else
Bundler.require(:default)
require 'sinatra'

More info on the bundler site gemfile specifications found here.

Bundler: You are trying to install in deployment mode after changing your Gemfile

The error message you're getting regarding Gemfile.lock may be because your Gemfile and Gemfile.lock don't agree with each other. It sounds like you've changed something in your Gemfile since you last ran bundle install (or update). When you bundle install, it updates your Gemfile.lock with any changes you've made to Gemfile.

Make sure you run bundle install locally, and check-in to source control your newly updated Gemfile.lock after that. Then try deploying.

Edit: As recognised in the comments, a conditional in the Gemfile resulted in a valid Gemfile.lock on one platform, invalid on another. Providing a :platform flag for these platform-dependent gems in the Gemfile should solve the asymmetry.

Running bundle or rspec adds line to Gemfile.lock

This was caused by global bundler config. Setting to false stopped the behavior.

specific_platform (BUNDLE_SPECIFIC_PLATFORM): Allow bundler to resolve for the specific running platform and store it in the lockfile, instead of only using a generic platform. A specific platform is the exact platform triple reported by Gem::Platform.local, such as x86_64-darwin-16 or universal-java-1.8. On the other hand, generic platforms are those such as ruby, mswin, or java. In this example, x86_64-darwin-16 would map to ruby and universal-java-1.8 to java.

Bundler: You must use Bundler 2 or greater with this lockfile

I deleted the project and made a git clone from the Heroku app, don´t know if it is a good solution, but it worked for me.

Install a specific set of gems in a CircleCI configuration file

THIS SOLUTION ONLY WORKS WITH CIRCLE 1.0

From my current research I had to verify the continous_integration environment
was setup correctly throughout Rails inside of secrets, the environments folder, gems, etc. As it turns out I have discovered that bundler does not use the ENV set so I am working with the following configuration know to force cache the gems, speed up the build process, and use the continous_integration environment.

References

  • CircleCI gems caching
  • https://github.com/sj26/rspec_junit_formatter/issues/50#issuecomment-312787281

.rspec

--color
--require spec_helper
--format documentation

.circle.yml

machine:
timezone:
America/Los_Angeles
ruby:
version:
2.4.1
services:
- redis

dependencies:
pre:
- gem install bundler
- gem update bundler
override:
- bundle config without development:test
- bundle check --path=vendor/bundle || bundle install --without development test --path=vendor/bundle --jobs=4 --retry=3:
timeout: 180

database:
override:
- RAILS_ENV=continous_integration bundle exec rake db:drop
- RAILS_ENV=continous_integration bundle exec rake db:setup

test:
override:
- RAILS_ENV=continous_integration bundle exec rspec --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec.xml
post:
- gem install brakeman
- gem install rubocop
- gem install rubocop-rspec
- RAILS_ENV=continous_integration bundle exec rubocop --format fuubar --require rubocop-rspec --config .rubocop.yml
- RAILS_ENV=continous_integration brakeman -z

Gemfile

group :development do
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'spring-commands-rspec'
gem 'spring-commands-rubocop'
end

group :development, :test do
gem 'pry-rails'
gem 'pry-nav'
gem 'pry-clipboard'
gem 'pry-rescue'
gem 'table_print'
gem 'awesome_print'
gem 'guard-rake'
gem 'guard-rspec'
end

group :development, :test, :continous_integration do
gem 'brakeman', require: false
gem 'rubocop', require: false
gem 'rubocop-rspec', require: false
gem 'timecop'
gem 'mail_safe'
gem 'dotenv-rails'
gem 'factory_girl_rails'
gem 'faker', '~> 1.6.6'
end

group :test, :continous_integration do
gem 'simplecov'
gem 'database_cleaner'
gem 'rspec-rails'
gem 'json_spec'
gem 'json-schema'
gem 'json_matchers'
gem 'shoulda-matchers'
gem 'nyan-cat-formatter'
gem 'rspec_junit_formatter', '~> 0.3.0.pre6'
gem 'webmock'
gem 'vcr'
end

This setup will yield the correct error output in Circle CI too

Sample Image



Related Topics



Leave a reply



Submit