All Projects → p0deje → Vagrant Exec

p0deje / Vagrant Exec

Licence: mit
Execute commands in Vagrant synced folder

Projects that are alternatives of or similar to Vagrant Exec

Ript
Ript provides a clean Ruby DSL for describing firewall rules, and implements database migrations-like functionality for applying the rules
Stars: ✭ 113 (-20.98%)
Mutual labels:  gherkin
Vagrant Butcher
Delete Chef client and node when destroying Vagrant VM
Stars: ✭ 127 (-11.19%)
Mutual labels:  vagrant
Sdkman For Fish
Adds support for SDKMAN! to fish
Stars: ✭ 139 (-2.8%)
Mutual labels:  gherkin
Servicecontainerextension
📻 Allows to declare own services inside Behat container without writing an extension.
Stars: ✭ 114 (-20.28%)
Mutual labels:  gherkin
Xunit.gherkin.quick
BDD in .NET Core - using Xunit and Gherkin (compatible with both .NET Core and .NET)
Stars: ✭ 123 (-13.99%)
Mutual labels:  gherkin
Vagrant Elastic Stack
Giving the Elastic Stack a try in Vagrant
Stars: ✭ 131 (-8.39%)
Mutual labels:  vagrant
Vermin
The smart virtual machines manager. A modern CLI for Vagrant Boxes.
Stars: ✭ 110 (-23.08%)
Mutual labels:  vagrant
Spectrum
A BDD-style test runner for Java 8. Inspired by Jasmine, RSpec, and Cucumber.
Stars: ✭ 142 (-0.7%)
Mutual labels:  gherkin
Cakebox
Framework agnostic virtual PHP Development Environment
Stars: ✭ 127 (-11.19%)
Mutual labels:  vagrant
Specflow
#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
Stars: ✭ 1,827 (+1177.62%)
Mutual labels:  gherkin
Rspec Json expectations
Set of matchers and helpers to allow you test your APIs responses like a pro.
Stars: ✭ 115 (-19.58%)
Mutual labels:  gherkin
Packer Windoze
Packer templates to create Windows vagrant box images
Stars: ✭ 117 (-18.18%)
Mutual labels:  vagrant
Vagrant Lamp Bootstrap
A super-simple Vagrantfile / bootstrap.sh to setup a LAMP stack inside Vagrant 100% automatically
Stars: ✭ 132 (-7.69%)
Mutual labels:  vagrant
Microservice App
A microservices architecture app powered by golang.
Stars: ✭ 114 (-20.28%)
Mutual labels:  vagrant
K8s Vagrant Multi Node
A Kubernetes Vagrant Multi node environment using kubeadm.
Stars: ✭ 141 (-1.4%)
Mutual labels:  vagrant
Vagrant Php7
A simple Vagrant LAMP setup with PHP 7.1 running on Ubuntu 16.04 LTS
Stars: ✭ 112 (-21.68%)
Mutual labels:  vagrant
Kubernetes Vagrant Centos Cluster
Setting up a distributed Kubernetes cluster along with Istio service mesh locally with Vagrant and VirtualBox, only PoC or Demo use.
Stars: ✭ 1,750 (+1123.78%)
Mutual labels:  vagrant
Joomlatools Vagrant
Vagrant box for Joomla development.
Stars: ✭ 142 (-0.7%)
Mutual labels:  vagrant
Forklift
Helpful deployment scripts for Foreman and Katello
Stars: ✭ 141 (-1.4%)
Mutual labels:  vagrant
Multi Streaming Server
A NGINX server with RTMP module to send video streaming to multiple services simultaneously (Youtube, Twitch, Dailymotion, Hitbox, Beam, etc...).
Stars: ✭ 132 (-7.69%)
Mutual labels:  vagrant

vagrant-exec Gem Version

Vagrant plugin to execute commands within the context of VM synced directory.

Description

You will probably use the plugin if you don't want to SSH into the box to execute commands simply because your machine environment is already configured (e.g. I use ZSH and TextMate bundles to run specs/features).

Installation

➜ vagrant plugin install vagrant-exec

Example

➜ vagrant exec pwd
/vagrant

Configuration

vagrant-exec has only one configuration option for Vagrantfile, which allows you to alter the behavior of all or specific commands.

Vagrant.configure('2') do |config|
  config.vm.box = 'precise32'
  config.exec.commands '*', directory: '/tmp'
end

Commands can either be:

  • "*" (wildcard) - apply options to all the commands
  • "command" (string) - apply options for specific commands
  • %w(command1 command2) (array) - apply options to all commands in array

