copy/ install wkhtmltoimage on heroku from heroku bash - ruby-on-rails

i am using wkhtmltoimage for my app.While deploying it to heroku it shows wkhtmltoimage executable not found in /usr/local/bin means that i have to install or copy executable to the heroku 's local/bin folder how can i install or copy from heroku bash to /usr/local/bin folder

Heroku does not play nicely with the IMGKit gem, and in order to make the screenshots work you need to download a compiled version of IMGKit.
https://wkhtmltopdf.googlecode.com/files/wkhtmltoimage-0.10.0_rc2-static-amd64.tar.bz2
You unzipped it and put it in the ‘bin’ directory of the application. Then make a configure file for IMGKit so that this would actually take effect.
IMGKit.configure do |config|
config.wkhtmltoimage = Rails.root.join('bin', 'wkhtmltoimage-amd64').to_s if ENV['RACK_ENV'] == 'production'
end

Related

can't deploy rails app since upgrade to Capistrano3

I have upgraded to Capistrano3 and followed the steps in the capistrano3 documentation but still get the error LoadError: cannot load such file -- config/deploy
I am sure that I am using Capistrano 3; here is my config/deploy.rb: http://pastie.org/9483501
full log : http://pastie.org/9483504
The uprade docs say:
We recommend to capify the project from scratch and move definitions
from old to new configs then.
mkdir old_cap
mv Capfile old_cap
mv config/deploy.rb old_cap
mv config/deploy/ old_cap # --> only for multistage setups
cap install
I did this, got my new capfiles, and then followed the preparing your application doc to set everything up again with the new v3 syntax, and it all worked.

Redmine Icalendar export issue in mac

