Rails : Could not find jwt-1.5.3 in any of the sources

I have been using Capistrano for a long time for this project. This time when I tried to deploy my latest changes I stumbled upon this issue. So I documented this.

 

(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as user@mysite.com: bundle exit status: 7
bundle stdout: Could not find jwt-1.5.3 in any of the sources
bundle stderr: Regenerating ruby-2.2.1 wrappers........
Regenerating ruby-2.2.1 wrappers........
/usr/local/rvm/gems/ruby-2.2.1/gems/bundler-1.11.2/lib/bundler/vendor/thor/lib/thor/shell/basic.rb:356: warning: Insecure world writable dir /usr/local/rvm/gems/ruby-2.2.1/bin in PATH, mode 042777

SSHKit::Command::Failed: bundle exit status: 7
bundle stdout: Could not find jwt-1.5.3 in any of the sources
bundle stderr: Regenerating ruby-2.2.1 wrappers........
Regenerating ruby-2.2.1 wrappers........
/usr/local/rvm/gems/ruby-2.2.1/gems/bundler-1.11.2/lib/bundler/vendor/thor/lib/thor/shell/basic.rb:356: warning: Insecure world writable dir /usr/local/rvm/gems/ruby-2.2.1/bin in PATH, mode 042777

Tasks: TOP => deploy:updated => bundler:install
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deployer@45.79.200.151: bundle exit status: 7
bundle stdout: Could not find jwt-1.5.3 in any of the sources
bundle stderr: Regenerating ruby-2.2.1 wrappers........

 

The reason is:

https://rubygems.org/gems/jwt/versions/1.5.3

jwt 1.5.3 is yanked because of some reasons. So 1.5.3 version isn’t in repository..!

How to solve

Delete your Gemfile.lock and

$ bundle install

update your remote repo and deploy again

Sources:

http://stackoverflow.com/a/36219627/3437900

Advertisements

Unix : SSH server add new user’s ssh keys

You have not chosen to deploy your application to fancy web hosting services like Engineyard, Digitalocean, or Heroku then you might be willing to know how to give other developers collaborating in this project access to the server via SSH. In other words you want to let others to deploy the application via SSH (eg. Capistrano).

Well, its pretty much simpler than you have thought.  Follow the steps

  • Copy the public key of your colleague to clipboard ( Ctrl + C )
  • SSH into the server
  • If you want to use the same username for all developer (say `deployer`)
    • $ cd /home/deployer/.ssh
      $ sudo nano authorized_keys
    • Paste the SSH public key of your colleague at the end of the file
    • Save the file
    • And you are Done!
    • Now your colleague should have access to the server
  • If want a separate username for every individual
    • It would be great if you create separate user-group for deployment purposes like `deployers`
    • create a new user in that group with privileges you like
      • to give sudo access you need to update the sudoers file
      • The configuration file for sudo is /etc/sudoers
    • goto that particular user’s home directory
    • add his ssh public key to the /home/user/.ssh/authorized_keys file
      • the .ssh folder might not already be available, you can create though
      • $ mkdir /home/user/.ssh
      • copy the content using `nano or echo`  into the file
    • Now you are Done!

 

Rails : Spree in production [Deface stuffs]

Spree In production

You need to take these things into consideration while deploying your spree app to production. Like, the login button/link might not appear even when your app is up and running. Or may appear twice.

Deface supports precompiling where all overrides are loaded and applied to the original views and the resulting templates are then saved to your application’s app/compiled_views directory. To precompile run:

 $ bundle exec rake deface:precompile

It’s important to disable Deface once precompiling is used to prevent overrides getting applied twice. To disable add the following line to your application’s production.rb file:

config.deface.enabled = false

Additionally,

After every deploy to production you will face this issue and you manually have to recompile the overrides. Its so cumbersome and annoying to do it every time. So I would prefer to make a Capistrano recipe and inject it to the deployment workflow.

There are two ways to execute the recipe

  • You can re-compile every time
  • You can once recompile in `shared` folder and symlink every time. You can invoke the task if there is change in the overrides.

 

namespace :deface do
  task :precompile do
    SSHKit.config.command_map[:rake] = "./bin/rake"

    on roles(:web) do
      set :current_path, "#{fetch(:deploy_to)}/current/"
      within fetch(:current_path) do
        with rails_env: fetch(:rails_env) do
          execute :rake, 'deface:precompile'
        end
      end
    end
  end
end

# in deploy.rb
before 'deploy:restart', 'deface:precompile'

NOTE: You can also use precompiling in development mode. Make sure you restart the application server every time you precompile the overrides.

Capistrano 3 : Invoke one custom made task from another task

In previous versions, it was like normal ruby of JavaScript function call

You can do it by using namespace:

namespace :test do
  task :one do
  end
  task :two do
    test.one
    # or just directly call it:
    one
  end
end

Just be careful with the name you use to not overwrite some important function.
Continue reading