Thursday, 25 February 2016

Chef Start here with ease..





Introduction

Until I discovered cooking, I was never really interested in anything. Julia Child


Chef, the lead in automation industry has many tickling facet and calibre. Before introducing the potentials of “The Chef”, it’s non negotiable to evade the foresight of its relevance to devops exercises. Chef can take care of server automation, infrastructure environment and continuously deliver your application.


Motive behind this array

With this blog series, we will familiarize you with the concepts of chef and will try to make you comfortable with our hands on blogs. This series of blog contains 15 blogs in a row which will enhance the knowledge and draw your faith in chef.

Always Pre-Heat The Oven Before Putting The Meat In !!

Prerequisites


For all the upcoming blogs we presume that you have basic understanding of Git, Docker,Vagrant and Linux. This blog series is written in consideration with centos as platform, although you can apply them on ubuntu by following some minor changes.



We are going to use our public git repository for all the blogs in this series. We will be using centos7 vagrant box to spin up our testing environment.



We are going to follow a single problem statement in our all blogs to maintain the uniformity and avoid the ambiguity. We are going to install nginx using chef and deploying two virtual host (blog.opstree.com, chef.opstree.com) with it.




Blogs in this series


In this blog we describe Nginx and manually setup the nginx, as per the problem statement and also create two virtual host(blog.opstree.com, chef.opstree.com).

Here we took some example of resources such as package, git, file and service and put our hands to work with chef-apply. We perform some simple task using chef resources.

This blog provides you theoretical concepts about chef resources. In this article  resources and their attributes elaborated.

Chef recipes is in consideration for this edition. Create your first recipe and apply it with chef. Complete doctrine behind the recipes of chef with simplified examples.

Walls of chef house, the cookbook, written from scratch with step to step explanation. Setup of nginx and proxy implementation with sample cookbook.

This blog furnish entire theoretical stuff about cookbooks. This includes command line cookbook generation and handling. One by one description of complete directory structure of a cookbook.  

Installation of chef kitchen. Testing of our nginx cookbook in different environment using docker container. Create, converge, verify and destroy a node with kitchen.

  1. Chef-Kitchen Chefs diagnosis center..
Theory behind the chef kitchen. Complete cycle of kitchen. With in this article elaborated view of .kitchen.yml file, and .kitchen folder provided.

  1. Chef Foodcritic && Chef Rubocop Handle it casually..
Chef lint tools, foodcritic and rubocop requirement. Theory, setup and practice exercises for foodcritic and rubocop.  

  1. Chef-Databags Carry all at once..
Introduction to databags and their need. Division of code and data with databags.  Databags implementation with chef-solo. Setup of mysql password with databags.  

  1. Chef-Roles Club everybody..
Requirement and implementation of chef roles. Clubbing of multiple nodes with chef roles. Complete web stack (webserver, proxy server and database) setup with roles.

  1. Chef-Environment  Organized wisely..
Chef environments for better management of the need of an organization. A complete organizational view with chef to setup different environment. Handle environments with chef-knife.

  1. Chef Server-Client Setup
Complete setup of chef client-server mode. Use of vagrant provisioning only, to spin up chef-server, chef-client and workstation.

  1. Collaboration of Client Server and Workstations
How chef-server, client and workstations work together to automate a complete infrastructure. Chef-server web interface.

  1. Chef Server-Client Work quietly..
Kickoff working with workstation. Chef-client. Install nginx and setup proxies with nginx cookbook on client node.

Monday, 8 February 2016

jgit-flow maven plugin to Release Java Application

Introduction

As a DevOps I need a smooth way to release the java application, so I compared two maven plugin that are used to release the java application and in the end I found that Jgit-flow plugin is far better than maven-release plugin on the basis of following points:
  • Maven-release plugin creates .backup and release.properties files to your working directory which can be committed mistakenly, when they should not be. jgit-flow maven plugin doesn't create these files or any other file in your working directory.
  • Maven-release plugin create two tags.
  • Maven-release plugin does a build in the prepare goal and a build in the perform goal causing tests to run 2 times but jgit-flow maven plugin builds project once so tests run only once.
  • If something goes wrong during the maven plugin execution, It become very tough to roll it back, on the other hand jgit-flow maven plugin makes all changes into the branch and if you want to roll back just delete that branch.
  • jgit-flow maven plugin doesn't run site-deploy
  • jgit-flow maven plugin provides option to turn on/off maven deployment
  • jgit-flow maven plugin provides option to turn on/off remote pushes/tagging
  • jgit-flow maven plugin keeps the master branch always at latest release version.