I am facing some issues when try to install following plugin in mac os.
It is working fine in linux as well as in windows.
https://github.com/thegcat/redmine_ical
Steps I followed:
After copying plugin files in vendor/plugin folder. Redmine stops working and shows "We're sorry but something went wrong" error message.
I am using bitnami-redmine-1.4.7-2-osx-x86_64-installer.dmg and when I remove Gemfile and require dispatcher from init.rb It starts running but doesn't show Ical on calendar page.
After copying plugin file we need to run "bundle install" command from terminal.
In bitnami stack redmine after copying plugin file,
1) $cd install dir
2) $./use_redmine
3) $bash: cd root_dir
4) bundle install
This will work .
The accepted answer didn't work for me, but did help me one step.
I had to do the following to make it work succesfully:
cd installdir/apps/redmine/htdocs
bundle install --without development test postgresql sqlite --no-deployment
bundle install --without development test postgresql sqlite --deployment
ruby bin/rake redmine:plugins RAILS_ENV=production
This all in addition to (or actually from within) using the "use_redmine" bash from the install dir.
I've opted to go for the other ical plugin, that didn't require the patchfiles (https://github.com/buschmais/redmics)
https://docs.bitnami.com/installer/apps/redmine/#how-to-install-the-redmine-agile-plugin

How to run "rails s"

I have a problem running rails s in Ubuntu. When I type rails s it doesn't start the server, but instead it outputs:
kyala#ubuntu:~/depot$ rails s
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /home/kyala/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db)enter code here
# Default: sqlite3
-b, [--builder=BUILDER] # Path to an application builder (can be a filesystem path or URL)
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
[--dev] # Setup the application with Gemfile pointing to your Rails
checkout
[--edge] # Setup the application with Gemfile pointing to Rails
repository
[--skip-gemfile] # Don't create a Gemfile
-O, [--skip-active-record] # Skip Active Record files
-T, [--skip-test-unit] # Skip Test::Unit files
-J, [--skip-prototype] # Skip Prototype files
-G, [--skip-git] # Skip Git ignores and keeps
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend] # Run but do not make any changes
-q, [--quiet] # Supress status output
-s, [--skip] # Skip files that already exist
Rails options:
-v, [--version] # Show Rails version number and quit
-h, [--help] # Show this help message and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going.
Try to regenerate binstubs:
rm bin/*
rake rails:update:bin
It should do the trick.
For newer (5.2+) Rails versions use
rake app:update:bin
When the script folder is missing from the Rails application folder it shows the above error.
I just copied it from another app and it worked for me.
Before running the Rails server, you need to first create a Rails application.
For example, to create a new app call "test_app", run the following:
rails new test_app
Once your application is created, you can cd into the directory and start your server:
cd test_app
rails server
OK guyz just for the closure... this problem occurs only when we delete some(mostly script) folders in the rails app... (may be.. accidentally.).. I had this issue but was in a wrong app folder...
My first hunch would be that you are not in the root of your Rails application.
On our deployment servers, I have to type
./script/rails s
when in the root-folder of my Rails-app. I think that is because bin\rails is not known there.
If that would not work, it seems to me that you are not at all inside a Rails root folder, which would also explain why rails s did not work.
A Rails root project will contain at least the following directories: app, lib, config, script ....
I've seen a similar issue with Rails 2.x apps. They fire up fine with thin, unicorn and such, but to get just the webrick server I've had to run bundle exec script/server (or for the less careful script/server seems to work). I don't know the root issue at play here, but this seems to tide me over as I don't maintain any rails 2.x code (simply running ChiliProject 3.x, etc.).
We had the same problem.
Be sure you run the 'rails' command in the script folder and not the binary 'rails' that is different
script/rails s
It´s the same that if you go to your script folder and run the command:
cd script
./rails s
Check whether the 'script' folder exists in your application structure.
I had the same issue. I had forgotten to run bundle after creating an app.
From the root of your project directory run:
bundle install
Run the following command inside your project folder:
rails s
Your project folder contains node_modules, Gemfile.lock, etc...
While searching for an answer myself, I ended up trying a few things that proved useful to getting rails s to work for me. This resulted in 658 files changed, 102204 insertions, and 149 deletions.
Look at the file that you're in by running ls.
Run git status.
Run git add ..
Run git commit -m "Notate whatever changes you are adding to github repository".
I tried to run git push and git push master but neither work, "go figure." My guess is that you can't push changes that belong to a different file or branch.
HERE's THE SECRET... For some strange reason, I was working in a different file so I had to run a git pull YourOtherFile. This is where everything started making sense.
Now, I ran another git status to understand what was going on within this file. There was modified and untracked content.
Next, cd back into the other file.
Run git status to view all of your modified and untracked files.
Run git add . and git commit -m "Notate your changes to this repository".
Watch the magic happen then run a git push.
Run gem update bundler.
Then I ran gem install rails_12factor.
Run another git status to view your modification.
Run git commit -m "Successfully added gem rails_12Factor".
Run git push.
I had issues with bcrypt being locked at 3.1.11 so I ran gem install 'bcrypt'.
Run gem install rails_12factor yet again. I believe that I had the "f" in "factor" capitalized.
Run gem update.
Run gem install pg.
Run git add ..
Run git commit -m "Updated Gemfile".
Run git push.
Run gem install 'pg' yet again.
I was running into all kind of issues but it was because I was trying to upgrade my gemfile to Rails 5.
Run gem install railties.
Run gem install activesupport.
If your Gemfile was already in another version of Rails (gem 'rails', '4.2.6'), make sure that you keep it there as there was not a significant difference in Rails 5.
Just Run 'bundle update' command and start your application
Try "rails server" instead of the short form. Maybe you have it aliased for some reason.

Using Hunspell With Heroku

I'm building a Rails app that uses Hunspell and the hunspell-ffi gem so that Ruby can interface with it. I'm deploying the app to heroku, but unfortunately it needs Hunspell to be installed on the server in order for the gem to work.
Is there any way for me to install Hunspell on Heroku? Or am I going to have to migrate to EC2?
Thanks in advance :)
You need to build the required Hunspell library and include it in your Heroku project directly.
Heroku runs on 64-bit Ubuntu therefore the binary has to be compiled under that system. The best approach is to simply use Heroku's Vulcan build server to compile on a Heroku instance.
Compiling for Heroku
gem install vulcan
vulcan create vulcan-compile-me last argument is your own app name.
Download Hunspell source
Extract
vulcan build -v -s ./hunspell-1.3.2 Tells Vulcan to build it and downloads the finished product automatically to /tmp/hunspell..
The build server requires the cloudant add-on, this is installed automatically but you have to make sure to have a verified (credit card added) Heroku account. If you get errors in step six of no build output then do heroku addons:add cloudant --app vulcan-compile-me
Adding to Your Project
Extract the Heroku Vulcan build tar from /tmp
Copy the entire lib folder to vendor/hunspell in your project root directory
Tell Heroku where to look for libraries: heroku config:add LD_LIBRARY_PATH=vendor/hunspell/lib.
Install Dictionaries
Download some dictionaries from Open Office and add them to your project. A good location is a folder called dictionaries at root level. This path is then referenced when initializing Hunspell in Ruby.
http://extensions.services.openoffice.org/dictionary
ftp://sunsite.informatik.rwth-aachen.de/pub/mirror/OpenOffice/contrib/
Using
Install your favorite Hunspell gem, I use hunspell-ffi. There is a newer gem for Hunspell but I prefer the previous FFI gem. To use initialize the Hunspell object with your dictionaries folder path and language (language match the dictionary file name).
dict = Hunspell.new("dictionaries", "en_US")
if dict.check('caribean') == false
suggestions = dict.suggest('caribean')
if (suggestions.size)
correction = suggestions.first # returns 'caribbean'
end
end
Vendoring for More Complex Projects
You can also vendor the library into your project by putting the tar built by the Vulcan server in the first step into a public accessible server such as Google Storage and then changing the Heroku build pack to download the tar on each instance startup.
heroku config:set BUILDPACK_URL=https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
The vendor build pack looks for a .vendor_urls file at the root level with HTTP links to the tar balls to install (needs to end in a new line to work).
http://commondatastorage.googleapis.com/developer.you.com/hunspell-heroku-1.3.tgz
Vendoring unpacks the tar into the root folder so the lib path for the Heroku settings would then just be "lib". heroku config:add LD_LIBRARY_PATH=lib
Unless I am mistaken or something has changed (I cannot find any evidence of this), you cannot install external native libraries on Heroku. If the library is not already installed (this is the case, I think, for ImageMagick, and perhaps others), you will not be able to use the gem.
Checkout this url: http://gems-summary.heroku.com/2011-07-19
It's freaking amazing how much support Heroku has for the gem community. So all you need to to is add the gem to your bundle since Hunspell is on rubygems, bundle install, and then deploy.
Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'hunspell'
Then add to git:
git add .
git commit -m 'added hunspell'
Then bundle:
bundle
And deploy:
git push heroku
With Bundler, you should be able to install any gem. According to http://devcenter.heroku.com/articles/how-do-i-install-gems-for-my-app, "Almost any gem - even those with native dependencies - can be installed using Bundler. If there’s a specific gem that won’t install on Heroku, please submit a support ticket."
AFAIK, when your app is spun up, gems in the Gemfile are installed on-the-fly to the server your app is spun up to.
The Aspen stack has pre-installed gems, but you still should be able to add gems not pre-installed.
The bamboo stack has no pre-installed gems, so all gem dependencies must be declared explicitly. I believe that is the same for the Celadon stack.

Rails 3 -- Bundler/Capistrano Errors

I have a basic Rails 3 app working locally on my development box, but want to test out deploying early on to make sure everything works. I'm using Capistrano to deploy.
When I run cap deploy (after all the other necessary setup), it breaks on this command with this error:
[...]
* executing 'bundle:install'
* executing "bundle install --gemfile /var/www/trex/releases/20100917172521/Gemfile --path /var/www/trex/shared/bundle --deployment --quiet --without development test"
servers: ["www.[my domain].com"]
[www.[my domain].com] executing command
** [out :: www.[my domain].com] sh: bundle: command not found
command finished
[...]
So it looks like it can't find the bundle command on the server.
However, when I log in to the server...
$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
$ rails -v
Rails 3.0.0
$ bundle -v
Bundler version 1.0.0
...the bundle command works just fine.
What could be going wrong?
-
(Furthermore, for completeness:)
$ which ruby
~/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
$ which rails
~/.rvm/gems/ruby-1.9.2-p0/bin/rails
$ which bundle
~/.rvm/gems/ruby-1.9.2-p0/bin/bundle
UPDATE:
For RVM >= 1.11.3, you should now just use the rvm-capistrano gem. For older RVM >= 1.0.1, the answer below still applies.
ORIGINAL ANSWER:
Okay, though I still haven't gotten a full cap deploy to work, I did fix this problem. The problem was Capistrano trying to use a different path for Bundler (and other gems) than the RVM paths.
Check your Capistrano path by doing cap shell, then echo $PATH. You'll probably see your standard /usr/local/bin and /usr/bin, but that's not where RVM has Bundler, et al., stored.
Edit your Capistrano config/deploy.rb file, and add the following lines, per these instructions:
# Add RVM's lib directory to the load path.
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
# Load RVM's capistrano plugin.
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.2'
set :rvm_type, :user # Don't use system-wide RVM
That finally got Capistrano to see Bundler and start loading gems appropriately.
Bundler isn't found because .bash_profile is not being loaded and thus your PATH is wrong. This is probably because you have the RVM script in .bash_profile.
The simple answer is to move the RVM script from .bash_profile to .bashrc and Capistrano should be able to find it (also verify that .bash_profile sources .bashrc).
Capistrano uses SSH to execute commands on the server via a non-interactive shell. This shell session will source .bashrc but not .bash_profile. I added an ECHO statement to both and ran an LS via SSH. You can see in the results below that only .bashrc is sourced:
$ ssh user#123.amazonaws.com ls
.bashrc loaded
git
file1
file2
I had an identical problem using rbenv. The solution was to take the rbenv specific lines from the bottom of my .bashrc file and put them at the top. The first line of my .bashrc file was returning aborting if the shell wasn't running in interactive mode.
That last line should actually be
set :rvm_type, :user
that is, user must be a symbol and not a variable, otherwise you'll get
undefined local variable or method `user'
No rvm/capistrano worked for me. The best solution I found was adding to deploy.rb file the following line (it's for non system-wide RVM):
set :bundle_cmd, 'source $HOME/.bash_profile && bundle'
It was my understanding that the bundle command is not found because the PATH variable, defined in the user's ~/.bash_profile, isn't loaded by Capistrano.
To get around this I have created a task :bundle_gems.
task :bundle_gems do
run "cd #{deploy_to}/current && export PATH=/usr/local/pgsql/bin:/opt/ruby-enterprise-X.X.X/bin:$PATH && bundle install vendor/gems"
end
Note that I also include the path to PostgreSQL binaries - installation of the pg gem was failing because they could not be found, even when bundle could be found.
This seems like a messy approach, though. Presumably there is a more 'global' place to define paths to binaries that I don't know about.
Update 23/12
To add a directory to $PATH for all users: https://serverfault.com/questions/102932/adding-a-directory-to-path-in-centos
However this still won't be loaded because it is a non-interactive non-login shell.
One suggestion was to add the paths to /etc/bashrc: How do I set $PATH such that `ssh user#host command` works?
However this also didn't work for me. I believe its because SSH doesn't load /etc/bashrc either.
Another suggestion was to edit ~/.ssh/environment: http://www.ruby-forum.com/topic/79248. However this seems almost as messy as specifying the paths in deploy.rb.
This one worked for me:
set :bundle_cmd, 'source $HOME/.bash_profile && bundle'
I tried a number of the suggestions. Had problems with setting the paths in the deploy.rb file for the RVM environment. My final solution was to include the following:
In the config/deploy.rb file add:
require "bundler/capistrano"
Also in config/deploy.rb, or in my case config/production.rb as I was using the multistage option for Capistrano
after "deploy", "rvm:trust_rvmrc"
This step simply ensures that we stop getting the 'do you want to trust the .rvmrc file' and it calls a task in the deploy.rb file such as:
namespace :rvm do
task :trust_rvmrc do
run "rvm rvmrc trust #{release_path}"
end
end
After putting in these slight changes I was able to run cap production deploy which checked out the code; executed the asset pipeline deployment, linked up the release folder to current, executed bundle install and cleaned up.

Resources