Lately we’ve been using Dropbox a lot and as a small team we love it! As a few days ago the need for a small staging server arose we decided to give Phusion Passenger a try and setup a very bare bone box with Apache, Passenger, Rails and all the small stuff around such a setup. When we came to the point when I would just start to configure Capistrano a tremendous idea came to our mind: How cool would it be if we could deploy and control our server by just moving things around in our shared Dropbox folders? GREAT! We never miss the chance for an adventure which lays along our path so we got right into it and would like to share what we found out with the rest of the world.

Photo by kellan: http://www.flickr.com/photos/kellan/2422461496/
For the most impatient folks of you: It works great! We can now deploy an application by just heading to our Dropbox folder with a shell, do a “git pull” and touch the tmp/restart.txt within the deployment! Also can our designers work just within the deployed version. We share the folder with them and they can see any changes to the CSS, views and images instantly online. They don’t have to run a Rails server on their own or bother with any kind of manual connection to the server. They work with files in their favorite file manager all day long and Dropbox integrates like a charm in this “workflow”. In addition to that we’ve built a plugin that let you even run rake tasks on the server and watch their output. But enough now, let’s start!
In a first step we will create a new Rails app and a distributed git repository. And because this article is all about Dropbox it’s just an obvious decision to “host” the repository on the Dropbox. This definitely has some flaws and might not be the right solution for you, so feel free to just use your normal git procedure instead of the described one:
Lets setup our Rails project:
rails myapp
cd myapp
git init
Now we’re following the instructions given by Tim Lucas to ensure that those annoying log files etc are not getting into our git repository. namely:
Create a .gitignore right where you are and add this into it:
log/*.log
tmp/**/*
.DS_Store
doc/api
doc/app
Nearly there. Just don’t forget to create to empty .gitignore files in log/ and tmp/ so that those directories are commited to the respository.
touch log/.gitignore
touch tmp/.gitignore
We’re now finally ready to do add anything into a first commit to the new git repository:
git add *
git commit -m "Initial commit"
The next step: Dropboxfication
To really host your git repository on the Dropbox you have to create a new folder within your Dropbox account and share it with your colleagues or friends who should have access to the repository. Now just clone your freshly created app here in git’s bare mode:
cd ~/Dropbox/your/newly/shared/dropbox/folder
git clone --bare path/to/your/earlier/created/rails/app yourapp.git
You should now throw away the folder where you created your app initially and clone a new version from the repository in the Dropbox to get all those settings right where a git push should be directed to. If you’ve done that create another shared folder in your Dropbox. This is the one where your app is going to be deployed to. So lets say you’ve created ~/Dropbox/your/newly/shared/yourapp-deploy for that purpose.
Now clone the repository there:
git clone ~/Dropbox/your/newly/shared/dropbox/folder ~/Dropbox/your/newly/shared/yourapp-deploy/
Step 3: Setting up the webserver
At the moment Dropox is not intended to be installed on a UNIX system without any X window system. But there is a great tutorial which explains how to do it anyway. So the first thing to do is just follow the tutorial and install the Dropbox client on your server within as a dedicated “dropbox” user (at least we did so). Please also do the last step and create the start/stop script, it’s just a matter of copy&paste the code shown in the tutorial!
At least as important as the Dropbox client on the server is an Apache2 setup with mod_rails. Again the installation process is very well documented. Just head over to the mod_rails website.
If you’ve mastered this, too, let’s take the last step towards your new deployment situation.
Step 4: Getting all the parts together
First we should link the deployment folder in the Dropbox to /var/www.
ln -s ~/Dropbox/your/newly/shared/yourapp-deploy/public /var/www/yourapp
Note that it’s important that you only link the public directory instead of the whole application!
Now let’s add a new virtual host file to Apache. It goes into the sites-available folder of the Apache config which should be located in /etc/apache2. So open /etc/apache2/sites-available/yourapp and let it look like this:
NameVirtualHost *:80
RailsEnv development
ServerName dev.yourhost.com
DocumentRoot /var/www/yourapp/
As you can see the environment your server runs in can be configured. For a whole list of all mod_rails configuration options have a look at it’s documentation.
After you’ve created the virtual host file you need to enable it and it might also be a good idea to restart apache even if this is not allways necessary:
a2ensite yourapp
apache2ctl graceful
Voila, at this time, you should already be able to completely manipulate your application by browsing and editing on any computer that has been invited to the “yourapp-deploy” folder just by altering the files.
Also keep in mind that you can restart the server by touching ‘yourapp-deploy/tmp/restart.txt’.
If you would like to get the newest version out of the git repository ot the server just take any shell you can get, head over to the yourapp-deploy folder and do a
git pull
That’s it! Give Dropbox the time it needs to transfer all the changed files to their server and then add a little extra time which your server needs to get the changes from the Dropbox, again. And if you or a designer or anybody else has changed something directly in the deploy directory just feel free to commit those changes back into the repository:
git add
git commit -m "A commit directly from the deploy folder"
git push
Pretty simple and pretty clean for a solution that can be used as an “instant online” test bed!
The little extra
This setup seems to be really cool for a small test or staging server. But we felt one urge with it: For any rake operation we need to connect to the server and loose all those benefits the Dropbox integration gave us, namely “the ease of use”. So we wrote a tool which allows you to run rake commands remotely just by echoing the arguments of the rake call into “yourapp-deploy/tmp/rake.txt”.
You can install this tool as a git submodule by executing
cd ~/Dropbox/your/newly/shared/dropbox/folder
git submodule add git://github.com/walski/control_by_files.git vendor/plugins/control_by_files
git submodule init
git submodule update
Now run this script as a cronjob. To accomplish this, get a shell on your server with the Dropbox user and run
crontab -e
now add the following line (IMPORTANT! ONE LINE)
* * * * * cd /home/user we created for dropbox/Dropbox/yourapp-deploy/the-name-of-the-app-itself/ ; export RAILS_ENV=development; ruby vendor/plugins/control_by_files/lib/control_by_files.rb
Your system is now complete! Anything you write to yourapp-deploy/tmp/rake.txt is executed after short amount of time by the server. The output of those rake tasks (you can enter multiple tasks at once! Just one in each line) is written back to the same rake.txt file and it gets marked so that it is not run twice.
That’s it. It’s a lot of stuff so please let us now if you encounter any problems or find any bug in our description.
Thanks a lot for reading and also a huuuuuge thanks to Jan who did nearly all the work to get this setup running and documented.
Enjoy your new super dynamic workspace.
Yours,
Thorben
FEtMab-Team