Specifying the gem dependecies for plugin - gem does not exist

I did go through the suggesstions in following posts

So I tried 2 ways

Specifying in plugin.rb file


My plugin depends upon “mini_magick” for image resizing, so I specified it in plugin.rb

gem ‘mini_magick’, ‘~> 4.8’

But I get the following error

I, [2017-07-09T03:54:49.899941 #13] INFO – : > cd /var/www/discourse && sudo -E -u discourse bundle exec rake db:migrate
ERROR: While executing gem … (Gem::Requirement::BadRequirementError)
Illformed requirement ["/root"]
I, [2017-07-09T03:54:54.692893 #13] INFO – : /root is not writable.
Bundler will use `/tmp/bundler/home/discourse’ as your home directory temporarily.
gem install mini_magick -v ~> 4.8 -i /var/www/discourse/plugins/discussbook-plugin/gems/2.4.1 --no-document --ignore-dependencies
You are specifying the gem mini_magick in /var/www/discourse/plugins/discussbook-plugin/plugin.rb, however it does not exist!

Specifying in yml file


As it was not working, I tried to add the gem install command in yml file custom commands

  • exec: gem install mini_magick -v 4.8.0

I get the following log(success) when it was being rebuilt

I, [2017-07-08T18:50:43.302333 #13] INFO – : Beginning of custom commands
I, [2017-07-08T18:50:43.302751 #13] INFO – : > gem install mini_magick -v 4.8.0
I, [2017-07-08T18:50:44.034391 #13] INFO – : Successfully installed mini_magick-4.8.0
1 gem installed

But when I try to require it in the route, I got the following error in error log

NameError (uninitialized constant) DiscussBook::DiscussbookController::MiniMagick)

Both of these trials did not work, can you please help me regarding what might be the error?

I don’t know, but you might make sure that the directory that is getting to write to is world writable.

1 Like

I can run the plugin locally… But in the server, the docker rebuild causes this issue.
Are you suggesting that I should enter inside docker, and change the permissions of folder to writable?
I will try that out, but if it would have been possible from plugin itself, it would be great.

This is not how you include gems,

The version has to be specific, you can not use ~>

4 Likes

Apparently, the most salient part of my earlier message was “I don’t know”. :slight_smile:

3 Likes

Hi @sam, thanks for answer.
I tried this many times in different configurations, but it failed. Then I came to know real cause, though I do not know the solution

When I install the discourse-backups-to-dropbox plugin from github (plugin that you shared), the docker builds properly. But if I put it discourse-backups-to-dropbox in private repository like bitbucket, it throws the error. The error logs for the plugin are same as shared in first post ie

E -u discourse bundle exec rake db:migrate
ERROR: While executing gem … (Errno::EACCES)
Permission denied @ dir_s_mkdir - /var/www/discourse/plugins/discourse-backups-to-dropbox/gems
I, [2017-07-10T18:18:41.229582 #15] INFO – : /root is not writable.
Bundler will use `/tmp/bundler/home/discourse’ as your home directory temporarily.
gem install public_suffix -v 2.0.5 -i /var/www/discourse/plugins/discourse-backups-to-dropbox/gems/2.4.1 --no-document --ignore-dependencies
You are specifying the gem public_suffix in /var/www/discourse/plugins/discourse-backups-to-dropbox/plugin.rb, however it does not exist!
I, [2017-07-10T18:18:41.230126 #15] INFO – : Terminating async processes

So I guess the problem lies in the my private repo configuration. But if the plugin(without any gem) gets installed properly from bitbucket, I do not know why would installing plugin with gem throw error. It should not matter whether the plugin is in open repository like github or in private repo like bitbucket.

My private repo config

  • exec: cd /var/www/discourse && sudo -u discourse bundle install --deployment --without test --without development
  • exec: mkdir /root/.ssh
  • exec: ssh-keyscan -t rsa bitbucket.org > /root/.ssh/known_hosts
  • exec: echo “Host bitbucket\n\tStrictHostKeyChecking no\n\tHostName bitbucket.com\n\tIdentityFile /root/.ssh/id_rsa\n” >> /root/.ssh/config
  • file:
    path: /root/.ssh/id_rsa
    chmod: 600
    contents: |
    -----BEGIN RSA PRIVATE KEY-----


    -----END RSA PRIVATE KEY-----
  • file:
    path: /root/.ssh/id_rsa.pub
    chmod: 600
    contents: ssh-rsa …
  • exec: cd $home/plugins && git clone git@bitbucket.org:path/to/discourse-backups-to-dropbox.git
  • exec: cd $home && sudo -E -u discourse bundle exec rake db:migrate
  • exec: cd $home && rm -fr tmp/cache
  • exec: cd $home && sudo -E -u discourse bundle exec rake assets:precompile
  • exec: rm /root/.ssh/id_rsa
  • exec: rm /root/.ssh/id_rsa.pub

Its same as mentioned in tutorial
https://meta.discourse.org/t/install-a-plugin/19157/33?u=net_deamon

I still don’t know.

If sounds like a permissions problem. You might chmod - r 777 the repo after you clone it.

1 Like

You are awesome @pfaffman. Thanks :slight_smile: :+1:

1 Like

That is one hell of a scary advice.
I advise to figure out which user needs write permissions, and then chown it to that user, keeping the permissions at 0755.

2 Likes

Thanks :slight_smile: ,
Yes I am now rebuilding with 755.
Atleast I got to know where the issue was.
I had been struggling with this for 3 days …

1 Like

Yes. Once you see if that fixes it and what the ownership of the files created are, you should take steps to lock things back down.

I know this is an old issue, and that the solution has been found, but I encountered a similar problem and what I did to resolve it was:

  1. Use a specific version, not “~>”, as Sam says above
  2. Version numbers should be “1.4.0” not just “1.4”, because while discourse installs “gemname-1.4.0” correctly, it looks for the declared “gemname-1.4” and fails.

Leaving this here in case it helps someone else who encounters this problem.

1 Like