How to install import script gem dependencies?

(Tobias Mühl) #1

Some import scripts are using external dependencies, and those seem to work just fine.

When trying to add my own Gemfiles, I’m always presented with

/usr/local/lib/ruby/gems/2.3.0/gems/activesupport- `require': cannot load such file -- redcarpet (LoadError)
        from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport- `block in require'
        from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport- `load_dependency'
        from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport- `require'
        from emed.rb:4:in `<main>'

I’m installing the gem using the root user inside the docker image since the discourse user isn’t privileged enough, and the gem’s can be run from the command line from the discourse user just fine. Just require redcarpet doesn’t work.

(Gerhard Schlager) #2

I recommend adding your dependency to the Gemfile and using bundler to install the gems. Run this inside the Docker container:

cd /var/www/discourse
echo "gem 'my_gem'" >> Gemfile
su discourse -c 'bundle install --no-deployment --without test --without development --path vendor/bundle'

And you need to run your import script as user discourse as well:

su discourse -c 'bundle exec ruby script/import_scripts/my_import_script.rb

(Tobias Mühl) #3

Thanks for the reply. Installing the gem using bundler worked the way you suggested, however running the import script with bundler didn’t work. Used su discourse -c 'ruby script/import_scripts/my_import_script.rb' instead, that worked