I have an old Ruby on Rails app, Ruby 2.5 and Rails 3.2, that I finally got around to switching to the next generation Circle docker images, but I’m getting an error on the first test build.
bundle _1.17.3_ exec rake db:migrate db:seed
rake aborted!
BCrypt::Errors::InvalidHash: invalid hash
/home/circleci/project/vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt.rb:171:in `initialize'
/home/circleci/project/vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt.rb:161:in `new'
/home/circleci/project/vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt.rb:161:in `create'
/home/circleci/project/vendor/bundle/gems/activemodel-3.2.22.5/lib/active_model/secure_password.rb:69:in `password='
/home/circleci/project/vendor/bundle/gems/activerecord-3.2.22.5/lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
/home/circleci/project/vendor/bundle/gems/activerecord-3.2.22.5/lib/active_record/attribute_assignment.rb:78:in `each'
/home/circleci/project/vendor/bundle/gems/activerecord-3.2.22.5/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
/home/circleci/project/vendor/bundle/gems/activerecord-3.2.22.5/lib/active_record/base.rb:498:in `initialize'
/home/circleci/project/vendor/bundle/gems/activerecord-3.2.22.5/lib/active_record/validations.rb:39:in `new'
/home/circleci/project/vendor/bundle/gems/activerecord-3.2.22.5/lib/active_record/validations.rb:39:in `create!'
/home/circleci/project/db/seeds.rb:9:in `<top (required)>'
/home/circleci/project/vendor/bundle/gems/activesupport-3.2.22.5/lib/active_support/dependencies.rb:245:in `load'
/home/circleci/project/vendor/bundle/gems/activesupport-3.2.22.5/lib/active_support/dependencies.rb:245:in `block in load'
/home/circleci/project/vendor/bundle/gems/activesupport-3.2.22.5/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/circleci/project/vendor/bundle/gems/activesupport-3.2.22.5/lib/active_support/dependencies.rb:245:in `load'
/home/circleci/project/vendor/bundle/gems/railties-3.2.22.5/lib/rails/engine.rb:525:in `load_seed'
/home/circleci/project/vendor/bundle/gems/activerecord-3.2.22.5/lib/active_record/railties/databases.rake:347:in `block (2 levels) in <top (required)>'
/home/circleci/project/vendor/bundle/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `load'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `kernel_load'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:28:in `run'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/cli.rb:463:in `exec'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/cli.rb:27:in `dispatch'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/cli.rb:18:in `start'
/home/circleci/.rubygems/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>'
/home/circleci/.rubygems/gems/bundler-1.17.3/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/home/circleci/.rubygems/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'
/home/circleci/.rubygems/bin/bundle:23:in `load'
/home/circleci/.rubygems/bin/bundle:23:in `<main>'
Tasks: TOP => db:seed
It’s happening when it tries to seed the database with test users. The bcrypt-ruby gem complains that the hash is invalid. This didn’t happen with the old Circle image. I can’t reproduce locally. Searching around, it sounds like the root cause may be the underlying bcrypt library in Ubuntu may be returning different values. Unfortunately, I can’t upgrade the bcrypt-ruby gem to fix this. It’s not an option with Rails 3. But I was confused why this came up when switching Circle images. I assumed that the new images would be “direct replacements” and largely be the same.
Here’s a minimal reproduction:
Here’s the full Circle config.yml:
version: 2.1
jobs:
rails:
docker:
- image: cimg/ruby:2.5.9-node
environment:
BUNDLE_FROZEN: "true"
BUNDLE_JOBS: 3
BUNDLE_RETRY: 3
BUNDLE_PATH: vendor/bundle
RAILS_ENV: test
RACK_ENV: test
- image: postgres:11
environment:
POSTGRES_USER: ubuntu
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: circle_ruby_test
resource_class: small
working_directory: ~/project
steps:
- restore_cache:
keys:
- source-v1-{{ .Branch }}-{{ .Revision }}
- source-v1-{{ .Branch }}-
- source-v1-
- checkout
- run: sudo apt-get update
- run: sudo apt-get install libsqlite3-dev
- save_cache:
key: source-v1-{{ .Branch }}-{{ .Revision }}
paths:
- .git
- restore_cache:
key: gem-dep-v2-{{ checksum "Gemfile.lock" }}
- run: ruby -v
- run: gem install --no-document bundler -v 1.17.3
- run: gem list bundler
- run: bundle _1.17.3_ -v
- run: bundle _1.17.3_ check || bundle _1.17.3_ install
- save_cache:
key: gem-dep-v2-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- ~/.bundle
- run: |-
mkdir -p config && echo 'test:
adapter: postgresql
database: circle_ruby_test
username: ubuntu
host: localhost
' > config/database.yml
- run: bundle _1.17.3_ exec rake db:create db:schema:load --trace
- run: bundle _1.17.3_ exec rake db:migrate db:seed
workflows:
build:
jobs:
- rails