Created
August 19, 2019 19:25
-
-
Save ultimateprogramer/97a94ddbc77d2c6a0246fdcb01bfe1b7 to your computer and use it in GitHub Desktop.
Using Vagrant for Rails Development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| site "http://community.opscode.com/api/v1" | |
| cookbook 'apt' | |
| cookbook 'build-essential' | |
| cookbook 'system' | |
| cookbook 'ruby_build' | |
| cookbook 'ruby_rbenv', '~> 1.1.0' | |
| cookbook 'postgresql', git: 'https://github.com/ChowOps/chef-postgresql' | |
| cookbook 'vim' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| vagrant plugin install vagrant-vbguest | |
| vagrant plugin install vagrant-librarian-chef-nochef | |
| # Create a vagrant config | |
| cd MY_RAILS_PROJECT # Change this to your Rails project directory | |
| vagrant init | |
| touch Cheffile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # To create vagrant environment | |
| vagrant up | |
| # To SSH into the environment | |
| vagrant ssh | |
| # To reprovision the box | |
| vagrant provision |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- mode: ruby -*- | |
| # vi: set ft=ruby : | |
| VAGRANTFILE_API_VERSION = "2" | |
| REQUIRED_PLUGINS = %w(vagrant-vbguest vagrant-librarian-chef-nochef) | |
| plugins_to_install = REQUIRED_PLUGINS.select { |plugin| not Vagrant.has_plugin? plugin } | |
| if not plugins_to_install.empty? | |
| puts "Installing required plugins: #{plugins_to_install.join(' ')}" | |
| if system "vagrant plugin install #{plugins_to_install.join(' ')}" | |
| exec "vagrant #{ARGV.join(' ')}" | |
| else | |
| abort "Installation of one or more plugins has failed. Aborting. Please read the Bike Index README." | |
| end | |
| end | |
| Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
| config.vm.box = "ubuntu/xenial64" | |
| # Configure the virtual machine to use 1.5GB of RAM | |
| config.vm.provider :virtualbox do |vb| | |
| vb.customize ["modifyvm", :id, "--memory", "1536"] | |
| end | |
| # Forward the Rails server default port to the host | |
| config.vm.network :forwarded_port, guest: 3000, host: 3000 | |
| # Use Chef Solo to provision our virtual machine | |
| config.vm.provision :chef_solo do |chef| | |
| chef.cookbooks_path = ["cookbooks", "site-cookbooks"] | |
| chef.add_recipe "apt" | |
| chef.add_recipe "build-essential" | |
| chef.add_recipe "system::install_packages" | |
| chef.add_recipe "ruby_build" | |
| chef.add_recipe "ruby_rbenv::user" | |
| chef.add_recipe "ruby_rbenv::user_install" | |
| chef.add_recipe "vim" | |
| chef.add_recipe "postgresql::server" | |
| chef.add_recipe "postgresql::client" | |
| chef.json = { | |
| rbenv: { | |
| user_installs: [{ | |
| user: 'ubuntu', | |
| rubies: ["2.4.0"], | |
| global: "2.4.0", | |
| gems: { | |
| "2.4.0" => [{ name: "bundler" }] | |
| } | |
| }] | |
| }, | |
| system: { | |
| packages: { | |
| install: ["redis-server", "nodejs", "libpq-dev"] | |
| } | |
| }, | |
| postgresql: { | |
| :pg_hba => [{ | |
| :comment => "# Add vagrant role", | |
| :type => 'local', :db => 'all', :user => 'ubuntu', :addr => nil, :method => 'trust' | |
| }], | |
| :users => [{ | |
| "username": "ubuntu", | |
| "password": "", | |
| "superuser": true, | |
| "replication": false, | |
| "createdb": true, | |
| "createrole": false, | |
| "inherit": false, | |
| "login": true | |
| }] | |
| } | |
| } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment