apache / openwhisk

Apache OpenWhisk is an open source serverless cloud platform
https://openwhisk.apache.org/
Apache License 2.0
6.49k stars 1.16k forks source link

Vagrant setup failed to create symbolic link ‘wsk’ #1215

Closed pparkkin closed 8 years ago

pparkkin commented 8 years ago

Environment details:

Windows 7, Git Bash.

Vagrant 1.8.4.

Steps to reproduce the issue:

git clone git@github.com:openwhisk/openwhisk.git
cd openwhisk/
cd tools/vagrant/
./hello

Provide the expected results and outputs:

No error.

Provide the actual results and outputs:

==> default: ++ sed -i.bak 's/:\/bin/:\/bin:\/home\/vagrant\/openwhisk\/bin/g' /etc/environment
==> default: ++ echo ANSIBLE_REMOTE_TEMP=/home/vagrant/openwhisk/ansible/tmp
==> default: ++ rm -r bin/wsk
==> default: ++ rm -r bin/wskadmin
==> default: ++ cd bin
==> default: ++ sudo ln -s ../tools/cli/wsk wsk
==> default: ln: failed to create symbolic link ‘wsk’
==> default: : Protocol error
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
pparkkin commented 8 years ago

I think it's because the directory is synced with the host, and Windows doesn't allow you to create symbolic links.

My workaround was to create the links in ~/bin.

vagrant@vagrant-ubuntu-trusty-64:~$ ln -s ~/openwhisk/tools/cli/wsk ~/bin/
vagrant@vagrant-ubuntu-trusty-64:~$ ln -s ~/openwhisk/tools/cli/wskadmin ~/bin/

After that, going through the rest of the Vagrantfile, I still got the following error, but other than that, everything worked fine and I was able run the echo action at the end.

vagrant@vagrant-ubuntu-trusty-64:~/openwhisk$ chown -R vagrant:vagrant $HOME
chown: changing ownership of ‘/home/vagrant/.pip/pip.log’: Operation not permitted
chown: changing ownership of ‘/home/vagrant/.pip’: Operation not permitted
pparkkin commented 8 years ago

This Vagrantfile worked for me on Windows 7. I don't have a Linux or an OSX to try out right now, but the provisioning for those should be unchanged.

At the start I check whether we're Windows, and in the end I split the tool setup to be different based on that.


# -*- mode: ruby -*-
# vi: set ft=ruby :

# Custom OpenWhisk

# vagrant resume issue https://github.com/mitchellh/vagrant/issues/6787
# Don't use vagrant resume, it will run the provisioning a second producing errors
# Use vagrant suspend and vagrant up (using up it skips provisioning)

BOX = "ubuntu/trusty64-2"
BOX_URL =  "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
BOX_MEMORY = ENV['BOX_MEMORY'] || '4096'
BOX_CPUS = ENV['BOX_CPUS'] || '4'
MACHINE_IP = ENV['MACHINE_IP'] || '192.168.33.13'
OW_DB = if ENV['OW_DB'] =~ (/^(cloudant|couchdb)$/i) then true else false end

# Check whether we're on Windows or not.
require 'rbconfig'
IS_WINDOWS = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)

Vagrant.configure('2') do |config|
  config.vm.box = BOX
  config.vm.box_url = BOX_URL

  config.vm.network :private_network, ip: MACHINE_IP

  # If true, then any SSH connections made will enable agent forwarding.
  # Default value: false
  config.ssh.forward_agent = true

  config.vm.provider :virtualbox do |vb|
    vb.name = "whisk-" + Time.now.strftime("%y%m%d%H%M")
    vb.gui = ENV['gui'] || false
    vb.cpus = BOX_CPUS
    vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
    vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
    vb.customize ['modifyvm', :id, '--ostype', 'Ubuntu_64']
    vb.customize ['modifyvm', :id, '--memory', BOX_MEMORY]
  end

  # Shared root of repository; do not use symlinks
  config.vm.synced_folder '../../', '/home/vagrant/openwhisk'

  # Prevents "stdin: is not a tty" on Ubuntu (https://github.com/mitchellh/vagrant/issues/1673)
  config.vm.provision "fix-no-tty", type: "shell" do |s|
    s.privileged = false
    s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
  end

  # Install Software
