Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

can't set rvm_path in 1.x #414

Closed
devvmh opened this issue Aug 10, 2016 · 5 comments
Closed

can't set rvm_path in 1.x #414

devvmh opened this issue Aug 10, 2016 · 5 comments
Labels

Comments

@devvmh
Copy link
Contributor

devvmh commented Aug 10, 2016

I'm having a mind bending issue while testing a fork of mina-sidekiq. In their test_env file, I've added

require 'mina/rvm'

I'm using the 1.0.0.beta2 version of mina, and I can verify which code is running by adding puts statements in the gem code on my machine.

No matter where I put my call to set :rvm_path, '$HOME/.rvm/scripts/rvm', it continually returns me a value of /Users/devin/.rvm, which is an invalid rvm path. I've set it in the task, I've set it in config/deploy.rb, I've set it in the mina 1.0.0.beta2 local code, and I've even set it inside the code for rvm:use. I literally wrote this code and it still happened:

set :rvm_path, '$HOME/.rvm/scripts/rvm'

task :'rvm:use', :env do |_, args|
  comment "CHECK IT OUT"
  comment fetch(:rvm_path)
  set :rvm_path, '$HOME/.rvm/scripts/rvm'
  comment fetch(:rvm_path)

  # ... rest of rvm:use
end

Hacking the local mina code again and changing it use a variable :rvm_cool instead of :rvm_path resolves the issue. I'm at a loss as to why.

Seeing as it does resolve the issue, though, I'm wondering if you guys have thoughts of how to fix this, and/or would like a pull request changing the rvm_path variable name. Let me know.

@devvmh devvmh changed the title can't set rvm_path can't set rvm_path in 1.x Aug 10, 2016
@d4be4st
Copy link
Member

d4be4st commented Aug 27, 2016

@devvmh how are you invoking the rvm:set ?

Also can you output your deploy --simulate ?

@devvmh
Copy link
Contributor Author

devvmh commented Aug 29, 2016

ok here's the details.

Using the latest mina 1.0.0.beta4 fails. Using my branch (master...devvmh-forks:fix/rvm-path) succeeds. Here's the output I get when it fails:

-----> Using RVM environment "ruby-2.3.0"
       $ if [[ ! -s "/Users/devin/.rvm" ]]; then
             echo "! Ruby Version Manager not found"
             echo "! If RVM is installed, check your :rvm_path setting."
             exit 1
           fi
       $ source /Users/devin/.rvm
       bash: line 12: source: /Users/devin/.rvm: is a directory

And here's the output of mina deploy --simulate. Note that this situation is a little strange, because I'm running the tests for mina-sidekiq so I'm sshing from localhost to localhost:

$ bundle exec mina --verbose deploy --simulate
#!/usr/bin/env bash
# Executing the following via 'ssh localhost -o StrictHostKeyChecking=no -tt':
#

#!/usr/bin/env bash

# Go to the deploy path
cd "/Users/devin/git/forks/mina-sidekiq/test_env/deploy" || (
  echo "! ERROR: not set up."
  echo "The path '/Users/devin/git/forks/mina-sidekiq/test_env/deploy' is not accessible on the server."
  echo "You may need to run 'mina setup' first."
  false
) || exit 15

# Check releases path
if [ ! -d "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/releases" ]; then
  echo "! ERROR: not set up."
  echo "The directory '/Users/devin/git/forks/mina-sidekiq/test_env/deploy/releases' does not exist on the server."
  echo "You may need to run 'mina setup' first."
  exit 16
fi

# Check lockfile
if [ -e "deploy.lock" ]; then
  echo "! ERROR: another deployment is ongoing."
  echo "The file 'deploy.lock' was found."
  echo "If no other deployment is ongoing, run 'mina deploy:force_unlock' to delete the file."
  exit 17
fi

# Determine $previous_path and other variables
[ -h "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current" ] && [ -d "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current" ] && previous_path=$(cd "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current" >/dev/null && pwd -LP)
build_path="./tmp/build-$(date +%s)$RANDOM"

version="$((`ls -1 /Users/devin/git/forks/mina-sidekiq/test_env/deploy/releases | sort -n | tail -n 1`+1))"
release_path="/Users/devin/git/forks/mina-sidekiq/test_env/deploy/releases/$version"

# Sanity check
if [ -e "$build_path" ]; then
  echo "! ERROR: Path already exists."
  exit 18
fi