Configuration options are merged, so if you specify single command in several places, all the option will be applied. The only exception is :directory, which is applied only once and in reverse order (i.e. the last set is used).

Directory

Vagrant.configure('2') do |config|
  config.vm.box = 'precise32'

  # Make /tmp working directory for all the commands:
  #   ➜ vagrant exec pwd
  #   # is the same as
  #   ➜ vagrant ssh -c "cd /tmp && pwd"
  config.exec.commands '*', directory: '/tmp'

  # Make /etc working directory for env command:
  #   ➜ vagrant exec env
  #   # is the same as
  #   ➜ vagrant ssh -c "cd /etc && env"
  config.exec.commands 'env', directory: '/etc'
end

Prepend

Vagrant.configure('2') do |config|
  config.vm.box = 'precise32'

  # Automatically prepend apt-get command with sudo:
  #   ➜ vagrant exec apt-get install htop
  #   # is the same as
  #   ➜ vagrant ssh -c "cd /vagrant && sudo apt-get install htop"
  config.exec.commands 'apt-get', prepend: 'sudo'

  # Automatically prepend rails and rspec commands with bundle exec:
  #   ➜ vagrant exec rails c
  #   # is the same as
  #   ➜ vagrant ssh -c "cd /vagrant && bundle exec rails c"
  #
  #   ➜ vagrant exec rspec spec/
  #   # is the same as
  #   ➜ vagrant ssh -c "cd /vagrant && bundle exec rspec spec/"
  config.exec.commands %w[rails rspec], prepend: 'bundle exec'
end

Environment variables

Vagrant.configure('2') do |config|
  config.vm.box = 'precise32'

  # Automatically export environment variables for ruby command:
  #   ➜ vagrant exec ruby -e 'puts 1'
  #   # is the same as
  #   ➜ vagrant ssh -c "cd /vagrant && export RUBY_GC_MALLOC_LIMIT=100000000 && ruby -e 'puts 1'"
  config.exec.commands 'ruby', env: {'RUBY_GC_MALLOC_LIMIT' => 100000000}
end

Binstubs

It is possible to generate binstubs for all your configured commands. You might want to do this to avoid typing vagrant exec every time before command, or if you want integrate your flow in editor (e.g. running tests from editor).

Assuming you have the following configuration:

Vagrant.configure('2') do |config|
  config.vm.box = 'precise32'
  config.exec.commands 'bundle'
  config.exec.commands %w[rails rake], prepend: 'bundle exec'
  config.exec.commands %w[rspec cucumber], prepend: 'spring'
end

You can generate binstubs for each command:

➜ vagrant exec --binstubs
Generated binstub for bundle in bin/bundle.
Generated binstub for cucumber in bin/cucumber.
Generated binstub for rails in bin/rails.
Generated binstub for rake in bin/rake.
Generated binstub for rspec in bin/rspec.

Now you can use bin/cucumber instead of vagrant exec cucumber to execute commands in VM. All your configuration (directory, environment variables, prepend) will still be used.

Since binstubs use plain SSH to connect to VM, it creates connection much faster because Vagrant is not invoked:

time bin/echo 1
        0.28 real
➜ time vagrant exec echo 1
        2.84 real

To make plain SSH work, it saves current SSH configuration of Vagrant to temporary file when you run vagrant exec --binstubs. This means that if your VM network configuration has changed (IP address, port), you will have to regenerate binstubs again. So far I had no problems with this, but it's not very convenient for sure.

Moving forward, you can use projects like direnv to add bin/ to PATH and completely forget that you have VM running.

It is also possible to configure binstubs directory (e.g. default bin/ collides with Rails binstubs):

Vagrant.configure('2') do |config|
  config.vm.box = 'precise32'
  config.exec.binstubs_path = 'vbin'
end

Testing

Before running features, you'll need to bootstrap box.

➜ bundle exec rake features:bootstrap

To run features, execute the following rake task.

➜ bundle exec rake features:run

After you're done, remove Vagrant box.

➜ bundle exec rake features:cleanup

To show stdout, add @announce-stdout tag to scenario/feature.

Known issues

vagrant-exec cannot properly handle -v in command args (it's caught somewhere before plugin), so executing vagrant exec ruby -v will return Vagrant version rather than Ruby. As a workaround, wrap it in quotes: vagrant exec "ruby -v".

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2013-2015 Alex Rodionov. See LICENSE.md for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].