mina-deploy / mina

Blazing fast deployer and server automation tool
https://rubygems.org/gems/mina
Other
4.35k stars 490 forks source link

Mina console 'bash: bundle: command not found' #510

Closed thaichors3000 closed 7 years ago

thaichors3000 commented 7 years ago

mina console raise error bash: bundle: command not found

As I review source code, what mina console does is

  1. cd to current_path
  2. execute rails c

However, when we use rvm or rben, we need to load ruby version with gemset first.

molfar commented 7 years ago

I wrote the same issue https://github.com/mina-deploy/mina/issues/476

bindiry commented 7 years ago

I have the same issue.

hovancik commented 7 years ago

This works for me with rbenv:

task :environment do
  # If you're using rbenv, use this to load the rbenv environment.
  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
  invoke :'rbenv:load'

  # For those using RVM, use this to load an RVM version@gemset.
  # invoke :'rvm:use[ruby-1.9.3-p125@default]'
end

then

desc "Starts an interactive rails console."
task :c => :environment do
  invoke :'console'
end
bindiry commented 7 years ago

@hovancik Thank you, it is worked for me.

molfar commented 7 years ago

But how can it be fixed? To work just out of the box, without any hacks

d4be4st commented 7 years ago

please take a look at https://github.com/mina-deploy/mina/blob/master/docs/faq.md#--command-not-found-bundle

NicosKaralis commented 6 years ago

About this, I still have this problem

In my case is because I need to load rbenv first to then run bundle

$ mina console -s --trace
** Invoke console (first_time)
** Execute console
** Invoke debug_configuration_variables (first_time)
** Execute debug_configuration_variables
** Invoke run_commands (first_time)
** Execute run_commands
** Invoke environment (first_time)
** Execute environment
** Invoke rbenv:load (first_time)
** Execute rbenv:load
** Invoke nvm:load (first_time)
** Execute nvm:load
#!/usr/bin/env bash
# Executing the following via 'ssh deployer@165.227.180.208 -i config/deployment_key -p 22 -tt':
#
echo "-----> Loading rbenv"
export RBENV_ROOT="$HOME/.rbenv"
export PATH="$HOME/.rbenv/bin:$PATH"
if ! which rbenv >/dev/null; then
  echo "! rbenv not found"
  echo "! If rbenv is installed, check your :rbenv_path setting."
  exit 1
fi
eval "$(rbenv init -)"
echo "-----> Loading nvm"
[ -s "/home/deployer/.nvm/nvm.sh" ] && . "/home/deployer/.nvm/nvm.sh"
(cd /home/deployer/app/current && RAILS_ENV="production" bundle exec rails console && cd -)
echo "-----> Loading rbenv"
export RBENV_ROOT="$HOME/.rbenv"
export PATH="$HOME/.rbenv/bin:$PATH"
if ! which rbenv >/dev/null; then
  echo "! rbenv not found"
  echo "! If rbenv is installed, check your :rbenv_path setting."
  exit 1
fi
eval "$(rbenv init -)"
echo "-----> Loading nvm"
[ -s "/home/deployer/.nvm/nvm.sh" ] && . "/home/deployer/.nvm/nvm.sh"

       Elapsed time: 0.00 seconds

As you can see in the output above the environment task is called after the console. Also the rbenv:load task is called twice.

Currently I'm doing like this:

# This task is the environment that is loaded for all remote run commands, such as
# `mina deploy` or `mina rake`.
task :load_env do
  # If you're using rbenv, use this to load the rbenv environment.
  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
  invoke :'rbenv:load'
  invoke :'nvm:load'
end
task environment: :load_env
task console: :load_env

Is there a more practical way to fix this?

d4be4st commented 6 years ago

mina 1.1.0 introduced local_environment and remote_environment https://github.com/mina-deploy/mina/commit/972a26ce354e8031a0656c16783c02390c821e33

You can use that