-
Notifications
You must be signed in to change notification settings - Fork 0
Development Environment
Vagrant is a tool that allows us to easily create and install a fully-configured development environment.
- Install version 4.3.8 or greater of VirtualBox
- Install version 1.5.0 or greater of Vagrant
In a command window, make a new directory for the project and in that directory in a command window.
vagrant init aooo/ao3_1; vagrant up --provider virtualbox
This step will first download and then boot the virtual machine.
Note: The download can take a long time -- make sure to set your computer not to go to sleep or else the download will be interrupted.
The output will look something like:
A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant. Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'aooo/ao3_1'... ==> default: Matching MAC address for NAT networking... ==> default: Checking if box 'aooo/ao3_1' is up to date... ==> default: Setting the name of the VM: vagrant_test_default_1435761128429_81089 ==> default: Fixed port collision for 22 => 2222. Now on port 2200. ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 => 2200 (adapter 1) ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2200 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection timeout. Retrying... default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if its present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => /Users/mac/Desktop/vagrant_test
Now you have downloaded the Vagrant virtual machine, you can connect to it using the following command:
vagrant ssh
This will connect you to the Ubuntu virtual machine as the user "vagrant".
You can keep your Vagrant install up to date with fixes and improvements by running
vagrant provision
in the same directory as the Vagrantfile, after running vagrant up.
This step is temporarily needed until we update the vagrant box.
Connect to the virtual machine with
vagrant ssh
Edit the file bin/reset_rvm2 and paste in the following script
#!/bin/bash if [ "$1" != "force" ] then echo "This script resets the rvm enviroment, downloading and reinstalling ruby and the gems to a known good state." read -p "Are you sure? " -n 1 if [[ ! $REPLY =~ ^[Yy]$ ]] then echo exit 1 fi fi if [ -d ~/.rvm ] ; then mv ~/.rvm ~/.rvm-`date +%F-%H-%M-%N` fi gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \curl -L https://get.rvm.io | bash -s stable [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" rvm autolibs read-fail rvm install ruby-2.0.0-p643 rvm --default use 2.0.0-p643 rvm gemset use global gem install rvm-capistrano gem install bundler gem install god gem install unicorn rvm rvmrc warning ignore /home/ao3app/app/current/Gemfile
Save the script and make it runnable with
chmod u+x bin/reset_rvm2
Run the script
bin/reset_rvm2
This will set up Ruby 2.0 correctly.
Next, you need to check out a copy of the Archive from GitHub. If you don't have a GitHub account, see Get a GitHub account.
If you intend to edit the Archive files using tools on your host machine, then perform the following step in the folder where you downloaded the Vagrantfile. The files will then be mirrored in the /vagrant folder on the Vagrant guest machine (note the leading slash in /vagrant).
git clone git@github.com:YOURUSERNAME/otwarchive.git Cloning into 'otwarchive'... remote: Reusing existing pack: 78163, done. remote: Counting objects: 15, done. remote: Compressing objects: 100% (12/12), done. remote: Total 78178 (delta 5), reused 7 (delta 3) Receiving objects: 100% (78178/78178), 41.37 MiB | 745 KiB/s, done. Resolving deltas: 100% (56038/56038), done.
If you are going to edit the Archive files directly on the guest virtual machine, you can place them wherever is convenient.
Once you have cloned the repository, add the release version of the Archive upstream so you can keep up to date.
git remote add upstream git://github.com/otwcode/otwarchive.git git fetch upstream
After connecting with vagrant ssh:
cd /vagrant/otwarchive/ bundle install
You will see:
Using rake (10.1.0) ...[long list of gems]... Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
bundle exec rake db:migrate
After connecting with vagrant ssh:
start_my_unicorns
You will see:
starting new unicorn master setting /home/vagrant/app/current to /vagrant/otwarchive copying config database.yml local.yml redis.yml -=t`", /`-.___. (_/, `-._.r=" /|/`--,`} \I' ,// vagrant@ubuntu:/vagrant/otwarchive$
In order to have the Archive skins available, you have to cache them.
After connecting with vagrant ssh, start a console with:
bundle exec rails c
In the console paste the command:
1.9.3-p545 :001 > Skin.where("skins.cached = true and not ( `skins`.`id` = 887 or `skins`.`id` = 890 or id=928 or id=929 ) ").each{|skin| skin.cache!}
bundle exec rake Tag:reset_filter_counts
Point your browser to http://127.0.0.1:8081/
If you get a "connection denied" message, check your Vagrantfile contains:
config.vm.network "forwarded_port", guest: 8081, host: 8081
If you get a "connection denied" message, you may need to configure VirtualBox to forward your port. (This has been an issue under OS X Yosemite in at least one case.)
- Open VirtualBox on your computer
- Right-click on the AO3 box in the list of boxes and choose Settings
- Click on Network
- Click on the Port Forwarding button
- Forward host port 8081 to guest port 8081 and OK
To load the autocomplete data into redis, you have to use the rake task. After connecting with vagrant ssh:
bundle exec rake autocomplete:load_data
This will take some time to complete. You can continue working on the Archive in the meantime.
start_my_unicorns
You will see:
vagrant@ubuntu:/vagrant/otwarchive$
kill_my_unicorns
After connecting with vagrant ssh:
start_my_workers
And
kill_my_workers
Note: The version of the Archive code being run by the Resque jobs will not automatically reload new code as you write. So if you change the way any background job works, you will have to kill your workers and start them again before the changes will be reflected in your results.
After connecting with vagrant ssh:
To run cucumber tests, use:
run_cucumber features
This will run all the tests, which might take a while. You can run individual (once the system is set up by the above command) tests in the /features folder using the following syntax:
export RAILS_ENV=test bundle exec rake db:create:all --trace bundle exec rake db:schema:load --trace bundle exec rake db:migrate --trace bundle exec cucumber -f progress -r features features/<folder, or folder/filename, or folder/filename:line-number>
If your Vagrant copy of Elasticsearch has problems and the Archive can't connect to it, you may need to restart Elasticsearch.
After connecting with vagrant ssh
sudo /etc/init.d/elasticsearch restart
If you need to dump your Memcached store:
rails c development
This will load your Rails console in the development environment. You then need to issue the command to dump the store:
Rails.cache.clear
- Make sure your Vagrant Archive is started and responding on port 8081 as explained above.
- Create an account at vagrantcloud.com.
- On the command line, go to your Archive Vagrant folder, type in vagrant login and enter the details you set up at step 2.
- Type vagrant share --http 8081 to enable sharing. It will allocate a URL based on some random name and number to your box. You should be able to access your copy of the Archive over the Internet.
Please see the SSH Sharing instructions at VagrantUp. Sharing your box via ssh will allow you to collaborate directly with other coders, or enable Systems to troubleshoot problems on your box.
If you have any questions regarding code development, please don't hesitate to send an email to otw-coders@transformativeworks.org and we will try to get back to you as soon as possible!