Showing posts with label DevCS. Show all posts
Showing posts with label DevCS. Show all posts

Wednesday, May 10, 2017

DevOps With Oracle DeveloperCS Ansible and Docker

This blog shows a sample DevOps cycle using combination of Oracle Developer Cloud Service & Ansible playbook.
Scenario: An organization wants to setup DevOps practice with Oracle public cloud for Dev & test. However production still remains on-premise. In such case Oracle Developer cloud service can deploy artifacts(e.g. JAR file) to JCS (Java cloud Service) or ACCS (Application container Cloud service). However to get the artifact on premise we can write extension. So that artifact is downloaded and production environment is rolled out automatically.
Note that here we are discussing a simple example to get the concept. In real implementation there will be more complex architecture. What we discuss below is just one of the possible way.
Tools/features used:
  1. Oracle Public Cloud:
  • Source code repository – GIT Repository available OOTB with Developer CS. Used to maintain source code of sample Java Spring bootstrap based application
  • Continuous Integration- Hudson build server available OOTB with Developer CS. Used to compile code, generate Jar file and perform Unit testing
  1. Internet:
  • GIT Hub  - to maintain artifacts/binaries generated by Developer CS. (Here jar generated from Developer CS is moved to GIT Hub)
  1. On Premise:
  • Docker – Docker container to run java application
  • Ansible – Ansible playbook to download artifact from GIT Hub, configure with Docker and rollout the environment.
Flow:




Implementation:
  • I am assuming that audience is familiar with Developer Cloud service, Docker concepts, Checkin code from their respective IDE to GIT repository. If you need information on Developer CS please refer to Oracle documentations (https://docs.oracle.com/en/cloud/paas/developer-cloud/index.html )
  • I have built a Spring bootstrap based J2SE project.
  • Let’s login to Developer CS. Provide your Identity domain and user credential.
  • On successful login you will see projects already configured in Developer CS. In my case I already have a Spring Medrec J2SE Project. A new project can be created from this page.
  • Click on the project and go to Project section. Copy the GIT repository path. That needs to configured with your IDE

  • Go to IDE (Netbean in my case) and check-in source code in GIT repository. Once source code is successfully pushed go to Code section. Here it shows source code checked-in to the GIT repository. It also has a pom.xml as Maven script, checked in as a part of source code.

  • Now go to build section to create a build job. Here I have created a Job named “Master Build”. Go to the configure section of Master build. And click on Source code tab. Here you need to configure repository info where code is checked-in.

  • Now click on Build steps. Add build step “Invoke Maven 3”. And define appropriate goals configured in your maven.xml
  • Go to post build section and select option to archive artifact. If you have Junit test cases select option to publish Junit test cases as well. It will show test results on Developer CS console.

  • Save changes and run the build. You will see an artifact generated as a result of successful build. Here a zip file ‘medrec-0.0.1-SNAPSHOT.zip’ can be seen. This zip contains application JAR inside.
  • Also you can see Junit test results by clicking on ‘Tests’
  • Since the artifact is generated successfully it can be deployed to Oracle ACCS. Click on ‘Deploy’ menu option configure & Deploy application in your ACCS account.

  • Go to configuration section of this job.
  • Click on build steps and select execute shell as an option. Here we will copy artifact generated by previous build and move to GIT Hub.


  • Click on build steps and select execute shell as an option. Here we will copy artifact generated by previous build and move to GIT Hub. On successful build ‘medrec-0.0.1-SNAPSHOT.zip’ file can be seen in GIT hub.
  • Next, we will use Ansible playbook to pull zip file from GIT Hub and deploy on Docker. I am using a Linux VM where docker engine & Ansible are already installed.
  • Here is the Ansible playbook (deploy.yml) created to perform following tasks in sequence:
    • Pull Artifacts (medrec-0.0.1-SNAPSHOT.zip file) on local file system
    • Unzip the archive
    • Stop and remove pre-existing docker contianer
    • Build new docker image
    • Start a new container
  • This is how deploy.yml looks like (2 screenshots) :
  • We will execute deploy.yml on localhost. However Ansible can perform same task on remote host as well.
  • Once above command is executed it will perform each task mentioned in playbook.
  • Lets check we check docker images and container.
  • Access URL to run java application on Docker’s IP address. (Here the application shows Swagger API)