ankane/blazer-docker

Adding oracle support fails rake task

Closed this issue · 7 comments

Hello,

i'm building blazer with oracle support. As stated on blazer repo i changed Gemfile adding this:

gem 'activerecord-oracle_enhanced-adapter'
gem "ruby-oci8" # for oracle

and switched docker base image to redhat registry.access.redhat.com/ubi8/ruby-27:latest which has ruby 2.7 and allows installation of oracle instantclient packages (on default alpine image instantclient 21 was not working).

This is the dockerfile

FROM registry.access.redhat.com/ubi8/ruby-27:latest

MAINTAINER Andrew Kane <andrew@chartkick.com>
USER root

RUN gem install bundler

ENV INSTALL_PATH /app

RUN mkdir -p $INSTALL_PATH

WORKDIR $INSTALL_PATH

COPY Gemfile Gemfile.lock ./

COPY oracle-instantclient-basic-21.1.0.0.0-1.x86_64.rpm /tmp
COPY oracle-instantclient-devel-21.1.0.0.0-1.x86_64.rpm /tmp
COPY oracle-instantclient-sqlplus-21.1.0.0.0-1.x86_64.rpm /tmp
RUN  dnf localinstall -y /tmp/oracle*

RUN bundle install --binstubs

COPY . .

RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass@127.0.0.1/dbname SECRET_TOKEN=dummytoken assets:precompile

ENV PORT 8080

EXPOSE 8080

CMD puma -C /app/config/puma.rb

Everything goes ok until the last run, which fails due to:

Step 15/18 : RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass@127.0.0.1/dbname SECRET_TOKEN=dummytoken assets:precompile
 ---> Running in ff82ea04c298
Warning: NLS_LANG is not set. fallback to US7ASCII.
rake aborted!
NameError: uninitialized constant ActiveRecord::ConnectionAdapters::ConnectionSpecification
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/database_configurations/url_config.rb:63:in `build_url_hash'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/database_configurations/url_config.rb:68:in `build_config'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/database_configurations/url_config.rb:36:in `initialize'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/database_configurations.rb:191:in `new'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/database_configurations.rb:191:in `environment_url_config'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/database_configurations.rb:133:in `build_configs'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/database_configurations.rb:18:in `initialize'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/core.rb:51:in `new'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/core.rb:51:in `configurations='
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/core.rb:53:in `block in <module:Core>'
/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concern.rb:122:in `class_eval'
/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concern.rb:122:in `append_features'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/base.rb:293:in `include'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/base.rb:293:in `<class:Base>'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/base.rb:277:in `<module:ActiveRecord>'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/base.rb:27:in `<top (required)>'
/usr/share/gems/gems/activerecord-oracle_enhanced-adapter-6.0.6/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb:3:in `<top (required)>'
/usr/share/gems/gems/activerecord-oracle_enhanced-adapter-6.0.6/lib/activerecord-oracle_enhanced-adapter.rb:8:in `block in <class:OracleEnhancedRailtie>'
/usr/share/gems/gems/railties-6.0.3.7/lib/rails/railtie.rb:245:in `instance_exec'
/usr/share/gems/gems/railties-6.0.3.7/lib/rails/railtie.rb:245:in `block in run_tasks_blocks'
/usr/share/gems/gems/railties-6.0.3.7/lib/rails/railtie.rb:253:in `each'
/usr/share/gems/gems/railties-6.0.3.7/lib/rails/railtie.rb:253:in `each_registered_block'
/usr/share/gems/gems/railties-6.0.3.7/lib/rails/railtie.rb:245:in `run_tasks_blocks'
/usr/share/gems/gems/railties-6.0.3.7/lib/rails/application.rb:517:in `block in run_tasks_blocks'
/usr/share/gems/gems/railties-6.0.3.7/lib/rails/engine/railties.rb:15:in `each'
/usr/share/gems/gems/railties-6.0.3.7/lib/rails/engine/railties.rb:15:in `each'
/usr/share/gems/gems/railties-6.0.3.7/lib/rails/application.rb:517:in `run_tasks_blocks'
/usr/share/gems/gems/railties-6.0.3.7/lib/rails/engine.rb:459:in `load_tasks'
/app/Rakefile:6:in `<top (required)>'
/usr/share/gems/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/cli/exec.rb:63:in `load'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/cli.rb:474:in `exec'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/cli.rb:30:in `dispatch'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/cli.rb:24:in `start'
/usr/local/share/gems/gems/bundler-2.2.20/exe/bundle:49:in `block in <top (required)>'
/usr/local/share/gems/gems/bundler-2.2.20/lib/bundler/friendly_errors.rb:128:in `with_friendly_errors'
/usr/local/share/gems/gems/bundler-2.2.20/exe/bundle:37:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
(See full trace by running task with --trace)

I tried building without the changes on gemfile and same dockerfile and goes ok. If i add ruby-oci8 works, but if i add activerecord-oracle_enhanced-adapter, everything breaks.

Any suggestion? I don't know if i have to select another activerecord package instead of the one stated in the documentation.

Luca

Hey @remixtj, it looks like active_record/connection_adapters/connection_specifications isn't being loaded. I'm not sure why that would be the case, but you can try adding:

require "active_record/connection_adapters/connection_specifications"

to config/application.rb right after require "rails/all".

Hello,

error is changed now:

LoadError: cannot load such file -- active_record/connection_adapters/connection_specifications

This is the change i've made:

diff --git a/config/application.rb b/config/application.rb
index 515e594..422e3cf 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -1,6 +1,7 @@
 require "bundler/setup"
 Bundler.require
 require "rails/all"
+require "active_record/connection_adapters/connection_specifications"
 
 abort "No DATABASE_URL" unless ENV["DATABASE_URL"]

Now i'm googling a bit to see if i can find something useful.

Oops, looks like it should be singular. Try:

require "active_record/connection_adapters/connection_specification"

Hello,

NameError: uninitialized constant ActiveRecord::ConnectionAdapters::ConnectionHandler

But adding require "active_record/connection_adapters/connection_handler" leads to:

LoadError: cannot load such file -- active_record/connection_adapters/connection_handler

I'm now checking what changes introduces the installation of

gem 'activerecord-oracle_enhanced-adapter'

Hello,

looks like changing the Gemfile entry to:

gem 'activerecord-oracle_enhanced-adapter', :require => false

allows the docker build to complete, but i'm not sure if this has any impact on application, since that param should exclude from bundler load.

Luca

Seems ok, because i've been able to run a simple select from an oracledb set with env variable BLAZER_DATABASE_URL=oracle-enhanced://user:password@oraserver:1521/oradb

Awesome, thanks for sharing the fix!