Building your local environment (SSHFS) - DoSomething/legacy-website GitHub Wiki

⚠️ This installation method is deprecated ⚠️

Instead, use the Building-your-local-environment-(NFS).

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


For troubleshooting tips, see the FAQ at the bottom of this page.

Sanity check

If your local environment recently got borked, check this list of environment-breaking changes.

The basic parts

We use Vagrant to manage the virtual app server.

In a separate project, you can see how we use Salt Stack via a Vagrant plugin to provision and configure the software on the server image.

For this project, however, you only need to vagrant up.

At the end of this installation routine, you'll have two identical directories on your host machine:

  • dosomething: This is where you originally cloned the repo. Use this directory for Vagrant operations: vagrant up, vagrant halt, etc. Note: To get DevOps updates to the dosomething repo do a git pull in dosomething.
  • dosomething-mount: This is the actual app code that will power your Vagrant web site. Do all of your app development in here.

Read more about these directories and SSH-FS.

Prerequisites

Install VirtualBox

Available here. We haven't seen any problems from running different versions, so just grab the latest.

Install OSXFUSE / SSHFS

Don't use Homebrew to install these packages. Instead, get them here:

  • OS X FUSE: Install latest version, then restart your machine
  • SSHFS: Install latest version

At this point, you should see sshfs as an executable on the command line, probably at /usr/local/bin/sshfs. This is necessary to proceed.

Vagrant

Once you've installed Vagrant, you should have the vagrant command in your CLI. Confirm your version:

Vagrant 1.6.5````

Very nice.

#### Create mount point

The Vagrantfile introduced in [this pull request](https://github.com/DoSomething/dosomething/pull/2390) sets the SSHFS-mounted directory as `../dosomething-mount`, i.e., one directory level up from where you've checked out the repo. So, within your main repo directory, simply

`mkdir ../dosomething-mount`

#### Vagrant plugin: SSHFS

`vagrant plugin install vagrant-sshfs`

#### Vagrant plugin: VB Guest Additions

This keeps the injected VirtualBox OS additions up to date in your Vagrant boxes.

`vagrant plugin install vagrant-vbguest`

### Vagrant setup

1. Clone the phoenix repo.  The phoenix repo's main branch is dev.

2. Because Vagrant uses [SSH agent forwarding](http://stackoverflow.com/questions/11955525/how-to-use-ssh-agent-forwarding-with-vagrant-ssh), make sure your local SSH key -- the one you use with GitHub -- is ready to be used. 

* From your host, try `ssh-add -L`. If your key is listed, you're good. 

* If not, run `ssh-add` without arguments. It will add any of the 'standard' keys in: `$HOME/.ssh/identity, $HOME/.ssh/id_rsa, and $HOME/.ssh/id_dsa.` (To add a key with a nonstandard name, specify it like `ssh-add /path/to/key`.)

3. To start up your environment, run `vagrant up` from the local directory of the clone of the dosomething repo fork.

4. When `vagrant up` is complete, you should see an identical file listing in `../dosomething-mount`. The first time you do this, it may take some time for the mount to complete and for the files to show.

* **Note**: On your first run, you may encounter this, which you can ignore.

> Installing the Window System drivers ...fail!
> (Could not find the X.Org or XFree86 Window System.)
> An error occurred during installation of VirtualBox Guest Additions 4.3.6. Some functionality may not work as intended.
> In most cases it is OK that the "Window System drivers" installation failed.

This is not an issue as none of the X-Windows functionality is installed on the Ubuntu server by default. We do everything on the command line, none of that silly GUI stuff.

### Application setup

1. From the original repo directory, run `vagrant ssh`.  This will open a terminal into the vagrant vm.

2. If this is the first time you ran `vagrant up`, make sure to run the setup
script: `setup-www`. This will deploy your local DoSomething distribution to the base directory `/var/www/dev.dosomething.org` in the vm.

3. Run the following to install the site. It might go a lot faster to be plugged into the office network via a network cable rather than using wi-fi. But the cable has to remain plugged in for the duration, otherwise, you may cause a process to hang.


  * `ds build --install`\*
  * `ds pull stage --db`

4. :coffee: time. Step 3 takes 10–30 mins to complete, depending on your machine's happiness.

5. Edit your local (not your vagrant box!) host file and add the development hostname. This is required to make sure that cookies work properly.

  `sudo vim /etc/hosts`  
   
   Add this line to the bottom, and save:  
  `127.0.0.1 dev.dosomething.org`

6. You're done!

   * Your environment will be available at http://localhost:8888/ and http://dev.dosomething.org:8888/.
   * The webroot in Vagrant is the `/var/www/dev.dosomething.org/html` directory. In your host machine, it's `../dosomething-mount`.

> \* `--install` is required again since [#2809](/DoSomething/dosomething/pull/2809)