$script_common = <<SCRIPT
  set -e
  set -x
  sudo add-apt-repository ppa:git-core/ppa
  sudo apt-get update
  sudo apt-get install git -y
  sudo apt-get install htop

  # Configure swapfile
  echo 'swapfile not found. Adding swapfile.'
  fallocate -l 8000M /swapfile
  chmod 600 /swapfile
  mkswap /swapfile
  swapon /swapfile
  echo '/swapfile none swap defaults 0 0' >> /etc/fstab

  cd /home/vagrant/openwhisk
  cd tools/ubuntu-setup
  su vagrant -c 'source all.sh'
SCRIPT

  config.vm.provision "script_common", type: "shell", keep_color: true, inline: $script_common

  # Configure Custom Database
$script_db = <<SCRIPT
export ANSIBLE_REMOTE_TEMP=/home/vagrant/openwhisk/ansible/tmp
export OW_DB=#{ENV['OW_DB']}
export OW_DB_USERNAME=#{ENV['OW_DB_USERNAME']}
export OW_DB_PASSWORD=#{ENV['OW_DB_PASSWORD']}
if [[ $OW_DB == "cloudant" ]]; then
  export OW_DB="Cloudant"
  export OW_DB_PROTOCOL="https"
  export OW_DB_HOST="$OW_DB_USERNAME.cloudant.com"
  export OW_DB_PORT="443"
else
  export OW_DB="CouchDB"
  export OW_DB_PROTOCOL=#{ENV['OW_DB_PROTOCOL']}
  export OW_DB_HOST=#{ENV['OW_DB_HOST']}
  export OW_DB_PORT=#{ENV['OW_DB_PORT']}
fi

cd /home/vagrant/openwhisk/ansible
su vagrant -c 'ansible-playbook -i environments/local setup.yml'
su vagrant -c 'ansible-playbook -i environments/local prereq.yml'
SCRIPT

  # Configure Default CouchDB
$couch_db = <<COUCH_DB
export ANSIBLE_REMOTE_TEMP=/home/vagrant/openwhisk/ansible/tmp
cd /home/vagrant/openwhisk/ansible
su vagrant -c 'ansible-playbook -i environments/local setup.yml'
su vagrant -c 'ansible-playbook -i environments/local prereq.yml'
su vagrant -c 'ansible-playbook -i environments/local couchdb.yml'
COUCH_DB

$init_db = <<INIT_DB
export ANSIBLE_REMOTE_TEMP=/home/vagrant/openwhisk/ansible/tmp
cd /home/vagrant/openwhisk/ansible
su vagrant -c 'ansible-playbook -i environments/local initdb.yml'
INIT_DB

  if OW_DB
    config.vm.provision "script_db", type: "shell", keep_color: true, inline: $script_db
  else
    config.vm.provision "start_couch", type: "shell", keep_color: true, inline: $couch_db
  end
  config.vm.provision "initdb", type: "shell", keep_color: true, inline: $init_db

  # Build and Deploy
$script_end = <<SCRIPT
  set -e
  set -x
  export ANSIBLE_REMOTE_TEMP=/home/vagrant/openwhisk/ansible/tmp
  cd /home/vagrant/openwhisk
  su vagrant -c './gradlew distDocker --parallel'
  cd ansible
  su vagrant -c 'ansible-playbook -i environments/local wipe.yml'
  su vagrant -c 'ansible-playbook -i environments/local openwhisk.yml'
  su vagrant -c 'ansible-playbook -i environments/local postdeploy.yml'
  cd ..
  # Add openwhisk/bin to system PATH to allow to work with vagrant ssh -- wsk
  sed -i.bak s/:\\\\/bin/:\\\\/bin:\\\\/home\\\\/vagrant\\\\/openwhisk\\\\/bin/g /etc/environment
  # Set remote tmp dir for ansible to fix shared folder problems on Windows
  echo "ANSIBLE_REMOTE_TEMP=$ANSIBLE_REMOTE_TEMP" >> /etc/environment
SCRIPT

$setup_tools = <<SCRIPT
  cd /home/vagrant/openwhisk
  rm -r bin/wsk && rm -r bin/wskadmin
  (cd bin && sudo ln -s ../tools/cli/wsk wsk)
  (cd bin && sudo ln -s ../tools/cli/wskadmin wskadmin)
  OPENWHISK_AUTH=`cat ansible/files/auth.guest`
  HOME=/home/vagrant
  # Adds openwhisk bins
  echo PATH='$PATH':$HOME/openwhisk/bin:$HOME/openwhisk/tools/build >> "$HOME/.bash_profile"
  # Adds tab completion
  echo 'eval "$(register-python-argcomplete wsk)"' >> "$HOME/.bash_profile"
  source "$HOME/.bash_profile"
  chown -R vagrant:vagrant $HOME
  # This allows user to see how to configure the wsk cli outside the VM
  wsk property set --apihost 192.168.33.13 --namespace guest --auth $OPENWHISK_AUTH
  wsk action invoke /whisk.system/samples/echo -p message hello --blocking --result
SCRIPT

$setup_tools_windows = <<SCRIPT
  cd /home/vagrant/openwhisk
  OPENWHISK_AUTH=`cat ansible/files/auth.guest`
  HOME=/home/vagrant
  if [ -f bin/wsk ]; then rm -r bin/wsk; fi
  if [ -f bin/wskadmin ]; then rm -r bin/wskadmin; fi
  mkdir -p "$HOME/bin"
  (cd $HOME/bin && sudo ln -s $HOME/openwhisk/tools/cli/wsk wsk)
  (cd $HOME/bin && sudo ln -s $HOME/openwhisk/tools/cli/wskadmin wskadmin)
  source "$HOME/.profile"
  # Adds openwhisk bins
  echo PATH='$PATH':$HOME/openwhisk/bin:$HOME/openwhisk/tools/build >> "$HOME/.bash_profile"
  # Adds tab completion
  echo 'eval "$(register-python-argcomplete wsk)"' >> "$HOME/.bash_profile"
  source "$HOME/.bash_profile"
  chown -R vagrant:vagrant $HOME || exit 0
  # This allows user to see how to configure the wsk cli outside the VM
  wsk property set --apihost 192.168.33.13 --namespace guest --auth $OPENWHISK_AUTH
  wsk action invoke /whisk.system/samples/echo -p message hello --blocking --result
SCRIPT

  config.vm.provision "script_end", type: "shell", keep_color: true, inline: $script_end
  if IS_WINDOWS
    config.vm.provision "setup_tools_windows", type: "shell", keep_color: true, inline: $setup_tools_windows
  else
    config.vm.provision "setup_tools", type: "shell", keep_color: true, inline: $setup_tools
  end

  if ENV['gui'] == 'true'
    # Install ubuntu-desktop and virtualbox additions
    config.vm.provision "shell", keep_color: true, inline: "apt-get update"
    config.vm.provision "shell", keep_color: true, inline: "apt-get install -y virtualbox-guest-dkms"
    config.vm.provision "shell", keep_color: true, inline: "apt-get install -y virtualbox-guest-utils"
    config.vm.provision "shell", keep_color: true, inline: "apt-get install -y virtualbox-guest-x11"
    config.vm.provision "shell", keep_color: true, inline: "sed -i 's/allowed_users=.*$/allowed_users=anybody/' /etc/X11/Xwrapper.config"
    #the ; true is used to ignore errors from ubuntu-desktop, vagrant reload should be done after provisioning
    config.vm.provision "shell", keep_color: true, inline: "sudo sh -c 'apt-get install -y ubuntu-desktop ; true'"
  end

end
pparkkin commented 8 years ago

Still missing an echo PATH='$PATH':$HOME/bin >> "$HOME/.bash_profile" from the Windows tool setup.

csantanapr commented 8 years ago

@pparkkin thanks for the report. we are transitioning out the python cli which was required to be located in $OPENWHISK_HOME/bin/wsk now with go-cli there is no need for that softlynk

We did some widows testing, and were able to create the softlynk on the shared folder from inside the VM, but it looks like it doesn't work in all windows or filesystems.