Flexiant Concerto

We recently published a couple of blogs on how you can use Flexiant Concerto to quickly and easily put together common application stacks, namely LAMP and LAMR (Ruby on Rails). Today we will take you through the steps required to put together another popular stack, specifically MongoDB, ExpressJS, AngularJS and Node.js, or MEAN.

MEAN’s popularity comes down to a number of factors. It provides a powerful framework within which to simplify and accelerate Web application development. MongoDB is, by all accounts, the leading NoSQL database, and a particularly good choice if you are making the transition over from SQL to NoSQL. Moreover, MEAN is full stack JavaScript, from client to server to database, giving you performance, efficiency and productivity benefits.

Let’s take a look at how we can do this in just 4 simple steps (NB: you first need to sign up for Flexiant Concerto – it’s simple to try for free).

Step 1 – Create a template

Click Blueprint -> Templates

  • Click Add Template
    • Specify a name
    • Choose an Ubuntu 14.04 generic image
    • Click New Template

Step 2 – Configure the template

  • Click on the template just created
    • Click on Cookbooks
    • Choose the following Cookbooks:
      • build-essential@2.2.3 (under System)
      • mongodb@0.16.2 (under Databases)
      • git@4.2.2 (under Development)
      • nodejs::nodejs@2.4.2 (under Development)

Development Run list

  • Change the following attributes;
    • nodejs/install_method : binary
    • nodejs/version : 0.12.7
    • nodejs/binary/checksum/linux_64 : 6a2b3077f293d17e2a1e6dba0297f761c9e981c255a2c82f329d4173acf9b9d5
    • nodejs/binary/checksum/linux_86 : bccf75736b64bd175b45681ed83a020f0dcc59b3626bbcefd5f7438aed9e9c15

Attributes

  • Click Save

Step 3 – Add a script

Create script

Click on Scripts on the left hand pane

      • Click Add Script
        • Specify a name and description
        • Save
      • Click on the script just created
      • Paste in the code section:
#!/bin/bash
 
# Install service
if [ ! -f /etc/init/mean.conf ];
then
    echo "Creating service" >> /var/log/mean.log
    BASEDIR=$(dirname $0)
    cp $BASEDIR/attachments/mean.conf /etc/init/mean.conf
else
    echo "Service already created" >> /var/log/mean.log
fi
 
#Execute service
ps cax | grep node > /dev/null
if [ $? -ne 0 ];
then
  echo "Executing service" >> /var/log/mean.log
  service mean start
else
  echo "Application already executing" >> /var/log/mean.log
fi
 
echo "Done!" >> /var/log/mean.log

Create a script attachment

  • Create a file with the name mean.conf
  • Enter the following content:
# Download source
if [ ! -f /var/mean/NEMTAB/package.json ];
then
  echo "[`date`]Downloading application code" >> /var/log/mean.log
  mkdir -p /var/mean/NEMTAB
  cd /var/mean
  wget https://github.com/mancioshell/NEMTAB/archive/master.tar.gz
  tar -xzf master.tar.gz -C NEMTAB --strip-components=1
  rm master.tar.gz
  echo "[`date`]Application code downloaded" >> /var/log/mean.log
else
  echo "[`date`]Application already exists" >> /var/log/mean.log
fi
 
# Install dependencies
if [ ! -d /var/mean/NEMTAB/node_modules ];
then
  echo "[`date`]Installing dependencies" >> /var/log/mean.log
  npm install -g bower
  npm install -g grunt-cli
  cd /var/mean/NEMTAB
  node_modules=$(npm list -g | sed -e 1b -e '$!d')'/node_modules'
  chown -R root:root $node_modules
  npm install
  bower update --allow-root --config.interactive=false
  echo "[`date`]Dependencies updated" >> /var/log/mean.log
else
  echo "[`date`]Dependencies up to date" >> /var/log/mean.log
fi
 
end script
 
script
  export HOME="/root"
  export PORT=80
  echo $$ > /var/run/mean.pid
  chdir /var/mean/NEMTAB/
  exec node server.js >> /var/log/mean.log 2>&1
end script
 
pre-stop script
  rm /var/run/mean.pid
  echo "[`date`]MEAN app stopping" >> /var/log/mean.log
end script
  • In Concerto, under Scripts, click on the Attachment tab
    • Click Select Files and upload the .conf file you just created
  • Click on the Code tab
  • Click on Save

Drop files here

Associate script to template

  • Go back to Templates and click on the template just created
  • Click on Scripts in the right hand pane
    • Click on the + button in the Boot box
    • Select the script just created

Step 4 – Boot up a server

  • Click on Infrastructure -> Servers
    • Click Add Workspace
      • Specify a name, domain, SSH and firewall profile
      • Save
    • Click Add server
      • Specify name, hostname, template and cloud provider/server plan
      • Save
    • Click on the server just created
    • Click on the Show Actions button
    • Click the play button
    • Wait for the boot and bootstrapping process to complete
    • Browse to the Fully Qualified Domain Name listed under DNS in the right hand panel

You are now up and running with a fully functional MEAN stack.

To find out more about Flexiant Concerto or to signup and try it out for free, visit www.concerto.io.

Tags: , , , , ,