Wednesday, May 6, 2015

Discourse - Open Source blog platform


Hello Discourse Dev community, I am a new web developer who just graduated from general assembly's web development full stack program. I have written some small apps and I want to jump into a more robust full feature app like Discourse. Another developer told me about Discourse and here I am. I installed discourse onto my machine and I would love any guidance on writing tests. I also go by the name kenyacode.

That was my first post at discourse, an open source blog platform. Today I'm going to go through the steps I went through installing Discourse, Virtual Box, & Vagrant. If your a new programmer and don't know what these are, don't worry I will go over each one.

Need to mention that I use a mac with OS X Yosemite 10.10.3, iTerm, and the Atom editor.

So what is Discourse and why did I want to install it?



Discourse is the 100% open source discussion platform built for the next decade of the Internet. It works as:
a mailing list
a discussion forum
a long-form chat room

To learn more about the philosophy and goals of the project, visit discourse.org.

Since I'm a Rubyist, I wanted a project that was written in Ruby. Discourse is built with:
Ruby on Rails — Our back end API is a Rails app. It responds to requests RESTfully in JSON.
Ember.js — Our front end is an Ember.js app that communicates with the Rails API.
PostgreSQL — Our main data store is in Postgres.
Redis — We use Redis as a cache and for transient data.


Plus lots of Ruby Gems, a complete list of which is at /master/Gemfile.As programmers we learn by doing and what better way than to work on a great app written in a programmer friendly language like Ruby On Rails and a modern front end like Ember.js. I hope to learn a lot about the code and also how to collaborate with other developers.
Alright now that you know why, here are the other three things I installed:
I used brew cask to install. If you don't know what brew is go here: caskroom.io/ Brew cask installs mac software in one line from your terminal.

1. VirtualBox

I don't set up environments on a regular basis, so it can be intimidating to set up a *nix flavored environment. (What is *nix? I believe it stands for Unix.)

This is where VirtualBox comes in. VirtualBox is a Virtual Machine, a doorway into an entirely different operating system. It’s free, open source, and runs on Windows, Linux, Mac and Solaris.

2. Vagrant

With VirtualBox installed, it’s now time to bring a VM to life. Discourse maintains all the
information necessary to wire up a VM within the Discourse codebase itself!
It does this through the magic of Vagrant, another free open-source tool which is used to both package and initialize a VM with all the necessary configurations in place. Thanks to Vagrant, there’s no need to figure out if you have the correct version of Ruby, or if Rails is up-to-date, or even how to install nginx, thin, or any of the other bits and pieces that make up Discourse.

It’s all in Vagrant, stored within the Vagrantfile, and comes up with with the ease of a single command line. For the purposes of working with Discourse, you’ll need Vagrant 1.7.2 or higher.

After installing VirtualBox and Vagrant, check to make sure you have the most recent version. In your terminal
vagrant -v => Vagrant 1.7.2

3. Next you will need to install Git.  I skipped this step because I already have git.  I went to Discourse's github repo and forked the repo, which means I copied it to my Github.  Then I cloned the repo to my mac.

4. Running the VM and Connecting to it. In iTerm: (to make sure I didn't miss a step, I copy and pasted these directions from http://blog.discourse.org/2013/04/discourse-as-your-first-rails-app/
vagrant up
This will kick the VM into motion. Vagrant will connect to the official Discourse site, download the VM image we’ve prepared (note: this may take a while), extract it, and enable all the subsystems necessary to bring the environment to life. VirtualBox may prompt you a few times, so go ahead and accept its requests.
Once the VM is up, you’ll be back at the command prompt.
Now, it’s time to connect to the VM and start up the Rails server. From the shell you already have open in the project folder, type:
vagrant ssh
Once inside, a few more commands is all it will take. Change to the vagrant directory:
cd /vagrant
Now it’s time to interact with Ruby on Rails. Invoke the Rails installer, like so:
bundle install
Next, tell Ruby on Rails to migrate the development database schema into your local repo. We do this via rake, which is Ruby’s version of make, boasting Ant-like features.
bundle exec rake db:migrate
At long last, it’s time to bring up the Rails server, ready to accept HTTP requests.
bundle exec rails s
Our VM config causes this Rails server to begin listening for requests on port 4000. So once the server is up, open up a web browser on your local workstation and navigate tohttp://localhost:4000
Voila! As you can see in the screenshot above, Discourse is indeed running locally off of port 4000, and in the background, you can see the guts of Discourse working away within the SSH client that you used to launch the server.
The initial request may take a while as Discourse begins to initialize its subsystems and start the caching processes; first page loads of 5 to 10 seconds are not uncommon. However, if you’re seeing page load times well beyond this, let us know what your PC configuration is. The Discourse community is actively looking for tweaks and improvements for better VM performance.
Step 5: Shutting Down

When you’re done for the day, Ctrl+C will kill the Rails server, exiting you back to the command prompt from within the VM. To finish up, type:
exit
vagrant halt
This will exit your SSH session, then end the VM and free up its resources.
Congratulations! You now have a working copy of Discourse, ready for you to hack away at any time, and a complete Ruby on Rails environment to facilitate said hacking.

Step 6: PhantomJS on Ubuntu

Ok so you have Discourse up and running.  Do you want to write tests? Well of course you do.  Well I do anyways.  So I looked and searched, by search I mean I read the Advanced developer Install Guide, its at the bottom.

You will need PhantomJs in order to run javascript tests he said.  Ok I replied.
Here is the only part I ran into a problem.  The directions on Discourse's Github page is for a 64-bit version and we installed a 32bit version of the Ubuntu linux .  Not to worry, here is how its done.

I went to http://phantomjs.org/build.html and followed the steps.  I know that running sudo commands can be scary so I put the link in case you wanted to copy and paste directly from the phantomjs.org site.

We are in a Linux environment, so we use the Debian-based distro.
On Debian-based distro (tested on Ubuntu 14.04), run:

sudo apt-get install build-essential g++ flex bison gperf ruby perl \ libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev \ libpng-dev libjpeg-dev python
Note: It is recommend also to install ttf-mscorefonts-installer package.
sudo ttf-mscorefonts-installer
Then, launch the build:
git clone git://github.com/ariya/phantomjs.gitcd phantomjsgit checkout 2.0./build.sh


Whoa... that was quite an afternoon.  It was fun seeing the blog up and running and now I get to read all the code and start contributing.  I plan on writing a blog post everyday about what I'm learning.

Feel free to reply to this post with anything you discovered in your install, or any general comments.





No comments:

Post a Comment