A place to breathe

Sunday, August 31, 2014

A new kind of animal: VM, Vagrant and Rails

Now, I manage to run a Vagrant provided by Discourse team. Next, I want to serve static page on Rails. 

All I want to do is to serve a static page. And now let's see what kind of mess I am getting into!
 
Once I plunged into Rails development, I realize that it is hard to develop on my local machine. I don't want to mess up my Mac environment with silly Rails gems dependencies, I am willing to invest a bit more time to understand all kind of Ruby tools. For all its worth, you better be good, Ruby on Rails!!!
  
My idea is to install a Virtual box using Vagrant so that I can ssh into a virtual box. Plus, I will run a Ruby environment within the Vagrant and install all the "germs" (yeah, pun intended) into that vagrant (read: it's not a misspelled of Viagra).
Now that's clean.

First, get the Vagrant image. Create a project folder, say "myapp" and make the source code development "into" a virtual box: 

mkdir myapp
cd myapp 
vagrant init precise32 http://files.vagrantup.com/precise32.box 

This will download a Vagrant config file called "Vagrantfile". Now, I want to host my Rails on port 3000 (following convention), so that, I edit the file here:

config.vm.network :forwarded_port, guest: 3000, host: 3000

Now, we're ready to configure the machines. Issue the following command:

vagrant up

Now, what it does is to do some magic of creating a default VM environment for your "myapp" folder so that you can build an isolated environment within that folder. To access that isolated environment, you need to remote login using ssh :

vagrant ssh
cd /vagrant

You now see your "Vagrantfile". Basically your "myapp" folder has been mounted into "/vagrant" folder in the VM. Cool so far? Run everything to get Rails started:

sudo apt-get update
sudo apt-get install curl 
\curl -sSL https://get.rvm.io | bash -s stable --rails 

Try check your rails:

vagrant@precise32:~$ which rails
/home/vagrant/.rvm/gems/ruby-2.1.3/bin/rails

I feel so safe that all these commands live within the Ubuntu VM on my Mac. At least if things screws up, I can just forget about this VM and starts over.

vagrant@precise32:~$ rvm -v
rvm 1.25.29 (stable) by Wayne E. Seguin , Michal Papis [https://rvm.io/]


A note of caution here: make sure you are running rails version from your home's RVM!.

which rvm 
/home/vagrant/.rvm/bin/rvm 

Now, install Rails. Because you need Rails to create projects.

gem install rails
rails new /vagrant 

make sure you have 'therubyracer' and 'execjs' inside your Gemfile.

bundle install 
rails server 


Go to "http://localhost:3000" . See something? Rejoice !!









Saturday, August 23, 2014

Helpful Unix command to check the biggest files in the server

Often, we suddenly realize that we are running out of space in the server. Here's a command that you can use to check the top files that is consuming your disk space:

du . | sort -nr | head -n10

Tuesday, August 12, 2014

Discourse on Docker

The Discourse team is solving the Rails complicated installation using Docker install. But docker itself is not easy to work with ! (at least for now).

I've spend around 3 hours fiddling with Docker to get the right installation ready. I spent another 2 hours demistify SMTP relay in Discourse. Fortunately i manage to sort out the email sending and my install works like breeze.

Part of the reason why is that docker daemon doesn't seem to be stable. And if you pull non-standard docker library, it may not work.

But honestly, i would rather work with docker than messing up my vps install. Kudos to Discourse team!

Now I'm having a blast. 

Monday, August 11, 2014

Fixing ReCom's forum

Recently, I've decided to fix ReCom's forum (www.recom.org) once and for all. I've enough of VB and I don't want to be adding custom codes and all variety of silly markups just to be broken on the next upgrade.

The last (hasty) upgrade that we did, we broke so many functions that the site is really unusable. I am very disappointed and I don't want to spend anymore time on VB. I blame it on myself for trusting VB.

OK enough ranting.

After a few days of searching, I've decided to migrate ReCom's VB forum. I figured that the work is so much that I quit my full time to work on it full time (of course, I have other things to work on as part time to support myself for a few months). In addition, I am turning it into startup for obvious reason that if i don't do it, the Forum will find its death thanks to the VB 4.x upgrade.

We're going to migrate to Discourse.

After a few days reading and trying out, I manage to install Discourse development on the VPS. But the really bad problem that I have is we have so much dependencies on Rails and I really don't like to way I need to install so many packages on the VPS.

Fortunately, the Discourse team is recommending to use Docker. I decided to then just follow their setups and so far so good.

When installing, I realize that I didn't configure "smtp.example.com" to be ReCom's email.
That would be my next move: to configure email



About Me

I'm currently a software engineer. My specific interest is games and networking. I'm running software company called Nusantara Software.