# Bootstrap script (in deployer)
(
  echo "-----> Creating a temporary build path"
  echo \$\ touch\ \"deploy.lock\" &&
touch "deploy.lock" &&
  echo \$\ mkdir\ -p\ \"\$build_path\" &&
mkdir -p "$build_path" &&
  echo \$\ cd\ \"\$build_path\" &&
cd "$build_path" &&
  (
    if [ ! -d "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/scm/objects" ]; then
              echo "-----> Cloning the Git repository"
              echo \$\ git\ clone\ \"https://github.com/Mic92/mina-sidekiq-test-rails.git\"\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/scm\"\ --bare &&
    git clone "https://github.com/Mic92/mina-sidekiq-test-rails.git" "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/scm" --bare
            else
              echo "-----> Fetching new git commits"
              echo \$\ \(cd\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/scm\"\ \&\&\ git\ fetch\ \"https://github.com/Mic92/mina-sidekiq-test-rails.git\"\ \"master:master\"\ --force\) &&
    (cd "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/scm" && git fetch "https://github.com/Mic92/mina-sidekiq-test-rails.git" "master:master" --force)
            fi &&
            echo "-----> Using git branch 'master'" &&
            echo \$\ git\ clone\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/scm\"\ .\ --recursive\ --branch\ \"master\" &&
    git clone "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/scm" . --recursive --branch "master" &&
    echo "-----> Using this git commit" &&
    echo \$\ git\ rev-parse\ HEAD\ \>\ .mina_git_revision &&
    git rev-parse HEAD > .mina_git_revision &&
    echo \$\ git\ --no-pager\ log\ --format\=\"\%aN\ \(\%h\):\%n\>\ \%s\"\ -n\ 1 &&
    git --no-pager log --format="%aN (%h):%n> %s" -n 1 &&
    echo \$\ rm\ -rf\ .git &&
    rm -rf .git &&
    echo "-----> Symlinking shared paths" &&
    echo \$\ mkdir\ -p\ ./vendor &&
    mkdir -p ./vendor &&
    echo \$\ rm\ -rf\ \"./vendor/bundle\" &&
    rm -rf "./vendor/bundle" &&
    echo \$\ ln\ -s\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/vendor/bundle\"\ \"./vendor/bundle\" &&
    ln -s "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/vendor/bundle" "./vendor/bundle" &&
    echo \$\ mkdir\ -p\ . &&
    mkdir -p . &&
    echo \$\ rm\ -rf\ \"./log\" &&
    rm -rf "./log" &&
    echo \$\ ln\ -s\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/log\"\ \"./log\" &&
    ln -s "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/log" "./log" &&
    echo \$\ mkdir\ -p\ ./tmp &&
    mkdir -p ./tmp &&
    echo \$\ rm\ -rf\ \"./tmp/cache\" &&
    rm -rf "./tmp/cache" &&
    echo \$\ ln\ -s\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/tmp/cache\"\ \"./tmp/cache\" &&
    ln -s "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/tmp/cache" "./tmp/cache" &&
    echo \$\ mkdir\ -p\ ./public &&
    mkdir -p ./public &&
    echo \$\ rm\ -rf\ \"./public/assets\" &&
    rm -rf "./public/assets" &&
    echo \$\ ln\ -s\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/public/assets\"\ \"./public/assets\" &&
    ln -s "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/public/assets" "./public/assets" &&
    echo \$\ mkdir\ -p\ . &&
    mkdir -p . &&
    echo \$\ rm\ -rf\ \"./log\" &&
    rm -rf "./log" &&
    echo \$\ ln\ -s\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/log\"\ \"./log\" &&
    ln -s "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/log" "./log" &&
    echo "-----> Installing gem dependencies using Bundler" &&
    echo \$\ bundle\ install\ --without\ development\ test\ --path\ \"vendor/bundle\"\ --deployment &&
    bundle install --without development test --path "vendor/bundle" --deployment
  ) &&
  echo "-----> Deploy finished"
) &&

#
# Build
(
  echo "-----> Building"
  echo "-----> Moving build to $release_path"
  echo \$\ mv\ \"\$build_path\"\ \"\$release_path\" &&
mv "$build_path" "$release_path" &&
  echo \$\ cd\ \"\$release_path\" &&
cd "$release_path" &&
  (
  true
  ) &&
  echo "-----> Build finished"

) &&

#
# Launching
# Rename to the real release path, then symlink 'current'
(
  echo "-----> Launching"
  echo "-----> Updating the /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current symlink" &&
  echo \$\ ln\ -nfs\ \"\$release_path\"\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current\" &&
ln -nfs "$release_path" "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current"
) &&

# ============================
# === Start up server => (in deployer)
(
  echo \$\ cd\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current\" &&
cd "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current"
    echo "-----> Start sidekiq" &&
    (cd /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current && echo "$ cd /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current" && echo \$\ bundle\ exec\ sidekiq\ -d\ -e\ production\ \ -C\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current/config/sidekiq.yml\ -i\ 0\ -P\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid\ -L\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current/log/sidekiq.log &&
    bundle exec sidekiq -d -e production  -C /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current/config/sidekiq.yml -i 0 -P /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid -L /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current/log/sidekiq.log) &&
    (cd /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current && echo "$ cd /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current" && echo \$\ bundle\ exec\ sidekiq\ -d\ -e\ production\ \ -C\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current/config/sidekiq.yml\ -i\ 1\ -P\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1\ -L\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current/log/sidekiq.log &&
    bundle exec sidekiq -d -e production  -C /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current/config/sidekiq.yml -i 1 -P /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1 -L /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current/log/sidekiq.log) &&
    echo \$\ sleep\ 3\;\ kill\ -0\ \`cat\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid\` &&
    sleep 3; kill -0 `cat /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid` &&
    echo "-----> Quiet sidekiq (stop accepting new work)" &&
    echo \$\ \ \\'
    '\ \ \ \ \ \ \ \ if\ \[\ -f\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid\ \]\ \&\&\ kill\ -0\ \`cat\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid\`\ \>\ /dev/null\ 2\>\&1\;\ then'
    '\ \ \ \ \ \ \ \ \ \ cd\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current\"'
    '\ \ \ \ \ \ \ \ \ \ RAILS_ENV\=\"production\"\ bundle\ exec\ sidekiqctl\ quiet\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid'
    '\ \ \ \ \ \ \ \ else'
    '\ \ \ \ \ \ \ \ \ \ echo\ \'Skip\ quiet\ command\ \(no\ pid\ file\ found\)\''
    '\ \ \ \ \ \ \ \ fi\ \\'
    '\ \ \ \ \ \  &&
     \
            if [ -f /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid ] && kill -0 `cat /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid` > /dev/null 2>&1; then
              cd "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current"
              RAILS_ENV="production" bundle exec sidekiqctl quiet /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid
            else
              echo 'Skip quiet command (no pid file found)'
            fi \
           &&
    echo \$\ \ \\'
    '\ \ \ \ \ \ \ \ if\ \[\ -f\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1\ \]\ \&\&\ kill\ -0\ \`cat\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1\`\ \>\ /dev/null\ 2\>\&1\;\ then'
    '\ \ \ \ \ \ \ \ \ \ cd\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current\"'
    '\ \ \ \ \ \ \ \ \ \ RAILS_ENV\=\"production\"\ bundle\ exec\ sidekiqctl\ quiet\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1'
    '\ \ \ \ \ \ \ \ else'
    '\ \ \ \ \ \ \ \ \ \ echo\ \'Skip\ quiet\ command\ \(no\ pid\ file\ found\)\''
    '\ \ \ \ \ \ \ \ fi\ \\'
    '\ \ \ \ \ \  &&
     \
            if [ -f /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1 ] && kill -0 `cat /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1` > /dev/null 2>&1; then
              cd "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current"
              RAILS_ENV="production" bundle exec sidekiqctl quiet /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1
            else
              echo 'Skip quiet command (no pid file found)'
            fi \
           &&
    echo "-----> Stop sidekiq" &&
    echo \$\ \ \\'
    '\ \ \ \ \ \ \ \ if\ \[\ -f\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid\ \]\ \&\&\ kill\ -0\ \`cat\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid\`\>\ /dev/null\ 2\>\&1\;\ then'
    '\ \ \ \ \ \ \ \ \ \ cd\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current'
    '\ \ \ \ \ \ \ \ \ \ RAILS_ENV\=\"production\"\ bundle\ exec\ sidekiqctl\ stop\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid\ 11'
    '\ \ \ \ \ \ \ \ else'
    '\ \ \ \ \ \ \ \ \ \ echo\ \'Skip\ stopping\ sidekiq\ \(no\ pid\ file\ found\)\''
    '\ \ \ \ \ \ \ \ fi\ \\'
    '\ \ \ \ \ \  &&
     \
            if [ -f /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid ] && kill -0 `cat /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid`> /dev/null 2>&1; then
              cd /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current
              RAILS_ENV="production" bundle exec sidekiqctl stop /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid 11
            else
              echo 'Skip stopping sidekiq (no pid file found)'
            fi \
           &&
    echo \$\ \ \\'
    '\ \ \ \ \ \ \ \ if\ \[\ -f\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1\ \]\ \&\&\ kill\ -0\ \`cat\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1\`\>\ /dev/null\ 2\>\&1\;\ then'
    '\ \ \ \ \ \ \ \ \ \ cd\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current'
    '\ \ \ \ \ \ \ \ \ \ RAILS_ENV\=\"production\"\ bundle\ exec\ sidekiqctl\ stop\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1\ 11'
    '\ \ \ \ \ \ \ \ else'
    '\ \ \ \ \ \ \ \ \ \ echo\ \'Skip\ stopping\ sidekiq\ \(no\ pid\ file\ found\)\''
    '\ \ \ \ \ \ \ \ fi\ \\'
    '\ \ \ \ \ \  &&
     \
            if [ -f /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1 ] && kill -0 `cat /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1`> /dev/null 2>&1; then
              cd /Users/devin/git/forks/mina-sidekiq/test_env/deploy/current
              RAILS_ENV="production" bundle exec sidekiqctl stop /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid-1 11
            else
              echo 'Skip stopping sidekiq (no pid file found)'
            fi \
           &&
    echo \$\ \(kill\ -0\ \`cat\ /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid\`\)\ 2\>\ /dev/null\ \&\&\ exit\ 1\ \|\|\ exit\ 0 &&
    (kill -0 `cat /Users/devin/git/forks/mina-sidekiq/test_env/deploy/shared/pids/sidekiq.pid`) 2> /dev/null && exit 1 || exit 0
) &&

# ============================
# === Complete & unlock
(
  rm -f "deploy.lock"
  echo "-----> Done. Deployed version $version"
) ||

# ============================
# === Failed deployment
(
  echo "! ERROR: Deploy failed."



  echo "-----> Cleaning up build"
  [ -e "$build_path" ] && (
    echo \$\ rm\ -rf\ \"\$build_path\" &&
rm -rf "$build_path"
  )
  [ -e "$release_path" ] && (
    echo "Deleting release"
    echo \$\ rm\ -rf\ \"\$release_path\" &&
rm -rf "$release_path"
  )
  (
    echo "Unlinking current"
    [ -n "$previous_path" ] && echo \$\ ln\ -nfs\ \"\$previous_path\"\ \"/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current\" &&
ln -nfs "$previous_path" "/Users/devin/git/forks/mina-sidekiq/test_env/deploy/current"
  )

  # Unlock
  echo \$\ rm\ -f\ \"deploy.lock\" &&
rm -f "deploy.lock"
  echo "OK"
  exit 19
)


       Elapsed time: 0.00 seconds

@devvmh
Copy link
Contributor Author

devvmh commented Sep 18, 2016

😓 I found it!

I use rvm on my local machine, and it sets a bash environment variable called $rvm_path to be "$HOME/.rvm". This seems to conflict with mina's :rvm_path variable, because of this line in the fetch function: https://github.com/mina-deploy/mina/blob/master/lib/mina/configuration.rb#L27

I can see a few possible solutions:

  1. Have me explicitly clear the ENV variable when calling mina: rvm_path= mina deploy This is probably a bad thing
  2. Change the name of the rvm_path variable. Not ideal.
  3. Set ENV values when calling set, so that set and fetch are more interrelated. This allows set to override pre-existing ENV variables. Also not ideal... but I think I lean this way for elegance and predictability
  4. Favour set values over ENV values when using fetch, so that calling set overrides the ENV. This is sort of a variant of 3 but perhaps the best one because it doesn't mangle ENV (not that it's likely to cause any problems...)

Is there a favoured way to go? I can set up a PR for this.

devvmh added a commit to devvmh-forks/mina that referenced this issue Sep 18, 2016
Old precedence was to favour ENV[key], then variables[key], then the
default passed to fetch

New precedence is variables[key], then default, then ENV[key]

This fixes mina-deploy#414, in which rvm_path is overridden by the $rvm_path bash
environment variable
devvmh added a commit to devvmh-forks/mina that referenced this issue Sep 18, 2016
Old precedence was to favour ENV[key], then variables[key], then the
default passed to fetch

New precedence is variables[key], then default, then ENV[key]

This fixes mina-deploy#414, in which rvm_path is overridden by the $rvm_path bash
environment variable
@d4be4st
Copy link
Member

d4be4st commented Sep 18, 2016

I see.

i would rather leave it as env first because this way you can change settings from the command line.

RVM is a bit of a specific situation. Usually environment variables are all UPCASE. Maybe the best solution would be to change the setting key to something diferent thant rvm_path

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants