Tuesday, August 4, 2015

Creating Javascript development environment on windows

Install Client-Side Tools

Install Git Bash 

Install npm

  • The best way to install npm is to install node using the node.js installer. npm is installed as part of node. node.js site: https://nodejs.org/
  • Once you’ve installed node.js, you can make sure you’ve got the very most recent version of npm using npm itself, open Git Bash and enter:
    npm install npm –g

Install Bower

  • Bower is a command line utility. Install it with npm, open Git Bash and enter:
    npm install -g bower

Install Grunt CLI

  • Open Git Bash and enter:
    npm install -g grunt-cli
  • This will put the grunt command in your system path, allowing it to be run from any directory.
  • Note that installing grunt-cli does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile. This allows multiple versions of Grunt to be installed on the same machine simultaneously.

Monday, May 25, 2015

Comparison chart for different continuous deployment tools for AWS


I recently needed to conduct a research on the various continuous deployment tools available.
My results are summed up in this table:


Chef
Puppet
Ansible
CodeDeploy
Docker
What is it
A master-worksation service with OO DSL for deployment, uses git (ruby based) web UI on enterprise edition
A master-worksation service with OO DSL for deployment (ruby based) web UI on enterprise edition
 Yaml based script,
Push architecture, no clients (python based)
AWS deployment tool UI from AWS console
A container for a software environment so that the deployment env matches the dev env similar to AMIs
How to use
Install both client and server. Build the script trigger the workstations
Install both client and server .Build a manifest in the puappetmaster and then run the puppet script on every station
Install server. Create a playbook in yaml
Install on the servers and then use web UI to configure
Create a new (or use a perdefined one as basis) container.
Install what you need.
Commit it as a container. Upload to hub.
Install it wherever you want
Learning curve
Need to learn the scripting language
Need to learn the scripting language
Need to learn the scripting language (but a simple one)
Very simple streightforward
Fast. Just a few docker commands
Price
Free with enterprise edition (6$ per node)
Free with enterprise edition (112$ per node)
Free
Free for now
Free open source
Scaling
Checf server deploys to multiple stations easily but no push
puppetmaster deploys to multiple stations easily using push
Ansible quick deployment to multiple severs
No prob
infinite
Environment support
All
All
All
All
Linux (based on linux containers)
On-premise
Can be deployed on on-premise servers
Can be deployed on on-premise servers
Can be deployed on on-premise servers
EC2 only
No prob
Supported langs
All
All
All
All
All
Cons
Takes some disk space (especcialy server). No push feature
Complexity of scripts. Steep learning curve. Expensive enterprise edition
Very simple - less control. No code reuse
Must use github (for now)
Less environment configuration options
Need to build entire image. Slow deployment.
pros
downloadable playbooks, strong community, cheap (not really necessary) paid edition
Fast, reusable, widely used, big community with downloadable modules

Fast, simple, no clients, downloadable playbooks
Great EC2 integration.
Automatic built in CD support. Very simple.
Community containers, full environment (very safe), simple (no need to learn a new language)


Monday, April 27, 2015

Installing Jenkins on AWS with java play, sbt and assembla

I recently tried to install a jenkins server in amazon cloud for our company's projects.
It took me a while but I wrote it all down for reference.
If you are having trouble setting Jenkins up this might help you:

Installing Jenkins on Ubuntu with Java Plat and Assembla on AWS
1)      Start a new ec2 machine with Basic Linux AMI
2)      In the security groups set a rule for custom TCP rule with port number 8080
3)      Installation steps from: http://sanketdangi.com/post/62715793234/install-configure-jenkins-on-amazon-linux (replace yum with apt-get if Ubuntu)

            a.       Login to your Amazon Linux instance
            b.      Become root using “sudo su -” command
c.       Install jenkins
                                                               i.      On red hat
1.       yum update
2.       wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
3.       rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key or sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key (whatever works with no errors)
4.       yum install Jenkins
                                                             ii.      on ubuntu
1.       use apt-get (TODO complete)
d.      service Jenkins start
e.      chkconfig Jenkins on
4)      open browser and go to the server url port 8080 (http://<url>:8080)
5)      go to manage Jenkins à manage plugins à available tab (for all plugins click install without restart if possible)
a.       install git plugin
b.      install assembla plugin
c.       install sbt plugin
d.      ssh agent plugin
e.      ssh credentials plugin
f.        play-plugin
6)      restart Jenkins using service Jenkins restart
7)      create an assembla webhook (for running build for every commit)
a.       login to your assembla account
b.      go to assembla à admin (you need admin privilages) à tools à more à webhooks à add
c.       go to webhooks settings
d.      click configure a webhook
e.      In Webhook, enter the following settings:
                                                               i.      Title=Anything
                                                             ii.      Enabled=true
                                                            iii.      Authentication type=basic
                                                           iv.      External url=http://<server URL>:8080/git/notifyCommit?url={repository_url}&branch={branch} 
                                                             v.      Http method=GET
                                                           vi.      Context type=text/plain
                                                          vii.      Post updates about=check "Code Commits"
                                                        viii.      Click Add


