Alienware Busted; Chromebook to the Rescue!

Introduction

My new-ish — I bought it in late January — Alienware laptop conked out on me.  It won’t POST: the logo has a light but neither the fan nor the screen start.  I bought it at Microcenter, so I took it back there to the support center.  They’re sending it to Dell for repair: unfortunately it’s going to take 10 – 14 (!) business (!) days (!) to get it back.  In the interim, all I’ve got is my old, busted up MacBook Pro that the Alienware replaced (late-2011, cracked trackpad, etc.) and a Samsung XE303C12 Chromebook (circa late-2012).  I decided to try to set up a development environment on the aforementioned Chromebook, as the MBP is nightmarish to use unless I can plug in external peripherals (especially a mouse); that makes it pretty much only useful as a desktop.

This post chronicles the trials and tribulations of setting up a reasonable web development environment on the Chromebook.  Honestly, in retrospect, I probably should have just used a cloud-based development environment like nitrous.io or set up a cheap AWS micro instance and tailored it to my liking, but I like the added flexibility of being able to work offline.  I think I’m also probably cheap.  Here were my goals with this project, broken up into bite-sized pieces:

  • Clone a Ruby-on-Rails project from my BitBucket repository
  • Make modifications to said RoR project (preferably with my favorite editor, Emacs)
  • Test my modified RoR project locally in an environment as close as possible to a Heroku dyno
  • Push the modifications back to my BitBucket repository
  • Push the modified project to Heroku

The Samsung XE303C12

I can’t remember how much this thing originally cost me; it looks like the MSRP was $250USD when it was released, so probably close to that.  Right now, it’s available on Amazon for about $180USD; note that there’s a newer (and probably much more capable) model available at pretty much the same price.  Unsurprisingly, things have come a long way since 2012-2013.  😉

Here’s the spec sheet for the little Chromebook that could: http://www.samsung.com/us/computer/chrome-os-devices/XE303C12-H01US-specs.  It’s got an Exynos 5 Dual processor,  a Samsung-designed implementation of the ARM Cortex-A15, 2GB of RAM, 16GB of eMMC storage, and an 11.6″ 1366 x 768 screen.  TL/DR?  It’s sort of slow, doesn’t have all that much memory, has a relatively small amount of slow(er) storage, and has a little screen.  I made specific choices with respect to the development environment to try to account for these shortcomings.

I should also note that I actually do enjoy using it, despite what I said above about its specifications.  I think the keyboard’s nice for the form-factor (it omits a lot of extraneous keys).  It’s also really light and the battery life is decent.

Setting up a Linux Environment

There are (at least) 2 ways to go about getting a Linux environment on a Chromebook: 1) ChrUbuntu and 2) Crouton.  ChrUbuntu will give you a full-fledged dual boot whereas Crouton runs side-by-side with ChromeOS.  I went with the latter because anecdotal evidence seemed to suggest that it was easier to set up.  I also haven’t maintained a full-blown Linux distribution on a laptop since college (early 2000’s) and my difficulty with it then colors my perception even now; that experience was probably my fault as I stubbornly insisted on using Slackware instead of one of the “beginner” distros.

