neillturner / kitchen-verifier-serverspec

A Test Kitchen Serverspec Verifer without having to transit the Busser layer
Other
39 stars 19 forks source link

kitchen verify fails when using ubuntu/debian docker images with rvm #2

Closed milky-milk closed 8 years ago

milky-milk commented 8 years ago

Hello!

I'm trying to use custom Ubuntu and Debian Docker images with installed rvm (ruby 2.3) for kitchen user :

USER kitchen
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 \
    && /bin/bash -l -c "curl -L get.rvm.io | bash -s stable" \
    && /bin/bash -l -c "rvm install 2.3" \
    && /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc" \
    && /bin/bash -l -c "gem install bundler --no-ri --no-rdoc" \
    && /bin/bash -l -c "gem install serverspec" \
    && /bin/bash -l -c "gem install rake" \
    && /bin/bash -l -c "gem install ansible_spec" \
    && echo 'source $HOME/.rvm/scripts/rvm' >> $HOME/.bashrc

When I'm trying to run kitchen verify it fails: http://upaste.me/32cc24597e5f5086a

However, rspec is installed and exist: http://upaste.me/d86824598be0de65c And I can run test manually:

kitchen@2f92a59ec673:/tmp/kitchen$ rspec -c -f documentation --default-path  /tmp/kitchen  -P roles/common/spec/common_spec.rb

Package "curl" 
  should be installed

Finished in 0.07897 seconds (files took 0.9562 seconds to load)

It seems like verifier don't use user's $PATH or ignoring ~/.bashrc settings? I've tried to use rspec_path setting in kitchen.yml but kitchen verify fails with error: /usr/bin/env: ruby_executable_hooks: No such file or directory There is the full output: http://upaste.me/8217245999e0fd72e

My kitchen.yml http://upaste.me/db0d246015ada65c2

What is intresting: same setup with CentOS-6.7 and rvm in Docker works fine when I run kitchen verify.

Cant you please tell me where I am wrong? Is it possible to use serverspec verifier with rvm?

milky-milk commented 8 years ago

I tried to add some debug to gem:

      def serverspec_commands
        if config[:remote_exec]
          if config[:serverspec_command]
            <<-INSTALL
            #{config[:serverspec_command]}
            INSTALL
          else
            <<-INSTALL
            whoami
            echo $PATH

            if [ -d #{config[:default_path]} ]; then
              cd #{config[:default_path]}
              #{rspec_commands}
              #{remove_default_path}
            else

              echo "ERROR: Default path '#{config[:default_path]}' does not exist" 
              exit 1
            fi
            INSTALL
          end

and got the output:

D      [SSH] kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32810, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/tmp/ansible/base-project/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :password=>"kitchen"}> (      whoami
#       source $HOME/.rvm/scripts/rvm
        echo $PATH

            if [ -d /tmp/kitchen ]; then
              cd /tmp/kitchen
               rspec -c -f documentation --default-path  /tmp/kitchen  -P roles/common/spec/common_spec.rb

            else

              echo "ERROR: Default path '/tmp/kitchen' does not exist"
              exit 1
            fi
)
D      [SSH] opening connection to kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32810, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/tmp/ansible/base-project/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :password=>"kitchen"}>
       kitchen
       /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
       bash: line 6: rspec: command not found
D      Cleaning up local sandbox in /tmp/Common-ubuntu-1404-sandbox-20160331-10489-1utyylz

It seems that verifier ignoring user's $PATH ?

When I tried to add source $HOME/.rvm/scripts/rvm to gem:

      def serverspec_commands
        if config[:remote_exec]
          if config[:serverspec_command]
            <<-INSTALL
            #{config[:serverspec_command]}
            INSTALL
          else
            <<-INSTALL
            whoami
            source $HOME/.rvm/scripts/rvm
            echo $PATH

            if [ -d #{config[:default_path]} ]; then
              cd #{config[:default_path]}
              #{rspec_commands}
              #{remove_default_path}
            else

              echo "ERROR: Default path '#{config[:default_path]}' does not exist" 
              exit 1
            fi
            INSTALL
          end

kitchen verify works fine.

neillturner commented 8 years ago

yes i have not got it working with different flavours of rubylike rvm yet. thanks for pointing this out. next thing to fix. -)

you can set the serverspec_command parameter to have the command plus the extra command in front source $HOME/.rvm/scripts/rvm you can set Multiple lines, a.k.a embed shell script like the custom_install_command option. I suggest we add 2 parameters for rvm require_rvm true/false default false and rvm_command defaults to source $HOME/.rvm/scripts/rvm

the other thing you can do is run the serverspec locally on your workstation. remote_exec: false then configure to run on the docker image. then you dn't need al the rvm stuff as ruby will be on your workstation.

milky-milk commented 8 years ago

you can set the serverspec_command parameter to have the command plus the extra command in front source $HOME/.rvm/scripts/rvm

Thanks! It works.

I suggest we add 2 parameters for rvm require_rvm true/false default false and rvm_command defaults to source $HOME/.rvm/scripts/rvm

It would be great.

neillturner commented 8 years ago

probably a more generic solution is to add a parameter additional_serverspec_command that runs in addition to the commands

neillturner commented 8 years ago

added additional install and serverspec command options in version 0.4.0 closing