8)      Login as Jenkins : sudo su jenkins -s /bin/bash
9)      Make sure you have a ssh key or generate a new one:
First, we need to check for existing SSH keys on your computer. Open Git Bash and enter:
ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist
Check the directory listing to see if you already have a public SSH key. By default, the filenames of the public keys are one of the following:
id_dsa.pub
id_ecdsa.pub
id_ed25519.pub
id_rsa.pub

Step 2: Generate a new SSH key

With Git Bash still open, copy and paste the text below. Make sure you substitute in your GitHub email address.
ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
We strongly suggest keeping the default settings as they are, so when you're prompted to "Enter a file in which to save the key", just press Enter to continue.
# Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
You'll be asked to enter a passphrase.
# Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]
Tip: We strongly recommend a very good, secure passphrase. For more information, see "Working with SSH key passphrases".
After you enter a passphrase, you'll be given the fingerprint, or id, of your SSH key. It will look something like this:
# Your identification has been saved in /Users/you/.ssh/id_rsa.
# Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

Copy the generated key to /var/lib/Jenkins/.ssh (you need admin priviledges) if it is not already there you can also generate a dsa key: ssh-keygen -t dsa


10)   Configure credentials
a.       Go to Jenkins->Manage Jenkins->Manage Credentials
b.      Use the global domain (domains are used to supply a set of rules to when we can use credentials)
c.       Scope=Global
d.      Username=jenkins
e.      Private Key=From the Jenkins master ~/.ssh or enter the location
f.        Click advance tab and enter your passphrase
g.       Click save
11)   Add the ssh key to assembla:
a.       Go to user menu (top left side) à profile à ssh keys from sidebar
b.      Connect to the server and enter: cat .ssh/id_rsa.pub
c.       Copy the output to clipboard and paste it to the text box (if using windows make sure there are no newlines cause windows terminal sucks)
d.      Click add key
12)   Configure git globals:
a.       git config —global user.name “Your Name”
b.      git config —global user.email email@email.com (email used for assembla)
13)   download sbt launcher using wget (you can use this link: http://www.scala-sbt.org/0.13/tutorial/Manual-Installation.html) save the file in /usr/bin            
14)   configure SBT
               a. Press the Manage Jenkins link and then the Configure System
               b. Go to sbt section
               c. Click add sbt
               d. Select the path to the launcher
15)   Install junit
a.       Redhat
                                                               i.      Yum install junit
b.      Debian/Ubuntu
                                                               i.      Sudo apt-get install junit
16)   Configure ssh-agent by creating the .profile file on the Jenkins home directory and copy-paste the following into it:


# Note: ~/.ssh/environment should not be used, as it already has a different purpose in SSH.
env=~/.ssh/agent.env
# Note: Don't bother checking SSH_AGENT_PID. It's not used
# by SSH itself, and it might even be incorrect
# (for example, when using agent-forwarding over SSH).
agent_is_running() {

if [ "$SSH_AUTH_SOCK" ]; then
# ssh-add returns:
# 0 = agent running, has keys
# 1 = agent running, no keys
# 2 = agent not running
  ssh-add -l >/dev/null 2>&1 || [ $? -eq 1 ]
else
  false
fi
}
agent_has_keys() {
  ssh-add -l >/dev/null 2>&1
}

agent_load_env() {
  . "$env" >/dev/null
}

agent_start() {
  (umask 077; ssh-agent >"$env")
  . "$env" >/dev/null
}
if ! agent_is_running; then
  agent_load_env
fi

if ! agent_is_running; then
  agent_start
  ssh-add
elif ! agent_has_keys; then
  ssh-add
fi

unset env

17)   Install Play!:
b.      unzip typesafe-activator-1.3.2-minimal.zip
c.       export PATH=$PATH:/var/lib/jenkins/activator-1.3.2-minimal
d.      activator
e.      go to manage jenkine à configure Jenkins
f.        add Play!
g.       Set path to activator
18)   for running scripts:
a.       login as root (sudo su -)
b.      vi /etc/sudoers
c.       comment out Defaults    requiretty
d.      vi /etc/sudoers.d/cloud-conf
e.      add jenkins ALL=(ALL) NOPASSWD: ALL
19)   project configuration
a.       go to dashboard
b.      click new item
c.       enter name
d.      select freestyle project
e.      click ok
f.        set SCM
                                                               i.      select source code management à git
                                                             ii.      enter repository url
                                                            iii.      branches to build set it to blank (will build all branches)
g.       build triggers
                                                               i.      poll SCM
                                                             ii.      keep schedule blank

                  h. build:
                               i. add build step
                               ii. using sbt:
                                      1. select build using sbt
                                      2. in action enter compile test
                                      3. TODO – how to use build.sbt
                               iii. Using activator (java play!)
                                      1. Select Play!
                                      2. Add compile and test
                              iv. Using a script:
                                      1. Write a shell script in the workspace directory
                                      2. Chmod 777 <name_of_script>
                                      3. Select shell script
                                      4. Name of script
                    i. post build actions
                                      1. select publish Junit result report
                                      2. select e-mail notification
                                              i. check both boxes
                                              ii. enter moderators e-mails