Posted by & filed under Programming.

Maybe you’re familiar with the LAMP stack? Linux, Apache, MySql, PHP. That’s been a pretty common way to serve websites for many years (circa 1998?). But things have changed, technologies have changed, and it’s not 1998 anymore. IE6 is dead, nested tables are dead, and the LAMP stack is the Old and Busted.

The New Hotness is the MEAN stack, MongoDB, ExpressJS, AngularJS, and NodeJS. This new stack of technologies is what many new web apps are using these days.

MongoDB

Ever since I started using MongoDB over a year ago I have not even considered using MySQL for a web project. I suppose it has its place, but the ease of storing your data as it really is instead of weird joins and relations makes a whole lot more sense to me. The beauty of MongoDB and NoSQL in general is the schema is regulated by the app. No more crazy schema migration scripts to keep your MySQL schema in tact.

I should also mention the other M you’ll want to use, when using NodeJS and MongoDB, and that’s MongooseJS. Mongoose makes working with MongoDB a breeze and adds so many convenient operations for querying, saving, updating, and deleting records.

ExpressJS

I had to try to explain to a coworker the other day how the MEAN stack equates to the LAMP stack and I was at amiss to communicate it. In a nutshell, ExpressJS makes creating a REST API dead simple. Express handles requests, routes, and responses. Throw in middleware and you have a supremely easy way to whip out a REST based API in no time.

Express lets you break the functions for different operations into small reusable chunks of code. Then combine them as you need them for different routes. For example, maybe some of your website is protected by authentication, and other parts are not. The auth protected routes can just call an auth() function and BAM!!! User authentication is now required for that particular route. Just to be clear a route is defined as an HTTP verb (GET, POST) and a URL (/user/profile).

AngularJS

New kid on the block is AngularJS. Developed for a few years by Misko, Igor, and Vojtia at Google, it’s now just come into its own. AngularJS is client side only and doesn’t care what you’re running on the backend. Rumor has it, the .Net crowd really loves AngularJS too, go figure.

AngularJS is a Single Page App (SPA). Once loaded into the browser it “fakes” page loads, by just loading different templates and changing the URL. This makes page loads extremely fast as all you’re waiting for is the data for that page. The CSS, JS, and most of the HTML is already there in the browser. AngularJS updates the page for you, it detects changes in your data and will update the page on the fly to reflect this change. For example, if you have a form to update some inforamtion, AngularJS, will update it live on the page as the form is being filled out. Truly awesome.

NodeJS

Let’s not forget the workhorse of this whole stack, NodeJS. Node is fast, efficient, and can do anything. Node’s popularity lately has skyrocketed and for good reason, it’s fast, modular, testable, and flexible. Node coupled with Express makes for a very powerful web server (hint: most people put Node behind Nginx)

Posted by & filed under Server Admin.

You want to keep those server logs right? I’ve had customers ask for analytical data for last year and by george Google Analytics doesn’t cover everything on the server.

What you’ll need

  • logrotate (installed on most systems). It’s beyond the scope of this article to install logrotate
  • s3cmd This you can install on a RedHat based server with their yum.repos.d file that’s easy enough to install
  • An Amazon S3 account (I hope this goes without saying)
  • Logs you want to rotate (in this case Nginx)

Setting up s3cmd

  • After you get it installed, you’ll want to run config (probably as root)
    • s3cmd --configure
    • This will ask you for your API KEY and API SCERET
    • This will also ask if you want to encrypt it on the disk or during transfer (HTTPS)
  • After you get it configured try running s3cmd ls That should list your buckets

Getting the logrotate set up

  • Go to the logrotate dir cd /etc/logrotate.d/
  • Edit the nginx file vim nginx to look like

    /var/log/nginx/*log {
        daily
        rotate 10
        missingok
        notifempty
        compress
        sharedscripts
        postrotate
          /etc/init.d/nginx reopen_logs
          nice /usr/bin/s3cmd sync /var/log/nginx/*.gz s3://<YOUR-S3-BUCKET-NAME/nginx/
        endscript
    }
    
  • This will sync all .gz files to a directory called nginx on the S3 server

Now wasn’t that simple?

Important notes

  • I’m using dates on my access files e.g. access.log-20130326.gz, if you use numbers doing a sync could really mess things up in your back ups. To change this you need to edit your logrotate.conf file adding dateext which makes the date the suffix.

Reference

http://www.lustforge.com/2012/07/15/logrotate-apache-logs-to-amazon-s3/

IMG_3538

Posted by & filed under GoodIdeas.

It’s time to give up the dedicated office and scale down to something a little smaller and more compact. I think I’ve struck a nice balance. Behold! I give you a renaissance of the Drop Front Secretary Solid Wood Desk. This desk has been in the family for a while. I think my grandparents had this desk in their house, with a few upgrades I’ve made into a modern convertible sitting desk + standing desk.

Tame Sit Down Desk by Day

Vicious Standing Desk by Night

Posted by & filed under Programming.

Setting up Jenkins for Node.js + Mocha testing and such

Install this stuff

  • Node.js via Nave
    • git clone https://github.com/isaacs/nave.git
    • ./bin/nave.sh usemain v.0.8.9
  • Mocha
    • npm install -g mocha
  • ChaiJS
    • npm install -g chai
  • xunit-file (Mocha custom report for Jenkins)
    • npm install -g xunit-file
  • Jshint
    • npm install -g jshint
  • Nock
    • npm install -g nock
  • Supertest
    • npm install -g supertest
  • Testacular
    • npm install -g testacular
  • PhantomJS
    • npm install -g phantomjs

Here is a hand script that will install v0.8.9 and all the others

https://gist.github.com/4535632

Posted by & filed under Programming.

Rollcall!

  • AngularJS in your code ✓
  • Jenkins ✓
  • Node.js is installed on the Jenkins server? ✓
  • Testacular is installed on the Jenkins server ✓
  • PhantomJS is installed on the Jenkins server ✓

If that’s what you’re using, this is how I set up testing on the Jenkins server.

  1. Create a new job in Jenkins
  2. Pull from Git (or whatever), Trigger how you want too. That’s not germane to this article.
  3. Inject some environment variables (may need to install a plugin for this)

    Env Vars

  4. Start a web server on the Jenkins server for Testacular to use and call the target in the build.xml script (see below)

    Web Server

  5. Generate the report (test_out/e2e.xml is configured in testacular-e2e.conf.js)

    xunit

build.xml

  
  <project name="My Project" default="build" basedir=".">

      <target name="testacular-e2e" description="Testacular AngularJS e2e Tests">
          <echo message="Running the tests ..." />
          <exec executable="testacular" output="test_out/output.txt" failonerror="true">
              <arg value="start" />
              <arg value="./config/testacular-e2e.conf.js" />
          </exec>
          <echo message="Tests done" />
      </target>

  </project>

config/testacular-e2e.conf.js

  basePath = '../';

  files = [
    ANGULAR_SCENARIO,
    ANGULAR_SCENARIO_ADAPTER,
    'test/e2e/**/*.js'
  ];

  autoWatch = false;

  browsers = ['PhantomJS'];

  reporters = ['dots', 'junit'];
  singleRun = true;

  proxies = {
    '/': 'http://localhost:8000/'
  };

  junitReporter = {
    outputFile: 'test_out/e2e.xml',
    suite: 'e2e'
  };