The GitHub page for Crouton is here (https://github.com/dnschneid/crouton); it’s got detailed instructions about things like enabling developer mode, downloading Crouton, and running it.  I also made heavy use of reference [3] (see below).  The particular command of interest for my setup was:

sudo sh ~/Downloads/crouton -r trusty -t audio,cli-extra,core,extension,keyboard,xfce,xiwi

That’ll install Ubuntu Trusty Tahr with the XFCE window manager, integration with ChromeOS tabs, and a few extras.  The Unity desktop is available, but given the specs I listed above, I thought I’d go with something more light-weight.  Note: this step takes awhile.

Initial Setup: Emacs, Git, Ruby, Rails, Etc.

Because I’ll be deploying my application to Heroku, I wanted an environment as similar to a Heroku dyno as possible for development and testing.  That means PostgreSQL instead of MySQL, among other things.

The first thing I did after starting XFCE4 was install emacs (gotta edit those config files somehow):

sudo apt-get install emacs

I also created ~/.bash_aliases and added alias emacs=”emacs -nw” because I dislike the default behavior of opening a new window for emacs; I also think the X version is ugly.

I realized that man wasn’t installed by default (?!), so I installed that as well with sudo apt-get install man.

Next, I installed Ruby, Rails, etc.  I mostly followed [4] here, so I started by installing the dependencies.  This is as per [4]: I didn’t prune out the MySQL or SQLite installations.  I also didn’t install PostgreSQL yet; I did that later.

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

I’m using rbenv to manage versions.  Again, following [4]:

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

rbenv install 2.3.0
rbenv global 2.3.0
ruby -v

gem install bundler

Next, I set up Git per [5]:

git config --global color.ui true
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR@EMAIL.com"
ssh-keygen -t rsa -b 4096 -C "YOUR@EMAIL.com"

Note:  you’ve got to replace “YOUR NAME” and “YOUR@EMAIL.com” with … well … your name and email address, respectively.  Then, I went to my BitBucket account and added the new key with “Chromebook” as the label.  Finally, I tested my setup by successfully cloning my repository to my local machine.

I continued to set up Ruby on Rails.  I needed to install NodeJS (dependencies!  CoffeeScript, Asset Pipeline, etc.) and Rails.

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
gem install rails -v 4.2.6
rbenv rehash
rails -v

Getting Ready for Heroku

As I mentioned before, my end-goal was to deploy an application to Heroku.  To support that, I wanted my local development environment to match a Heroku dyno as closely as possible.  Thus, I needed PostgreSQL; I set that up next:

sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo dpkg-reconfigure locales
sudo apt-get install postgresql-common
sudo apt-get install postgresql libpq-dev
sudo apt-get install postgresql-client

sudo service postgresql start

sudo -u postgres createuser YOURNAME -s
sudo -u postgres psql
postgres=# \password YOURNAME

The wget command above threw a warning near the end that I didn’t explore further.  I think it impacted my ability to get v9.5.  My slightly modified commands install v9.3.  The apt-get install postgresql-client was required to fix an “Error: You must install at least one postgresql-client-<version> package.” error.  The last line will provoke a prompt to set a password for your PostgreSQL user.

Setting up PostgreSQL proved to be the most difficult part thus far.  The commands I entered above are the end-result of beginning with the references listed below and additional iteration and Google-Fu to fix problems that cropped up.

At this point, I tested out my install by creating a new rails app, modifying config/database.yml (username & password and adding template: template0 to the default environment — otherwise you’ll get an error about an encoding mismatch when you try to create the database via rake db:create), running rails server, and checking the connection via Chrome in ChromeOS.

Next, I installed and configured the Heroku Toolbelt [8] via

wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
heroku login

The Heroku Toolbelt lets one provision dynos for an app, check their status, run commands on them, and push code to them — all from the command line.

End-to-End Test

Now that I’ve got everything installed, I performed an end-to-end test.  I created a new sample repository in my BitBucket account, cloned that repository to my Chromebook, modified that repository (by creating a Ruby on Rails application in it), pushed my changes back to BitBucket, pushed my changes to Heroku, and checked the live application on Heroku.

I created the repository in my BitBucket account via BitBucket’s web interface.  Then I set it up on my local machine, added a text file, and pushed it back to BitBucket:

mkdir sample-heroku-app
cd sample-heroku-app/

git init
git remote add origin git@bitbucket.org:derstander/sample-heroku-app.git
echo "Bill Mason" >> contributors.txt
git add contributors.txt 
git commit -m 'Initial commit with contributors'
git push -u origin master

After this, I backed up one directory and used the rails generator via rails new sample-heroku-app –database=postgresql.  I modified config/database.yml with my development environment credentials (including that template note above).  I then made a new controller via rails generate controller welcome, added an index page at app/views/welcome/index.html.erb, and added the corresponding route to config/routes.rb.  I also created the database with rake db:create.  Finally, I tested it locally by starting up the server (rails server) and connecting via Chrome in ChromeOS.

Next, I made the modifications necessary to deploy the application to Heroku.  I added rails_12factor in the Gemfile under the production environment, and ran bundle install.  I also wanted to ensure that my local environment and Heroku were running the same Ruby version.  I checked mine with ruby -v and added ruby ‘2.3.0’ to the end of the Gemfile.  Then, I committed the files and pushed them to BitBucket.

Now it was time to deploy.  I started by creating an app on Heroku via heroku create from the top-level directory of my application.  Then I pushed the application via git push heroku master and migrated the database via heroku run rake db:migrate.  Then, I visited the application in Chrome under ChromeOS (the application location will be listed in the push command; it might look something like https://shrouded-scrubland-53276.herokuapp.com/).

Success!

Backup

Now that I’ve got a fully functional environment, I backed it up.  To do so, I needed to log out of it (though not out of ChromeOS) and used sudo edit-chroot -f ~/ -b trusty, where trusty was the name of my setup.  I then moved the resulting .tar.gz to the ~/Downloads/ directory so that I could upload it to Google Drive.  This’ll let me more easily restore my working system if something goes wrong; after all, Chromebooks seem to like to “powerwash” the machine to factory settings if they run into problems.

Summary

If you followed along, at this point you should (hopefully) have a fully functional development environment capable of creating a Ruby on Rails application, editing it, pushing it live via Heroku, and putting it under source control via Git — all on your Samsung XE303C12.  This post might also serve as a starter in case you want to set up your XE303C12 to run Linux for something else.  Not bad for a little Chromebook, eh?

References

  1. Getting Started with Rails 4.x on Heroku. https://devcenter.heroku.com/articles/getting-started-with-rails4.  Retrieved 2016-04-28.
  2. Heroku Postgres.  https://devcenter.heroku.com/articles/heroku-postgresql#local-setup.  Retrieved 2016-04-28.
  3. W.  Thomas.  Chromebook for Web Development.  http://www.wyliethomas.com/blog/2014/04/12/chromebook-for-web-development/.  Retrieved 2016-04-28.
  4. Setup Ruby On Rails on Ubuntu 14.04 Trusty Tahr.  https://gorails.com/setup/ubuntu/14.04.  Retrieved 2016-04-28.
  5. Set up SSH for Git.  https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html.  Retrieved 2016-04-28.
  6. Crouton Command Cheat Sheet.  https://github.com/dnschneid/crouton/wiki/Crouton-Command-Cheat-Sheet.  Retrieved 2016-04-28.
  7. [Crouton] Keyboard.  https://github.com/dnschneid/crouton/wiki/Keyboard.  Retrieved 2016-04-28.
  8. Heroku Toolbelt.  https://toolbelt.heroku.com/debian.  Retrieved 2016-04-29.

Leave a Reply

Your email address will not be published. Required fields are marked *