DevOps is a philosophy, and any attempt to burn your hands in implementing DevOps (it may be IT or any other industry – though here we are concerned on the former) is a long stretched set of activities based on organization appetite to achieve IT agility. Now, this blog is to give you, as an individual, a very very basic guidance on how you can try it out in a small team (or at home using your personal laptop), more from an experimental standpoint.
While for an actual DevOps implementation, the three dimensions – people (read, culture), process and technology (read, tool-based automation) – are equally important; we would concern ourselves with the last factor for this small experiment. Further, we would constrain ourselves to the following scenario in a pre-prod IT environment:
a. Provision a virtual machine (VM) to set up an environment on-the-go
b. Install specific tools to write a small program (java in this case, given that the associated tools are available free over the web) and move it to a source code repository
c. Build the program (this is one-time before we automate in next step)
d. Establish an automated workflow such that whenever a change is made to the program, the code would be picked up and built – this is a very basic form of what is called ‘Continuous Integration’
Note – You can perform the given set of activities either on a Windows PC, or a Mac, or a LINUX PC; we would do the rest of the activities on Ubuntu LINUX that we will install in the VM. Further, you may refer to unlimited content available on the web for specific implementation level instructions based on your host O/S. Note that this is a basic guidance that will give you a basic understanding of where typically DevOps may start, and is in no means a tutorial on DevOps or associated software, tools or processes.
The steps are as follows [WARNING: Details are quite a bit technical]
1. Provision the VM – Install Oracle VirtualBox from the web; it is available for free. Go to the UI and create a new VM; you may either go with the default parameters, or choose your own while it asks for the options (say, 1GB RAM, 80GB hard drive space, etc.). Note that you can create as many VMs as you wish, use them or remove them at will.
2. Download Ubuntu 32-bit (or 64-bit if your host O/S is 64-bit) which is available as an image (typically, .iso format for a Window machine).
3. Start the VM. It will ask for the O/S image you want to install. Browse to your local copy of the .iso file that you have saved in your machine, select and install it.
4. Once Ubuntu starts, go to the command line interface [CLI] by selecting ‘X-Terminal’ from the start menu in Ubuntu GUI.
5. Install the following tools – Git, Maven, Jenkins. In Ubuntu, following may be the commands (may vary slightly based on conditions or parameters of the specific installation):
$ sudo apt-get update
$ sudo apt-get install git
$ sudo apt-get install maven
$ sudo apt-get install jenkins
(Note – Git is a source code repository, Maven is a java build tool, Jenkins is a CI tool that will integrate Git and Maven to achieve the automation objective stated in point (d) above. Further, there are specific Linux commands that you can use to check the versions, adjust parameters in configuration files in Linux, etc., that are quite well covered in various internet sources)
6. Write a java program using any CLI editor such as nano (you can also use VI editor if you are a seasoned Linux user) and save it in a folder
7. Generate the Maven folder structure and project object model (pom) file using ‘mvn archetype:generate …..’ command; accordingly, Maven downloads several pieces of .jar files from the web, creates a default folder structure using one of it’s available templates and creates a pom.xml file.
Default folder structure is typically of this form:
/<yourname>/src/main/java/<yourstructure>/java (a default program ‘App.java’ is also placed at the bottom of this structure)
Note: <yourname> and <yourstructure> are names you specify as parameters to archetype:generate command
Also, Maven creates a separate similar looking structure for tests under /src and places a file ‘AppTest.java’
– Actually, Maven also installs JUnit for unit tests, and this file is a unit test script file
The pom.xml file is created under /<yourname> folder itself
8. Copy your java source code in the folder structure (note that a default program called ‘App.java’ has been already created at the very bottom of the structure, which you can replace with your source code)
9. In the folder where you have App.java, initialize Git and check in your source code to it; typical commands are:
$ git init
$ git add App.java
$ git commit -m ‘my first version’
10. You can use maven to test, compile and package [commonly known as ‘build’] the source code using only one command, ‘mvn package’ (this will create a .jar file which can also be run using maven; there are numerous internet sources where you can find further details; this step is optional as the next steps would achieve this using Jenkins
Note – Next few steps are the most important that will give you the very basic essence of automation using CI
11. Start jenkins (if not already started); check by going back to the Ubuntu GUI, opening the browser – typically, Mozilla Firefox – and enter ‘http://localhost:8080’ (note that Jenkins uses port 8080)
12. Login to jenkins using your Ubuntu userid and password (if asked for)
13. In the jenkins dashboard screen, go to ‘Manage Jenkins’ at the left
14. Configure your Git (specifying location, etc.) and Maven installations in appropriate panels (there are thousands of internet sources to talk about it). Coming back to the dashboard, you have to create a ‘New Item’ (button at top left) and create a Maven project. For this project, you will get a form where you need to specify (among other things) the Git location, and the Maven command that needs to be run whenever code is changed and committed to Git; in this case, it would be ‘mvn package’. Further, a schedule needs to be specified to tell Jenkins at what frequency the code would be checked for changes; for checking every 10 minutes, the schedule is specified as ‘* * * * H/5’ – appropriate help is available in Jenkins describing what it means.
15. Once you make any change to the code (or even if you do not), you can always run ‘Build Now’ from the specific project’s dashboard to build your code anytime.
16. Alternatively, Jenkins will check for every 10 min. if your code in Git has changed, and accordingly will pick it up and build it (a successful build is shown as a solid blue circle, and unsuccessful one in red; at bottom left of the project dashboard).
Voila! You have achieved a very basic CI on java.