This tutorial will cover the steps for using a virtual maching (VM) on Nitrous.IO to develop and deploy AngularJS web apps running on a node.js server.
The tutorial is divided into the following 2 sections:
- Part 1 walks through the steps to use Git and Jenkins as a test and deploy tool to push updates to CloudBees (PaaS).
- Part 3 covers AngularJS web app development approaches
- Sign up for GitHub
- Sign up for Nitrous.IO. You can choose to use your GitHub account to do this, or your own email. If you are going to use Nitrous.IO to develop for both Python and node.js stacks, please sign up for two Nitrous.IO accounts.
- Once your Nitrous.IO registration has been completed, create new node.js VM Box from here
- Open the IDE of the VM Box, which should look like this:
Use the Nitrous.IO console located at the bottom section of the IDE to execute terminal commands.
Generate a new ssh key pair on the VM to use to sync with GitHub and Jenkins.
cd ~/.sshssh-keygen -t rsa -C "<your_email@example.com>"- When "Enter file in which to save the key (/home/action/.ssh/id_rsa):" is prompted, enter
/home/action/.ssh/nitrous_id_rsa Enter passphrase (empty for no passphrase): [Type a passphrase]Enter same passphrase again: [Type passphrase again]- Once the key pair has been generated, open the public key nitrous_id_rsa.pub using with vim
vim nitrous_id_rsa.pub - Copy the public key (first line) and add it to your GitHub keys with a new key name, e.g. nitrous_node
- Close vim by entering
:q! - Create a new config file in the .ssh folder and enter these lines below:
# Default GitHub user
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/nitrous_id_rsa
- Set your git user email identity
git config --global user.email "<your_email@example.com>" - Set your git user name identity
git config --global user.name "<Your Name>" - Clone this repository
git clone https://github.com/andrewbeng89/IS429AngularTest.git cd IS429AngularTest- Reomve the .git directory
rm -rf .git - Create a new GitHub repository with your account
- Initialise the demo app as a git repo on the VM
git init - Add the remote to the newly create GitHub repository
git remote add origin git@github.com:<your_username>/<your_new_repo>.git
You can use Nitrous.IO as a testing environment for development.
cd app- In the app/ directory, create a new file
credentials.js - Add
module.exports = {MONGO_PASSWORD:"is429"};and save - Install the dependencies
npm install - Run the app
node main.js - Under "Preview" from the IDE, select "Port 3000" to view the app which should look like this:
After signing up for CloudBees, install the CloudBees SDK on your Nitrous.IO Box
curl -L cloudbees-downloads.s3.amazonaws.com/sdk/cloudbees-sdk-1.5.2-bin.zip > bees_sdk.zipunzip bees_sdk.ziprm bees_sdk.zipcd cloudbees-sdk-1.5.2vim ~/.bashrcand typeito activate insertion mode- Insert the following lines at the end on the file.
Esc + :wqto save and close
export BEES_HOME=~/cloudbees-sdk-1.5.2
PATH=$PATH:$BEES_HOME
Check that the SDK has been installed:
- Reload .bashrc
source ~/.bashrc bees helpand enter region and account credentials
CloudBees provides Jenkins, a framework for building/testing software projects continuously, as a service. Developers can hook their GitHub project to this service, triggering automated test, build and deployment scripts whenever a push is made to the GitHub repository. Follow these steps to use Jenkins-as-a-Service with GitHub and CloudBees:
- Go to
https://<your-username>.ci.cloudbees.com/pluginManager/available - Select the GitHub plugin and click "Install without restart"
- During the installation process, check "Restart Jenkens when installation is complete..."
- Once Jenkins has restarted, go to
https://<your-username>.ci.cloudbees.com/configureand scroll down to "GitHub Web Hook" - Check "Let Jenkins auto-manage..."
- Enter GitHub credentials and test them
- Check "Override Hook URL"
- Copy the Hook URL
- Go to
https://github.com/<your-username>/<your-repository>/settings/hooks - Select "Jenkins (Github plugin)" and enter the URL
- Check "Active" and click "Test Hook"
- Click "Apply" at the bottom of the page.
Create and configure new CloudBees hosted node.js application
bees app:create -a <your-app-name> -t nodejs -P MONGO_PASSWORD="is429" -R PLUGIN.SRC.nodejs=https://dl.dropboxusercontent.com/u/6484381/nodejs-clickstack.zip- Go to
https://<your-username>.ci.cloudbees.com/view/All/newJobto configure a new Jenkins build job - Check "Build a free-style software project" and click "Ok"
- Uncheck "Restrict where this project can be run" under "CloudBees DEV@cloud Authorization" on the next page
- Check "Git" under "Source Code Management" and enter
https://github.com/<your-username>/<your-repository>.gitas the "Repository URL" - Check "Build when a change is pushed to GitHub" under "Build Triggers"
- Select "Execute shell" from "Add build step" dropdown
- Add "Deploy applications" build step
- Click "Add application" and enter the Application ID of the app you just created in the first step
- Change "Application file" to
target/*.zip - Add "Publish JUnit test result report" from "Add post-build action" and fill
test_out/unit.xml,test_out/e2e.xmlin "Test report XMLs" - Add the contents of
./build_scriptto the shell commands under "Execute shell": - Finally... click "Apply" at the bottom of the page!
To test the CI testing and deployment:
cd ~/IS429AngularTest- Make some changes to app/index.html using the Nitrous.IO IDE
- Commit the changes
git commit -m "test changes to app/index.html" - Push the changes to GitHub
git push origin master - Go to
https://<your-username>.ci.cloudbees.com/job/<your-build-id>/where the build will start shortly
This section will cover simple front and back end techniques to get you up to speed with AngularJS application development in the Cloud
AngularJS provides a modularized approach to bind data structures, e.g. Arrays, Objects and other variables, to HTML views. This repository provides the code for a simple "todo list" application created in AngularJS.
AngularJS also provides an easy way to implment single page applications with front end templating and routing. In this example application, routing to the various templates are in app/js/app.js while the HTML fragments are stored in the app/partials directory. Each template can then be associated to a unique AngularJS controller (app/js/controllers.js).
This repository also provides a classic "todo" application with two backend approaches:
- A pure front-end AngularJS app that syncs with a Firebase real-time Database-as-a-Service
- Integrated AngularJS app that communites with a Node.js back-end hosted on CloudBees
Firebase provides a real-time Object (JSON) database. AngularFire is a JavaScript library that allows developers to bind AngularJS scope objects with real-time data from Firebase. CRUD operations will be persisted and executed on the client-side without any need for any backend operations.
Take a look at app/partials/todos.html and the "TodoFireController" in app/js/controllers.js.
To create your own Firebase real-time database:
- Sign up for Firebase with your GitHub account
- Create a new developer plan Firebase, and note the URL of the Firebase
- Change this line in app/js/controllers.js:
var ref = new Firebase('https://<your-firebase-name>.firebaseio.com/todos'); - Push an update GitHub
- View the app on your CloudBees app URL one the build is completed
- Create some new todos and reload the page and observe
- Open up different windows to the same URL and observe when you perform CRUD on the todos
This version of the "todo" app is enabled by default.
To enable the node.js with MongoDB version of the "todo" app, change var firebase_backend in app/js/app.js to false. This will enable the "TodoController" in AngularJS.
Node.js is a JavaScript platform built on Google's V8 engine, and is used to develop a wide variety of network applications, including web applications.
This demo application uses the Express web app framework as its backbone, with a app/ folder containing all of the front (js/, css/, partials/ etc.) and back-end (main.js, package.json etc.) code.
The application database used here is MongoDB, a document/object based database system. Unlike a traditional relational databse system (e.g. MySQL, Oracle DB), MongoDB is an example of a non-relational NoSQL database. Other examples of NoSQL database systems include CouchDB and Google's App Engine Datastore (NDB is covered in the sister GAE tutorial).
To uses MongoDB-as-a-Service hosted on Mongolab with the "todo list" application, follow these steps:
- Sign up for Mongolab here
- Once logged in, proceed to create a new mondolab development environment here. Remember to select "Development (single-node)" under "plans"
- Choose a name for the database, e.g. "is429-todos"
- When prompted, create the credentials for a new database user (username and password)
- Make a note of the database name and the username and password of the new user you have just created
To make use of the MongoDB database you have just created in the Node.js web application these credentials have to be used in a secure manner:
- For developemnt on Nitrous.IO, app/credentials.js will be used
- Using the CloudBees SDK, the MongoDB password will be set as CloudBees config variable
To use the password in the development environment, edit the contents of "credentials.js" (created in Part 1) accordingly:
module.exports = {
MONGO_PASSWORD: ''
};
Using CloudBees SDK from the VM terminal:
bees config:set MONGO_PASSWORD=<MongoDB Password from Mongolab here> -a <your-username>/<your-repo>- Verify that the MONGO_PASSWORD variable has been set:
bees config:list -a <your-username>/<your-repo>
Change the MongoDB URL endpoint in this line in app/main.js
connection_string = 'mongodb://<your-db-username>:' + MONGO_PASSWORD + '@<your-mongolab-host>:39088/<your-database>';

