Node.Js: Trying to access a ruby gem inside node app on heroku - ruby

I am trying to use this https://github.com/mooktakim/image_optim_bin on my Heroku application, and I'm really not sure as to how to do it. Right now I have the following code trying to run pngcrush
exec('pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB ' + file + ' ' + file, function(error, stdout, stderr) {
console.log('PNGCRUSH OUTPUT: ', error, stdout, stderr);
});
But it results in the following error on my heroku logs output:
PNGCRUSH OUTPUT: { [Error: Command failed: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'image_optim_bin' (>= 0) among 9 total gem(s) (Gem::LoadError)
This is my Gemfile
gem 'image_optim_bin', :git => 'https://github.com/mooktakim/image_optim_bin.git'
This is the first time I've tried using ruby gems inside a nodejs application so I really am unclear of how to do so. Is there a specific directory I need to target to run the gem?

Are you already using Heroku multi buildpacks to support both Node and Ruby? If so, I recommend running heroku run bash and then trying to execute pngcrush from the command line. You should be able to quickly identify the path you need.

Related

Ruby on Rail running apache show index of when accessing the site

I have recently updated to Apache 2.4, and I am using Ruby on Rail to run my application. Following the upgrade, the site shows a content as seen in the image below, and the error on the log file shows this error message. I have tried using the 'Bundle Install' and checked the permission but that hasn't helped. Any advice would be greatly appreciated. Thanks
[ 2022-02-07 07:47:24.5559 8104/7efc89c8f700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /home/adminuser/hroot: An error occured while starting up the preloader.
Error ID: ba7e6074
Error details saved to: /tmp/passenger-error-RA01E9.html
Message from application: libmysqlclient.so.18: cannot open shared object file: No such file or directory - /usr/local/rvm/gems/ruby-2.0.0-p353#hroot/gems/mysql2-0.3.14/lib/mysql2/mysql2.so (LoadError)
PassengerRuby /usr/local/rvm/gems/ruby-2.0.0-p353#hroot/wrappers/ruby
SetEnv GEM_HOME /root/.gem/ruby/1.9.1
This error shows a problem with the shared objects. You probably updated MySQL/MariaDB libraries with Apache and new libraries are incompatible with your mysql2 gem build. The solution is simple:
First, ensure you are using the ruby-2.0.0-p353#hroot RVM environment.
Then, execute the following command:
gem install mysql2 --version 0.3.14
This should rebuild your mysql2 gem for the new MySQL/MariaDB client libraries on your system.
this isn't the answer anyway but another method to run ruby (in my case Windows 10 ; if you use another OS try to find out how to modify inside index.php the ruby starter)
i post here an alternative method to use apache + php +... and ruby
https://stackoverflow.com/a/71733656/5781320

How to fix YouTube-dl Invalid parameters. on Heroku

When I try to download a song with youtube-dl.rb gem it works locally, but when I do it on Heroku it says this:
Terrapin::ExitStatusError - Command '/app/vendor/bundle/ruby/2.6.0/gems/youtube-dl.rb-0.3.1.2016.09.11.1/vendor/bin/youtube-dl --no-color --no-progress --print-json "ytsearch:notion hooked"' returned 1. Expected 0
It also says something about cocaine being deprecated like this:
DEPRECATION: The cocaine gem is deprecated. Please upgrade to terrapin. See https://github.com/thoughtbot/terrapin/ for further instructions.
This is my code that is running this gem:
song_list.each { |song|
# formatted_command = 'youtube-dl -o "' + __dir__.to_s + '/' + temp_dir_name + '/%(title)s.%(ext)s" -x --audio-format mp3 "ytsearch:' + song + '"'
# system formatted_command
options = {
audio_format: :mp3,
extract_audio: true,
output: "#{__dir__.to_s}/#{temp_dir_name}/%(title)s.%(ext)s",
}
YoutubeDL.download "ytsearch:#{song}", options
}
I commented two lines above that were downloading songs with the CLI tool, that worked as well, but I can't download that tool on a Heroku machine, so I have to use this Ruby wrapper.
Here are some instructions to running youtube-dl on your Heroku server:
create a requirements.txt file in the root of your repo, with content:
youtube-dl
Run the following three commands to set up Python buildpack as well as Ruby buildpack, making sure Ruby is the primary buildpack:
heroku buildpacks:add heroku/ruby
heroku buildpacks:add --index 1 heroku/python
heroku buildpacks:set heroku/ruby
Commit and deploy, test by opening heroku run bash and running youtube-dl. If it works here, you can also call it from Ruby.

Issue getting wkhtmltoimage working on Amazon Linux / Ruby on Rails

It works fine on my development environment (osx), but I can't get it to work on the server.
in my gemfile
gem 'imgkit'
gem 'wkhtmltoimage-binary'
When I run:
kit = IMGKit.new(html, quality: 100)
img_binary = kit.to_img
I get this error
IMGKit::CommandFailedError: Command failed:
/var/www/myapp/shared/bundle/ruby/2.3.0/bin/wkhtmltoimage --height 0 --quality 100 --format jpg - -:
/var/www/myapp/shared/bundle/ruby/2.3.0/gems/wkhtmltoimage-binary-0.12.5/libexec/wkhtmltoimage-amd64:
error while loading shared libraries: libjpeg.so.8: cannot open shared object file: No such file or directory
I've searched online and tried installing some more packages, but no success. Anyone able to help? Thanks.
Using 'wkhtmltoimage-binary', '~> 0.11.0.1.1' in the Gemfile fixed the issue for me. Found the solution here.

Ruby: 'Zip is not installed' error message when running on Win CMD this: buildpack-packager --uncached

I'm running cmd command buildpack-packer --uncached (or any other option of buildpack-packer). I had many error messages prior that. They were caused by bad content of manifest.yml. I corrected them. So now I receive this error message: Zip is not installed (RuntimeError)
I used gem install to install zip gem and rubyzip gem (as first did not work, so I tried a second). So now both not helping to get rid of this error message.
Here is a part of the installed gem list:
And here is the code that drops this error (found it based on the error message in file: C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/buildpack-packager-2.3.4/lib/buildpack/packager.rb):
I'm quite new in Ruby, so maybe I do some very basic mistake...
Thx in advance!!
Please don't use pictures or screenshots in your post. Use plaintext only.
I think you are misunderstanding the code:
_, _, status = Open3.capture3('which zip')
It checks if you have any zip program (executable) installed not a ruby gem (library). It actually executes which zip in your cmd shell.
For example on my system it found an oracle one:
c:\> which zip
/c/app/oracle/client11g/product/11.2.0/client/bin/zip
Then if you test it in irb:
irb(main):004:0> _, _, status = Open3.capture3('which zip')
=> ["/c/app/oracle/client11g/product/11.2.0/client/bin/zip\n", "", #<Process::Status: pid 10944 exit 0>]
You can see that the executable was found and success state is indicated by the 0. The variable status holds the return message - status => #<Process::Status: pid 10944 exit 0>
I have the which program from dev_kit:
c:\>which which
/c/prg_sdk/ruby/dev_kit/bin/which

If-else and error handing in command prompt

I am trying to detect if certain ruby gem is not installed, install it first and then proceed.
For instance:
gem which rails
returns path to gem's driver file (.rb) on stdout, if gem exists, if not it checks throws error on stderr.
How can I solve it?
Pseudo code:
if throws "gem which example1" ( gem install example1 )
if throws "gem which example2" ( gem install example2 )
if throws "gem which example3" ( gem install example3 )
:: install other stuff
Either cmd or powershell would work.
I need to add these in AppVeyor CI yaml configuration file. AppVeyor CI has this wonderful feature of caching the directory for DRY'ing installations to improve build performance. So I have cached the gems directory and it restores fine on running the build, but then gem install reinstalls the gem anyway!
By using powershell to run the command you can use error redirection to check if the command was successful:
$gemPath = gem which example3 2>$null
if ($gemPath)
{
# We got a path for the gem driver
}
else
{
# Failed, gem might not be installed
}
Explanation: We're telling powershell to store the result of "gem which example3" in the variable $gemPath, however if there is an error we want to redirect the error to the variable $null by using 2>$null
You can also replace 2 with the number corresponding to the stream you'd like to capture (Success, Error, Warning etc)
* All output
1 Success output
2 Errors
3 Warning messages
4 Verbose output
5 Debug messages
More on redirection here About_Redirection
Try, in .cmd script:
gem which rails 1>nul 2>&1
IF ERRORLEVEL 1 (gem install rails)
I'm assuming here you want the outputs to stdout and stderr stifled for purposes of this batch script - otherwise, drop the 1>nul 2>&1.

Resources