Now let's see how to integrate Jgit-flow maven plugin and use it

    How to use Jgit-flow maven Plugin for Release

    Follow the flowing steps 
    1. Add the following lines in your pom.xml for source code management access
             
      <scm>
        <connection>scm:git:<Git Repo URL></connection>
        <developerConnection>scm:git:git:<Git Repo URL></developerConnection>
      </scm>

    2. Add these line to resolve the Jgit-flow maven plugin and put the other option that will be required during the build
             
      <build>
          <plugins>
            <plugin>
              <groupId>com.atlassian.maven.plugins</groupId>
              <artifactId>maven-jgitflow-plugin</artifactId>
              <version>1.0-m4.3</version>
              <configuration>
                <pushReleases>true</pushReleases>
               <keepBranch>false</keepBranch>
      <autoVersionSubmodules>true</autoVersionSubmodules>
                <noTag>true</noTag>
                <allowUntracked>true</allowUntracked>
      <pullDevelop>true</pullDevelop>
      <pullMaster>true</pullMaster>
      <allowSnapshots>true</allowSnapshots>
                <flowInitContext>
                  <masterBranchName>master-test</masterBranchName>
                  <developBranchName>deploy-test</developBranchName>
                </flowInitContext>
              </configuration>
           </plugin>
        </plugins>
      </build>
       
    3. Above code snippet will perform following steps:
      • Maven will resolve the jgitflow plug-in dependency
      • In the configuration section, we describe how jgit-flow plug-in will behave.
      • pushRelease XML tag to enable and disable jgit-flow from releasing the intermediate branches into the git or not.
      • keepBranch XML tag to enable and disable the plug-in for keep the intermediate branch or not.
      • noTag XMl tag to enable and disable the plug-in to create the that tag in git.
      • allowUntracked XML tag to whether allow untracked file during the checking. 
      • flowInitContext XML tag is used to override the default and branch name of the jgit-flow plug-in
      • In above code snippet, there is only two branches, master from where that code will be pulled and a intermediate branch that will be used by the jgit-flow plug-in. as I have discussed that jgit-flow plug-in uses the branches to keep it records. so development branch will be created by the plug-in that resides in the local not remotely, to track the release version etc. 
    4. To put your your releases into the repository manager add these lines
             
      <distributionManagement>
        <repository>
          <id><auth id></id>
          <url><repo url of repository managers></url>
        </repository>
        <snapshotRepository>
          <id><auth id></id>
          <url><repo url of repository managers></url>
        </snapshotRepository>
      </distributionManagement>

    5. Put the following lines into your m2/settings.xml with your repository manager credentials
              
      <settings>
        <servers>
          <server>
              <id><PUT THE ID OF THE REPOSITORY OR SNAPSHOTS ID HERE></id>
            <username><USERNAME></username>
            <password><PASSWORD></password>
          </server>
        </servers>
      </settings>

    Start Release jgit-flow maven plugin command

    To start the new release execute jgitflow:release-start.  

    Finish Release jgit-flow maven plugin  command

    To finish new release, execute mvn jgitflow:release-finish.

    For a example I have created a repository in github.com. for testing and two branch master-test and deploy-test. It is assumed that you have configured maven and git your system.
    In the deploy-test branch run following command
    $ mvn clean -Dmaven.test.skip=true install jgitflow:release-start


    This command will take input from you for release version and create a release branch with release/<version>. then it will push this release branch into github repository for temporarily because we are not saving the intermediate branched





















    Now At the end run this command
    $ mvn -Dmaven.test.skip=true jgitflow:release-finish
    after finishing this command it will delete release/<version> from local and remote.











    Now you can check the changes in pom file by jgitflow. in the above snapshot, it is master-test branch, you can see in the <version> tag it has removed the snapshot and also increased the version.  It hold the current version of the application.

    And in the deploy-test branch it show you new branch on which developers are working on