Search code examples
ruby-on-railsrubyrvmmina

I can't deploy my rails app via mina deploy


I'm trying deploy a Rails App (5.2.0 and Ruby 2.4.0) to a server (Ubuntu 16.04.2 LTS) via mina deploy. I already configured my files to deploy, but when I try run mina deploy, I get the error: bash: line 145: bundle: command not found. Like this:

mina deploy
-----> Creating a temporary build path
-----> Using RVM environment "ruby-2.4.0@marconPortfolio"
       Using /usr/local/rvm/gems/ruby-2.4.0 with gemset marconPortfolio
-----> Deploying marconPortfolio to 165.227.63.110:/home/rails/marcon
-----> Fetching new git commits
       remote: Counting objects: 8, done.
remote: Compressing objects: 100% (8/8), done.
       remote: Total 8 (delta 6), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.   
       From bitbucket.org:felipeemarcon/marcon-portfolio
          6113173..1f02042  master     -> master
-----> Using git branch 'master'
       Cloning into '.'...
       done.
-----> Using this git commit
       Felipe Marcon (1f02042):
       > Rvm path in deploy
-----> Symlinking shared paths
-----> Installing gem dependencies using Bundler
       bash: line 145: bundle: command not found
 !     ERROR: Deploy failed.
-----> Cleaning up build
       Unlinking current
       OK
       Connection to 165.227.63.110 closed.

 !     Run Error

I've already search in to many places how fix this, but nothing helped. How can i solve this?

I already run "gem install bundle" in my server and when I run "bundle --version" it returns the version of bundler, so it's installed. The ruby version in my server is the same that I have in local (ruby 2.4.0). I don't know what to do to solve this. Anyone can help me?

Oh, if that's relevant, I'm using Puma as the app server.

deploy.rb

require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'
require 'mina/puma'

set :domain, '165.227.63.110'

set :deploy_to, '/home/rails/marcon'

set :repository, '[email protected]:felipeemarcon/marcon-portfolio.git'

set :branch, 'master'

set :shared_dirs, fetch(:shared_dirs, []).push('log', 'tmp/pids', 'tmp/sockets', 'public/uploads')
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml', 'config/puma.rb')

set :user, 'root'

set :application_name, 'marconPortfolio'
set :ssh_flags, '-l root'
set :rvm_use_path, '/usr/local/rvm/scripts/rvm'


task :remote_environment do
  invoke :'rvm:use', 'ruby-2.4.0@marconPortfolio'
end

task :setup do
  command %[touch "#{fetch(:shared_path)}/config/database.yml"]
  command %[touch "#{fetch(:shared_path)}/config/secrets.yml"]
  command %[touch "#{fetch(:shared_path)}/config/puma.rb"]
  comment "Be sure to edit '#{fetch(:shared_path)}/config/database.yml', 'secrets.yml' and puma.rb."
end

task :deploy do
  deploy do
    comment "Deploying #{fetch(:application_name)} to #{fetch(:domain)}:#{fetch(:deploy_to)}"
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    # invoke :'rvm:load_env_vars'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    command %{#{fetch(:rails)} db:seed}
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    on :launch do
      command "export RAILS_ENV=production"
      invoke :'puma:phased_restart'
      command '/etc/init.d/nginx restart'
      command 'rm -f /home/rails/marcon/current/public/system/'
      command "ln -s /home/rails/marcon/current/public/"
    end
  end
end

puma.rb:

threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count

port        ENV.fetch("PORT") { 3000 }

environment ENV.fetch("RAILS_ENV") { "development" }

plugin :tmp_restart

bind "unix:/home/rails/marcon/shared/tmp/sockets/puma.sock" if ENV.fetch("RAILS_ENV") == 'production'

Thanks.


Solution

  • I got solve this problem. I clone my project directly to my server, install the dependencies and after, I runed mina deploy from my local machine. Now everything works fine.

    But I still guess that should not work like this. I should not be able to deploy my application in the first time by mina deploy in the server?

    Thank you all.